/** * Returns true if some event is valid. An event is valid if the * element changed in the event is valid. This is determined via a * call to isValidElement. This method can be overriden by * subclasses if they cannot determine if it is a valid event just * by checking the changed element. * * @param e the event * @return boolean true if the event is valid */ protected boolean isValidEvent(PropertyChangeEvent e) { boolean valid = false; if (!(getChangedElement(e) instanceof Collection)) { if ((e.getNewValue() == null && e.getOldValue() != null) // Don't try to test this if we're removing the element || isValidElement(getChangedElement(e))) { valid = true; // we tried to remove a value } } else { Collection col = (Collection) getChangedElement(e); if (!col.isEmpty()) { valid = true; for (Object o : col) { if (!isValidElement(o)) { valid = false; break; } } } else { if (e.getOldValue() instanceof Collection && !((Collection) e.getOldValue()).isEmpty()) { valid = true; } } } return valid; }
/** * Must be different from the extends class because * when we add a sterotype=> remove from available * remove a stereotype=> add to available * Called twices: with a AttributeChangeEvent, and with AddAssociationEvent or RemoveAssociationEvent * * @param e * * @see org.argouml.uml.ui.UMLStereotypeListModel#propertyChange(PropertyChangeEvent) * @since 20110215 */ public void propertyChange(PropertyChangeEvent e) { if (e instanceof AttributeChangeEvent) { // ignored this event } else if (e instanceof AddAssociationEvent) { //Remove the element from Available List boolean valid = false; if (!(getChangedElement(e) instanceof Collection)) { valid = contains(getChangedElement(e)); } else { Collection col = (Collection) getChangedElement(e); Iterator it = col.iterator(); valid = true; while (it.hasNext()) { Object o = it.next(); if (!contains(o)) { valid = false; break; } } } if (valid) { Object o = getChangedElement(e); if (o instanceof Collection) { Iterator it = ((Collection) o).iterator(); while (it.hasNext()) { Object o3 = it.next(); removeElement(o3); } } else { removeElement(o); } } } else if (e instanceof RemoveAssociationEvent) { if (isValidEventRemove(e)) { Object o = getChangedElement(e); if (o instanceof Collection) { ArrayList tempList = new ArrayList((Collection) o); Iterator it = tempList.iterator(); while (it.hasNext()) { Object o2 = it.next(); addElement(o2); } } else { addElement(o); } } } }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java File path: /ArgoUML-0.34-src/argouml/src/argouml-app/src/org/argouml/uml/ui/TabStereotype.java
Method name: boolean isValidEvent(PropertyChangeEvent) Method name: void propertyChange(PropertyChangeEvent)
Number of AST nodes: 4 Number of AST nodes: 5
1
/**
1
/**
2
     * Returns true if some event is valid. An event is valid if the
2
         * Must be different from the extends class because 
3
     * element changed in the event is valid. This is determined via a
3
         * when we add a sterotype=> remove from available
4
     * call to isValidElement.  This method can be overriden by
4
         *         remove a stereotype=> add to available
5
     * subclasses if they cannot determine if it is a valid event just
5
         * Called twices: with a AttributeChangeEvent, and with AddAssociationEvent or RemoveAssociationEvent
6
     * by checking the changed element.
6
         * 
7
     *
7
         * @param e
8
     * @param e the event
8
         * 
9
     * @return boolean true if the event is valid
9
         * @see org.argouml.uml.ui.UMLStereotypeListModel#propertyChange(PropertyChangeEvent)
10
     */
10
         * @since 20110215
11
    protected boolean isValidEvent(PropertyChangeEvent e) {
11
         */
12
        boolean valid = false;
12
        public void propertyChange(PropertyChangeEvent e) {
13
        if (!(getChangedElement(e) instanceof Collection)) {
13
            if (e instanceof AttributeChangeEvent) {
14
            if ((e.getNewValue() == null && e.getOldValue() != null)
14
               // ignored this event
15
                    // Don't try to test this if we're removing the element
15
            } else if (e instanceof AddAssociationEvent) {
16
                    || isValidElement(getChangedElement(e))) {
16
                //Remove the element from Available List
17
                valid = true; // we tried to remove a value
17
                boolean valid = false;
18
            }
18
                if (!(getChangedElement(e) instanceof Collection)) {
19
        } else {
19
                    valid = contains(getChangedElement(e));
20
            Collection col = (Collection) getChangedElement(e);
20
                } else {
21
            if (!col.isEmpty()) {
21
                    Collection col = (Collection) getChangedElement(e);
22
                valid = true;
22
                    Iterator it = col.iterator();
23
                for (Object o : col) {
23
                    valid = true;
24
                    if (!isValidElement(o)) {
24
                    while (it.hasNext()) {
25
                        valid = false;
25
                        Object o = it.next();
26
                        break;
26
                        if (!contains(o)) {
27
                    }
27
                            valid = false;
28
                }
28
                            break;
29
            } else {
29
                        }
30
                if (e.getOldValue() instanceof Collection
30
                    }
31
                    && !((Collection) e.getOldValue()).isEmpty()) {
31
                }
32
                    valid = true;
32
                if (valid) {
33
                }
33
                    Object o = getChangedElement(e);
34
            }
34
                    if (o instanceof Collection) {
35
        }
35
                        Iterator it = ((Collection) o).iterator();
36
        return valid;
36
                        while (it.hasNext()) {
37
    }
37
                            Object o3 = it.next();
38
                            removeElement(o3);
39
                        }
40
                    } else {
41
                        removeElement(o);
42
                    }
43
                }
44
                
45
               
46
                
47
            } else if (e instanceof RemoveAssociationEvent) {
48
                if (isValidEventRemove(e)) {
49
                    Object o = getChangedElement(e);
50
                    if (o instanceof Collection) {
51
                        ArrayList tempList = new ArrayList((Collection) o);
52
                        Iterator it = tempList.iterator();
53
                        while (it.hasNext()) {
54
                            Object o2 = it.next();
55
                            addElement(o2);
56
                        }
57
                    } else {
58
                        addElement(o); 
59
                    }
60
                }
61
                
62
            }
63
        }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements6
    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.500
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    8
    for (Object o : col)
    9
    while (it.hasNext())
                                                  
    10
    Object o = it.next();
    9
    if (!isValidElement(o))
    9
    if (!isValidElement(o))
    11
    if (!contains(o))
    Differences
    Expression1Expression2Difference
    isValidElementcontainsMETHOD_INVOCATION_NAME_MISMATCH
    Preondition Violations
    Expression isValidElement(o) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11
    if (!contains(o))
    10
    valid = false;
    12
    valid = false;
    11
    break;
    13
    break;
    Precondition Violations (1)
    Row Violation
    1Expression isValidElement(o) cannot be parameterized, because it has dependencies to/from statements that will be extracted