/** * Find a class within the given namespace that has the given identifier. * * @param identifier the class identifier * @param ns namespace to look in * @return the class if found, null otherwise */ private static Object findClass(String identifier, Object ns) { Collection classes = getCoreHelper().getAllClasses(ns); Iterator it = classes.iterator(); while (it.hasNext()) { Object candidateClass = it.next(); if (Model.getFacade().getName(candidateClass).equals(identifier)) { return candidateClass; } } return null; }
/** * Search the attribute named <code>attributeName</code> in the given * relation. If there exist more than one attribute the first one is * returned. * * @param relation * The relation in which to search the attribute. * @param attributeName * The name of the attribute to search. * @return The attribute if found, <code>null</code> else. */ public static Object getAttributeForName(Object relation, String attributeName) { Object attribute = null; Collection attributes = Model.getFacade().getAttributes(relation); for (Iterator it = attributes.iterator(); it.hasNext();) { Object attr = it.next(); if (Model.getFacade().getName(attr).equals(attributeName)) { attribute = attr; break; } } return attribute; }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml-cpp/src/org/argouml/language/cpp/reveng/ModelerImpl.java File path: /ArgoUML-0.34-src/argouml-sql/src/org/argouml/language/sql/Utils.java
Method name: Object findClass(String, Object) Method name: Object getAttributeForName(Object, String)
Number of AST nodes: 4 Number of AST nodes: 5
1
/**
1
/**
2
     * Find a class within the given namespace that has the given identifier.
2
     * Search the attribute named <code>attributeName</code> in the given
3
     *
3
     * relation. If there exist more than one attribute the first one is
4
     * @param identifier the class identifier
4
     * returned.
5
     * @param ns namespace to look in
5
     * 
6
     * @return the class if found, null otherwise
6
     * @param relation
7
     */
7
     *            The relation in which to search the attribute.
8
    private static Object findClass(String identifier, Object ns) {
8
     * @param attributeName
9
        Collection classes = getCoreHelper().getAllClasses(ns);
9
     *            The name of the attribute to search.
10
        Iterator it = classes.iterator();
10
     * @return The attribute if found, <code>null</code> else.
11
        while (it.hasNext()) {
11
     */
12
            Object candidateClass = it.next();
12
    public static Object getAttributeForName(Object relation,
13
            if (Model.getFacade().getName(candidateClass).equals(identifier)) {
13
            String attributeName) {
14
                return candidateClass;
14
        Object attribute = null;
15
            }
15
16
        }
16
        Collection attributes = Model.getFacade().getAttributes(relation);
17
        return null;
17
        for (Iterator it = attributes.iterator(); it.hasNext();) {
18
    }
18
            Object attr = it.next();
19
            if (Model.getFacade().getName(attr).equals(attributeName)) {
20
                attribute = attr;
21
                break;
22
            }
23
        }
24
25
        return attribute;
26
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements6
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment2
    Time elapsed for statement mapping (ms)0.0
    Similarity Score1.000
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    3
    while (it.hasNext())
    3
    while (it.hasNext())
    3
    for (Iterator it = attributes.iterator(); it.hasNext(); )
    Differences
    Expression1Expression2Difference
    candidateClassattrVARIABLE_NAME_MISMATCH
    3
    for (Iterator it = attributes.iterator(); it.hasNext(); )
    4
    Object candidateClass = it.next();
    4
    Object candidateClass = it.next();
    4
    Object attr = it.next();
    Differences
    Expression1Expression2Difference
    candidateClassattrVARIABLE_NAME_MISMATCH
    4
    Object attr = it.next();
    5
    if (Model.getFacade().getName(candidateClass).equals(identifier))
    5
    if (Model.getFacade().getName(candidateClass).equals(identifier))
    5
    if (Model.getFacade().getName(attr).equals(attributeName))
    Differences
    Expression1Expression2Difference
    identifierattributeNameVARIABLE_NAME_MISMATCH
    candidateClassattrVARIABLE_NAME_MISMATCH
    5
    if (Model.getFacade().getName(attr).equals(attributeName))
                                        
    6
    attribute = attr;
    Preondition Violations
    Unmatched statement attribute=attr; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6
    attribute = attr;
    6
    return candidateClass;
    6
    return candidateClass;
    Preondition Violations
    Unmatched statement return candidateClass; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched return candidateClass;
                                                      
                      
    7
    break;
    Preondition Violations
    Unmatched break;
    7
    break;
    Precondition Violations (4)
    Row Violation
    1Unmatched statement attribute=attr; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement return candidateClass; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched return candidateClass;
    4Unmatched break;