/** * Adds elements from collection without duplicates. */ private void addCollection(Collection c, Collection v) { for (Object o : c) { if (!v.contains(o)) { v.add(o); } } }
/** * Update a collection using a minimal update strategy and updating the * collection in place. This can be used with the JMI "live" semantic * collections to update the model in place. Order of processing is to first * remove all obsolete elements from the collection and then add all new * elements. * * @param base * the base collection to be updated * @param updates * desired end state of collection */ static void update(Collection base, Collection updates) { if (updates == null) { base.clear(); return; } Collection toBeRemoved = new ArrayList(); Collection toBeAdded = new ArrayList(); Iterator oldIt = base.iterator(); while (oldIt.hasNext()) { Object obj = oldIt.next(); if (!updates.contains(obj)) { toBeRemoved.add(obj); } } Iterator newIt = updates.iterator(); while (newIt.hasNext()) { Object obj = newIt.next(); if (!base.contains(obj)) { toBeAdded.add(obj); } } base.removeAll(toBeRemoved); base.addAll(toBeAdded); }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml/src/argouml-app/src/org/argouml/uml/ui/ActionGenerateAll.java File path: /ArgoUML-0.34-src/argouml/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CollectionHelper.java
Method name: void addCollection(Collection, Collection) Method name: void update(Collection, Collection)
Number of AST nodes: 3 Number of AST nodes: 4
1
/**
1
/**
2
     * Adds elements from collection without duplicates.
2
     * Update a collection using a minimal update strategy and updating the
3
     */
3
     * collection in place. This can be used with the JMI "live" semantic
4
    private void addCollection(Collection c, Collection v) {
4
     * collections to update the model in place. Order of processing is to first
5
        for (Object o : c) {
5
     * remove all obsolete elements from the collection and then add all new
6
            if (!v.contains(o)) {
6
     * elements.
7
                v.add(o);
7
     * 
8
            }
8
     * @param base
9
        }
9
     *            the base collection to be updated
10
    }
10
     * @param updates
11
     *            desired end state of collection
12
     */
13
    static void update(Collection base, Collection updates) {
14
        if (updates == null) {
15
            base.clear();
16
            return;
17
        }
18
        Collection toBeRemoved = new ArrayList();
19
        Collection toBeAdded = new ArrayList();
20
21
        Iterator oldIt = base.iterator();
22
        while (oldIt.hasNext()) {
23
            Object obj = oldIt.next();
24
            if (!updates.contains(obj)) {
25
                toBeRemoved.add(obj);
26
            }
27
        }
28
        Iterator newIt = updates.iterator();
29
        while (newIt.hasNext()) {
30
            Object obj = newIt.next();
31
            if (!base.contains(obj)) {
32
                toBeAdded.add(obj);
33
            }
34
        }
35
        
36
        base.removeAll(toBeRemoved);
37
        base.addAll(toBeAdded);
38
    }
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements5
    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 Score1.000
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    for (Object o : c)
    1
    for (Object o : c)
    7
    while (oldIt.hasNext())
    Differences
    Expression1Expression2Difference
    oobjVARIABLE_NAME_MISMATCH
    7
    while (oldIt.hasNext())
                                                          
    8
    Object obj = oldIt.next();
    Differences
    Expression1Expression2Difference
    oobjVARIABLE_NAME_MISMATCH
    8
    Object obj = oldIt.next();
    2
    if (!v.contains(o))
    2
    if (!v.contains(o))
    9
    if (!updates.contains(obj))
    Differences
    Expression1Expression2Difference
    oobjVARIABLE_NAME_MISMATCH
    vupdatesVARIABLE_NAME_MISMATCH
    9
    if (!updates.contains(obj))
    3
    v.add(o);
    3
    v.add(o);
    10
    toBeRemoved.add(obj);
    Differences
    Expression1Expression2Difference
    oobjVARIABLE_NAME_MISMATCH
    vtoBeRemovedVARIABLE_NAME_MISMATCH
    10
    toBeRemoved.add(obj);
    Precondition Violations (0)
    Row Violation