public Collection<BehavioralFeature> getAllBehavioralFeatures(Object element) { if (!(element instanceof ModelElement)) { throw new IllegalArgumentException(); } List contents = new ArrayList(); List<BehavioralFeature> result = new ArrayList<BehavioralFeature>(); try { contents.addAll(Model.getFacade() .getTaggedValuesCollection(element)); contents.addAll(((ModelElement) element).getTemplateParameter()); Iterator it = contents.iterator(); while (it.hasNext()) { Object o = it.next(); if (o instanceof Classifier) { Classifier clazz = (Classifier) o; if (!(clazz instanceof DataType)) { for (Object o1 : clazz.getFeature()) { if (o1 instanceof BehavioralFeature) { result.add((BehavioralFeature) o1); } } } } else { // TODO: 2nd next() for single hasNext() result.addAll(getAllBehavioralFeatures(it.next())); } } } catch (InvalidObjectException e) { throw new InvalidElementException(e); } return result; }
public Collection getAllBehavioralFeatures(Object ns) { // Get Classifiers in Namespace ArrayList features = new ArrayList(); try { Collection classifiers = getAllModelElementsOfKind(ns, modelImpl.getMetaTypes().getClassifier()); Iterator i = classifiers.iterator(); // Get Features owned by those Classifiers while (i.hasNext()) { features.addAll(modelImpl.getFacade().getFeatures(i.next())); } } catch (InvalidObjectException e) { throw new InvalidElementException(e); } // Select those Features which are BehavioralFeatures ArrayList behavioralfeatures = new ArrayList(); Iterator ii = features.iterator(); while (ii.hasNext()) { Object f = ii.next(); if (f instanceof BehavioralFeature) { behavioralfeatures.add(f); } } return behavioralfeatures; }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreHelperMDRImpl.java File path: /ArgoUML-0.34-src/argouml/src/argouml-core-model-mdr/src/org/argouml/model/mdr/ModelManagementHelperMDRImpl.java
Method name: Collection getAllBehavioralFeatures(Object) Method name: Collection getAllBehavioralFeatures(Object)
Number of AST nodes: 3 Number of AST nodes: 4
1
public Collection<BehavioralFeature> getAllBehavioralFeatures(Object element) {
1
public Collection getAllBehavioralFeatures(Object ns) {
2
        if (!(element instanceof ModelElement)) {
2
        // Get Classifiers in Namespace
3
            throw new IllegalArgumentException();
3
        ArrayList features = new ArrayList();
4
        }
4
        try {
5
        List contents = new ArrayList();
5
            Collection classifiers = getAllModelElementsOfKind(ns, 
6
        List<BehavioralFeature> result = new ArrayList<BehavioralFeature>();
6
                    modelImpl.getMetaTypes().getClassifier());
7
        try {
7
            Iterator i = classifiers.iterator();
8
            contents.addAll(Model.getFacade()
8
            // Get Features owned by those Classifiers
9
                    .getTaggedValuesCollection(element));
9
            while (i.hasNext()) {
10
            contents.addAll(((ModelElement) element).getTemplateParameter());
10
                features.addAll(modelImpl.getFacade().getFeatures(i.next()));
11
            Iterator it = contents.iterator();
11
            }
12
            while (it.hasNext()) {
12
        } catch (InvalidObjectException e) {
13
                Object o = it.next();
13
            throw new InvalidElementException(e);
14
                if (o instanceof Classifier) {
14
        }
15
                    Classifier clazz = (Classifier) o;
15
        // Select those Features which are BehavioralFeatures
16
                    if (!(clazz instanceof DataType)) {
16
        ArrayList behavioralfeatures = new ArrayList();
17
                        for (Object o1 : clazz.getFeature()) {
17
        Iterator ii = features.iterator();
18
                            if (o1 instanceof BehavioralFeature) {
18
        while (ii.hasNext()) {
19
                                result.add((BehavioralFeature) o1);
19
            Object f = ii.next();
20
                            }
20
            if (f instanceof BehavioralFeature) {
21
                        }
21
                behavioralfeatures.add(f);
22
                    }
22
            }
23
                } else {
23
        }
24
                    // TODO: 2nd next() for single hasNext()
24
        return behavioralfeatures;
25
                    result.addAll(getAllBehavioralFeatures(it.next()));
25
    }
26
                }
27
            }
28
        } catch (InvalidObjectException e) {
29
            throw new InvalidElementException(e);
30
        }
31
        return result;
32
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements4
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.600
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    14
    for (Object o1 : clazz.getFeature())
    14
    for (Object o1 : clazz.getFeature())
    9
    while (ii.hasNext())
    Differences
    Expression1Expression2Difference
    o1fVARIABLE_NAME_MISMATCH
    java.util.Listjava.util.ArrayListVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.util.List<org.omg.uml.foundation.core.Feature> of variable clazz.getFeature() does not match with type java.util.ArrayList of variable features
    • Make classes java.util.List and java.util.ArrayList extend a common superclass
    9
    while (ii.hasNext())
                                                  
    10
    Object f = ii.next();
    Differences
    Expression1Expression2Difference
    o1fVARIABLE_NAME_MISMATCH
    10
    Object f = ii.next();
    15
    if (o1 instanceof BehavioralFeature)
    15
    if (o1 instanceof BehavioralFeature)
    11
    if (f instanceof BehavioralFeature)
    Differences
    Expression1Expression2Difference
    o1fVARIABLE_NAME_MISMATCH
    11
    if (f instanceof BehavioralFeature)
                                                                
    12
    behavioralfeatures.add(f);
    Preondition Violations
    Unmatched statement behavioralfeatures.add(f); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12
    behavioralfeatures.add(f);
    16
    result.add((BehavioralFeature)o1);
    16
    result.add((BehavioralFeature)o1);
    Preondition Violations
    Unmatched statement result.add((BehavioralFeature)o1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                
    Precondition Violations (3)
    Row Violation
    1Type java.util.List<org.omg.uml.foundation.core.Feature> of variable clazz.getFeature() does not match with type java.util.ArrayList of variable features
    2Unmatched statement behavioralfeatures.add(f); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched statement result.add((BehavioralFeature)o1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted