/** * Finds a type in a model by name * * @param s the type name * @param model the model * @return the type or <code>null</code> if the type has not been found. */ public static Object findTypeInModel(String s, Object model) { if (!Model.getFacade().isANamespace(model)) { throw new IllegalArgumentException( "Looking for the classifier " + s + " in a non-namespace object of " + model + ". A namespace was expected."); } Collection allClassifiers = Model.getModelManagementHelper() .getAllModelElementsOfKind(model, Model.getMetaTypes().getClassifier()); for (Object classifier : allClassifiers) { if (Model.getFacade().getName(classifier) != null && Model.getFacade().getName(classifier).equals(s)) { return classifier; } } return null; }
/** * Finds a type in a model by name * * FIXME: duplicated from the method with the same name in * org.argouml.profile.internal.ModelUtils. * * @param s the type name * @param model the model * @return the type or <code>null</code> if the type has not been found. */ public static Object findTypeInModel(String s, Object model) { if (!Model.getFacade().isANamespace(model)) { throw new IllegalArgumentException( "Looking for the classifier " + s + " in a non-namespace object of " + model + ". A namespace was expected."); } Collection allClassifiers = Model.getModelManagementHelper() .getAllModelElementsOfKind(model, Model.getMetaTypes().getClassifier()); Object[] classifiers = allClassifiers.toArray(); Object classifier = null; for (int i = 0; i < classifiers.length; i++) { classifier = classifiers[i]; if (Model.getFacade().getName(classifier) != null && Model.getFacade().getName(classifier).equals(s)) { return classifier; } } return null; }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml-java/src/org/argouml/language/java/profile/ModelUtils.java File path: /ArgoUML-0.34-src/argouml/src/argouml-app/src/org/argouml/kernel/ProfileConfiguration.java
Method name: Object findTypeInModel(String, Object) Method name: Object findTypeInModel(String, Object)
Number of AST nodes: 3 Number of AST nodes: 4
1
/**
1
/**
2
     * Finds a type in a model by name
2
     * Finds a type in a model by name
3
     *
3
     * 
4
     * @param s the type name
4
     * FIXME: duplicated from the method with the same name in 
5
     * @param model the model
5
     * org.argouml.profile.internal.ModelUtils.
6
     * @return the type or <code>null</code> if the type has not been found.
6
     * 
7
     */
7
     * @param s the type name
8
    public static Object findTypeInModel(String s, Object model) {
8
     * @param model the model
9
9
     * @return the type or <code>null</code> if the type has not been found.
10
        if (!Model.getFacade().isANamespace(model)) {
10
     */
11
            throw new IllegalArgumentException(
11
    public static Object findTypeInModel(String s, Object model) {
12
                    "Looking for the classifier " + s
12
13
                    + " in a non-namespace object of " + model
13
        if (!Model.getFacade().isANamespace(model)) {
14
                    + ". A namespace was expected.");
14
            throw new IllegalArgumentException(
15
        }
15
                    "Looking for the classifier " + s
16
16
                    + " in a non-namespace object of " + model
17
        Collection allClassifiers =
17
                    + ". A namespace was expected.");
18
            Model.getModelManagementHelper()
18
        }
19
                .getAllModelElementsOfKind(model,
19
20
                        Model.getMetaTypes().getClassifier());
20
        Collection allClassifiers =
21
21
            Model.getModelManagementHelper()
22
        for (Object classifier : allClassifiers) {
22
                .getAllModelElementsOfKind(model,
23
            if (Model.getFacade().getName(classifier) != null
23
                        Model.getMetaTypes().getClassifier());
24
                        && Model.getFacade().getName(classifier).equals(s)) {
24
25
                return classifier;
25
        Object[] classifiers = allClassifiers.toArray();
26
            }
26
        Object classifier = null;
27
        }
27
28
28
        for (int i = 0; i < classifiers.length; i++) {
29
        return null;
29
30
    }
30
            classifier = classifiers[i];
31
            if (Model.getFacade().getName(classifier) != null
32
                        && Model.getFacade().getName(classifier).equals(s)) {
33
                return classifier;
34
            }
35
        }
36
37
        return null;
38
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements4
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.778
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    4
    for (Object classifier : allClassifiers)
    4
    for (Object classifier : allClassifiers)
    6
    for (int i = 0; i < classifiers.length; i++)
    Differences
    Expression1Expression2Difference
    java.util.Collectionjava.lang.Object[]VARIABLE_TYPE_MISMATCH
    java.util.Collectionjava.lang.Object[]VARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.util.Collection of variable allClassifiers does not match with type java.lang.Object[] of variable classifiers
    • Make classes java.util.Collection and java.lang.Object[] extend a common superclass
    Type java.util.Collection of variable allClassifiers does not match with type java.lang.Object[] of variable classifiers
    • Make classes java.util.Collection and java.lang.Object[] extend a common superclass
    6
    for (int i = 0; i < classifiers.length; i++)
                                                              
    7
    classifier = classifiers[i];
    Differences
    Expression1Expression2Difference
    java.util.Collectionjava.lang.Object[]VARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.util.Collection of variable allClassifiers does not match with type java.lang.Object[] of variable classifiers
    • Make classes java.util.Collection and java.lang.Object[] extend a common superclass
    7
    classifier = classifiers[i];
    5
    if (Model.getFacade().getName(classifier) != null && Model.getFacade().getName(classifier).equals(s))
    8
    if (Model.getFacade().getName(classifier) != null && Model.getFacade().getName(classifier).equals(s))
    6
    return classifier;
    9
    return classifier;
    Precondition Violations (3)
    Row Violation
    1Type java.util.Collection of variable allClassifiers does not match with type java.lang.Object[] of variable classifiers
    2Type java.util.Collection of variable allClassifiers does not match with type java.lang.Object[] of variable classifiers
    3Type java.util.Collection of variable allClassifiers does not match with type java.lang.Object[] of variable classifiers