public boolean isConnectionValid(Object connectionType, Object fromElement, Object toElement, boolean checkWFR) { // Get the list of valid model item pairs for the given connection type List validItems = (ArrayList) validConnectionMap.get(connectionType); if (validItems == null) { return false; } // See if there's a pair in this list that match the given // model elements Iterator it = validItems.iterator(); while (it.hasNext()) { Class[] modeElementPair = (Class[]) it.next(); if (modeElementPair[0].isInstance(fromElement) && modeElementPair[1].isInstance(toElement)) { if (checkWFR) { return isConnectionWellformed( (Class) connectionType, (Element) fromElement, (Element) toElement); } else { return true; } } } return false; }
public boolean isConnectionValid(Object connectionType, Object fromElement, Object toElement, boolean checkWFR) { if (Model.getModelManagementHelper().isReadOnly(fromElement)) { // Don't allow connections to be created from a read only // model element to any other // TODO: This should be considered a workaround. It only works // because, by default, we place newly created relationships in // the namespace of the fromElement. The correct behavior in // the presence of read-only elements really depends on the type of // connection as well as the writeability of both ends. return false; } // Get the list of valid model item pairs for the given connection type List<Class<?>[]> validItems = validConnectionMap.get(connectionType); if (validItems == null) { return false; } // See if there's a pair in this list that match the given // model elements for (Class<?>[] modeElementPair : validItems) { if (modeElementPair[0].isInstance(fromElement) && modeElementPair[1].isInstance(toElement)) { if (checkWFR) { return isConnectionWellformed( (Class<?>) connectionType, (ModelElement) fromElement, (ModelElement) toElement); } else { return true; } } } return false; }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml/src/argouml-core-model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java File path: /ArgoUML-0.34-src/argouml/src/argouml-core-model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java
Method name: boolean isConnectionValid(Object, Object, Object, boolean) Method name: boolean isConnectionValid(Object, Object, Object, boolean)
Number of AST nodes: 6 Number of AST nodes: 5
1
public boolean isConnectionValid(Object connectionType, Object fromElement,
1
public boolean isConnectionValid(Object connectionType, Object fromElement,
2
            Object toElement, boolean checkWFR) {
2
            Object toElement, boolean checkWFR) {
3
        // Get the list of valid model item pairs for the given connection type
3
        if (Model.getModelManagementHelper().isReadOnly(fromElement)) {
4
        List validItems = (ArrayList) validConnectionMap.get(connectionType);
4
            // Don't allow connections to be created from a read only
5
        if (validItems == null) {
5
            // model element to any other
6
            return false;
6
            // TODO: This should be considered a workaround.  It only works
7
        }
7
            // because, by default, we place newly created relationships in
8
        // See if there's a pair in this list that match the given
8
            // the namespace of the fromElement.  The correct behavior in
9
        // model elements
9
            // the presence of read-only elements really depends on the type of
10
        Iterator it = validItems.iterator();
10
            // connection as well as the writeability of both ends.
11
        while (it.hasNext()) {
11
            return false;
12
            Class[] modeElementPair = (Class[]) it.next();
12
        }
13
            if (modeElementPair[0].isInstance(fromElement)
13
        // Get the list of valid model item pairs for the given connection type
14
                && modeElementPair[1].isInstance(toElement)) {
14
        List<Class<?>[]> validItems = validConnectionMap.get(connectionType);
15
                if (checkWFR) {
15
        if (validItems == null) {
16
                    return isConnectionWellformed(
16
            return false;
17
                            (Class) connectionType,
17
        }
18
                            (Element) fromElement,
18
        // See if there's a pair in this list that match the given
19
                            (Element) toElement);
19
        // model elements
20
                } else {
20
        for (Class<?>[] modeElementPair : validItems) {
21
                    return true;
21
            if (modeElementPair[0].isInstance(fromElement)
22
                }
22
                    && modeElementPair[1].isInstance(toElement)) {
23
            }
23
                if (checkWFR) {
24
        }
24
                    return isConnectionWellformed(
25
        return false;
25
                            (Class<?>) connectionType,
26
    }
26
                            (ModelElement) fromElement,
27
                            (ModelElement) toElement);
28
                } else {
29
                    return true;
30
                }
31
            }
32
        }
33
        return false;
34
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements7
    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.308
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    5
    while (it.hasNext())
    5
    while (it.hasNext())
    6
    for (Class<?>[] modeElementPair : validItems)
    Differences
    Expression1Expression2Difference
    java.util.Listjava.util.List[]>VARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.util.List of variable validItems does not match with type java.util.List<java.lang.Class<?>[]> of variable validItems
    • Make classes java.util.List and java.util.List[]> extend a common superclass
    6
    for (Class<?>[] modeElementPair : validItems)
    6
    Class[] modeElementPair = (Class[])it.next();
                                                                                                
    7
    if (modeElementPair[0].isInstance(fromElement) && modeElementPair[1].isInstance(toElement))
    7
    if (modeElementPair[0].isInstance(fromElement) && modeElementPair[1].isInstance(toElement))
    7
    if (modeElementPair[0].isInstance(fromElement) && modeElementPair[1].isInstance(toElement))
    Differences
    Expression1Expression2Difference
    java.lang.Class[]java.lang.Class[]VARIABLE_TYPE_MISMATCH
    java.lang.Class[]java.lang.Class[]VARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.lang.Class[] of variable modeElementPair does not match with type java.lang.Class<?>[] of variable modeElementPair
    • Make classes java.lang.Class[] and java.lang.Class[] extend a common superclass
    Type java.lang.Class[] of variable modeElementPair does not match with type java.lang.Class<?>[] of variable modeElementPair
    • Make classes java.lang.Class[] and java.lang.Class[] extend a common superclass
    7
    if (modeElementPair[0].isInstance(fromElement) && modeElementPair[1].isInstance(toElement))
    8
    if (checkWFR)
    8
    if (checkWFR)
    9
    return isConnectionWellformed((Class)connectionType, (Element)fromElement, (Element)toElement);
    9
    return isConnectionWellformed((Class<?>)connectionType, (ModelElement)fromElement, (ModelElement)toElement);
    else
    else
    10
    return true;
    10
    return true;
    10
    return true;
    Preondition Violations
    Conditional return true;
    Conditional return true;
    10
    return true;
    Precondition Violations (5)
    Row Violation
    1Type java.util.List of variable validItems does not match with type java.util.List<java.lang.Class<?>[]> of variable validItems
    2Type java.lang.Class[] of variable modeElementPair does not match with type java.lang.Class<?>[] of variable modeElementPair
    3Type java.lang.Class[] of variable modeElementPair does not match with type java.lang.Class<?>[] of variable modeElementPair
    4Conditional return true;
    5Conditional return true;