/** * 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; }
/** * @param e * @return * @see org.argouml.uml.ui.UMLStereotypeListModel#isValidEvent(java.beans.PropertyChangeEvent) * @since 20110215 */ private boolean isValidEventRemove(PropertyChangeEvent e) { boolean valid = false; if (!(getChangedElement(e) instanceof Collection)) { if ((e.getNewValue() != null && e.getOldValue() == null) || isValidElement(getChangedElement(e))) { valid = true; // we tried to remove a value } } else { Collection col = (Collection) getChangedElement(e); Iterator it = col.iterator(); if (!col.isEmpty()) { valid = true; while (it.hasNext()) { Object o = it.next(); if (!isValidElement(o)) { valid = false; break; } } } else { if (e.getOldValue() instanceof Collection && !((Collection) e.getOldValue()).isEmpty()) { valid = true; } } } return valid; }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLComboBoxModel.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: boolean isValidEventRemove(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
         * @param e
3
     * element changed in the event is valid. This is determined via a
3
         * @return
4
     * call to isValidElement.  This method can be overriden by
4
         * @see org.argouml.uml.ui.UMLStereotypeListModel#isValidEvent(java.beans.PropertyChangeEvent)
5
     * subclasses if they cannot determine if it is a valid event just
5
         * @since 20110215
6
     * by checking the changed element.
6
         */
7
     *
7
        private boolean isValidEventRemove(PropertyChangeEvent e) {
8
     * @param e the event
8
            boolean valid = false;
9
     * @return boolean true if the event is valid
9
            if (!(getChangedElement(e) instanceof Collection)) {
10
     */
10
               
11
    protected boolean isValidEvent(PropertyChangeEvent e) {
11
                if ((e.getNewValue() != null && e.getOldValue() == null) 
12
        boolean valid = false;
12
                        || isValidElement(getChangedElement(e))) {
13
        if (!(getChangedElement(e) instanceof Collection)) {
13
                    valid = true; // we tried to remove a value
14
            if ((e.getNewValue() == null && e.getOldValue() != null)
14
                }
15
                    // Don't try to test this if we're removing the element
15
            } else {
16
                    || isValidElement(getChangedElement(e))) {
16
                Collection col = (Collection) getChangedElement(e);
17
                valid = true; // we tried to remove a value
17
                Iterator it = col.iterator();
18
            }
18
                if (!col.isEmpty()) {
19
        } else {
19
                    valid = true;
20
            Collection col = (Collection) getChangedElement(e);
20
                    while (it.hasNext()) {
21
            if (!col.isEmpty()) {
21
                        Object o = it.next();
22
                valid = true;
22
                        if (!isValidElement(o)) {
23
                for (Object o : col) {
23
                            valid = false;
24
                    if (!isValidElement(o)) {
24
                            break;
25
                        valid = false;
25
                        }
26
                        break;
26
                    }
27
                    }
27
                } else {
28
                }
28
                    if (e.getOldValue() instanceof Collection
29
            } else {
29
                        && !((Collection) e.getOldValue()).isEmpty()) {
30
                if (e.getOldValue() instanceof Collection
30
                        valid = true;
31
                    && !((Collection) e.getOldValue()).isEmpty()) {
31
                    }
32
                    valid = true;
32
                }
33
                }
33
            }
34
            }
34
            return valid;
35
        }
35
        }
36
        return valid;
37
    }
  1. {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 1
    Mapped Statements
    ID Statement ID Statement
    8
    for (Object o : col)
    9
    while (it.hasNext())
                                                  
    10
    Object o = it.next();
    9
    if (!isValidElement(o))
    11
    if (!isValidElement(o))
    10
    valid = false;
    12
    valid = false;
    11
    break;
    13
    break;
    Precondition Violations (0)
    Row Violation