/** * 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 valid */ protected boolean isValidEvent(PropertyChangeEvent e) { boolean valid = false; if (!(getChangedElement(e) instanceof Collection)) { // TODO: Considering all delete events to be valid like below // is going to cause lots of unecessary work and some problems if ((e.getNewValue() == null && e.getOldValue() != null) // Don't test changed element if it was deleted || 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; }
/** * 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; }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml/src/argouml-app/src/org/argouml/uml/ui/UMLStereotypeListModel.java File path: /ArgoUML-0.34-src/argouml/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLComboBoxModel.java
Method name: boolean isValidEvent(PropertyChangeEvent) Method name: boolean isValidEvent(PropertyChangeEvent)
Number of AST nodes: 5 Number of AST nodes: 4
1
/**
1
/**
2
     * Returns true if some event is valid. An event is valid if the
2
     * Returns true if some event is valid. An event is valid if the
3
     * element changed in the event is valid. This is determined via a
3
     * element changed in the event is valid. This is determined via a
4
     * call to isValidElement.  This method can be overriden by
4
     * call to isValidElement.  This method can be overriden by
5
     * subclasses if they cannot determine if it is a valid event just
5
     * subclasses if they cannot determine if it is a valid event just
6
     * by checking the changed element.
6
     * by checking the changed element.
7
     *
7
     *
8
     * @param e the event
8
     * @param e the event
9
     * @return boolean true if valid
9
     * @return boolean true if the event is valid
10
     */
10
     */
11
    protected boolean isValidEvent(PropertyChangeEvent e) {
11
    protected boolean isValidEvent(PropertyChangeEvent e) {
12
        boolean valid = false;
12
        boolean valid = false;
13
        if (!(getChangedElement(e) instanceof Collection)) {
13
        if (!(getChangedElement(e) instanceof Collection)) {
14
            // TODO: Considering all delete events to be valid like below
14
            if ((e.getNewValue() == null && e.getOldValue() != null)
15
            // is going to cause lots of unecessary work and some problems
15
                    // Don't try to test this if we're removing the element
16
            if ((e.getNewValue() == null && e.getOldValue() != null)
16
                    || isValidElement(getChangedElement(e))) {
17
                    // Don't test changed element if it was deleted
17
                valid = true; // we tried to remove a value
18
                    || isValidElement(getChangedElement(e))) {
18
            }
19
                valid = true; // we tried to remove a value
19
        } else {
20
            }
20
            Collection col = (Collection) getChangedElement(e);
21
        } else {
21
            if (!col.isEmpty()) {
22
            Collection col = (Collection) getChangedElement(e);
22
                valid = true;
23
            Iterator it = col.iterator();
23
                for (Object o : col) {
24
            if (!col.isEmpty()) {
24
                    if (!isValidElement(o)) {
25
                valid = true;
25
                        valid = false;
26
                while (it.hasNext()) {
26
                        break;
27
                    Object o = it.next();
27
                    }
28
                    if (!isValidElement(o)) {
28
                }
29
                        valid = false;
29
            } else {
30
                        break;
30
                if (e.getOldValue() instanceof Collection
31
                    }
31
                    && !((Collection) e.getOldValue()).isEmpty()) {
32
                }
32
                    valid = true;
33
            } else {
33
                }
34
                if (e.getOldValue() instanceof Collection
34
            }
35
                    && !((Collection) e.getOldValue()).isEmpty()) {
35
        }
36
                    valid = true;
36
        return valid;
37
                }
37
    }
38
            }
39
        }
40
        return valid;
41
    }
  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
    9
    while (it.hasNext())
    8
    for (Object o : col)
    10
    Object o = it.next();
                                                  
    11
    if (!isValidElement(o))
    9
    if (!isValidElement(o))
    12
    valid = false;
    10
    valid = false;
    13
    break;
    11
    break;
    Precondition Violations (0)
    Row Violation