10-1-2

if (collection.size() == 0) { return false; } boolean isFeatureMap = FeatureMapUtil.isFeatureMap(feature); @SuppressWarnings("unchecked") Collection<Entry> entryCollection = isFeatureMap ? (Collection<Entry>)collection : new BasicEList<Entry>(collection.size()); if (isMany(feature)) { if (feature.isUnique()) { for (Object object : collection) { if (!contains(feature, object)) { Entry entry = createEntry(feature, object); if (!entryCollection.contains(entry)) { entryCollection.add(entry); } } } } else if (!isFeatureMap) { for (Object object : collection) { Entry entry = createEntry(feature, object); entryCollection.add(entry); } } } else { if (collection.size() > 1) { throw new IllegalArgumentException("The multiplicity constraint is violated"); } if (isFeatureMap) { if (contains(feature, collection.iterator().next())) { return false; } } else { FeatureMapUtil.Validator validator = FeatureMapUtil.getValidator(owner.eClass(), feature); Entry [] entries = (Entry[])data; for (int i = 0; i < size; ++i) { Entry entry = entries[i]; if (validator.isValid(entry.getEStructuralFeature())) { if (collection.contains(entry.getValue())) { return false; } else { throw new IllegalArgumentException("The multiplicity constraint is violated"); } } } Entry entry = createEntry(feature, collection.iterator().next()); entryCollection.add(entry); } } return doAddAll(index, entryCollection);
if (collection.size() == 0) { return false; } boolean isFeatureMap = FeatureMapUtil.isFeatureMap(feature); @SuppressWarnings("unchecked") Collection<Entry> entryCollection = isFeatureMap ? (Collection<Entry>)collection : new BasicEList<Entry>(collection.size()); if (isMany(feature)) { if (feature.isUnique()) { for (Object object : collection) { if (!contains(feature, object)) { Entry entry = createEntry(feature, object); if (!entryCollection.contains(entry)) { entryCollection.add(entry); } } } } else if (!isFeatureMap) { for (Object object : collection) { Entry entry = createEntry(feature, object); entryCollection.add(entry); } } } else { if (collection.size() > 1) { throw new IllegalArgumentException("The multiplicity constraint is violated"); } if (isFeatureMap) { if (contains(feature, collection.iterator().next())) { return false; } } else { FeatureMapUtil.Validator validator = FeatureMapUtil.getValidator(owner.eClass(), feature); for (int i = 0, size = delegateSize(); i < size; ++i) { Entry entry = delegateGet(i); if (validator.isValid(entry.getEStructuralFeature())) { if (collection.contains(entry.getValue())) { return false; } else { throw new IllegalArgumentException("The multiplicity constraint is violated"); } } } Entry entry = createEntry(feature, collection.iterator().next()); entryCollection.add(entry); } } return doAddAll(index, entryCollection);

Clone fragments detected by clone detection tool
File path: /emf-2.4.1/src/org/eclipse/emf/ecore/util/BasicFeatureMap.java |  | File path: /emf-2.4.1/src/org/eclipse/emf/ecore/util/DelegatingFeatureMap.java
Method name: `boolean addAll(int, EStructuralFeature, Collection)` |  | Method name: `boolean addAll(int, EStructuralFeature, Collection)`
Number of AST nodes: 31 |  | Number of AST nodes: 30

1

    if (collection.size() == 0)↵

1

    if (collection.size() == 0)↵

2

        {↵

2

        {↵

3

          return false;↵

3

          return false;↵

4

        }↵

4

        }↵

5

        boolean isFeatureMap = FeatureMapUtil.isFeatureMap(feature);↵

5

        boolean isFeatureMap = FeatureMapUtil.isFeatureMap(feature);↵

6

        @SuppressWarnings("unchecked") Collection<Entry> entryCollection = ↵

6

        @SuppressWarnings("unchecked") Collection<Entry> entryCollection = ↵

7

          isFeatureMap ? ↵

7

          isFeatureMap ? ↵

8

            (Collection<Entry>)collection : ↵

8

    (Collection<Entry>)collection : ↵

9

            new BasicEList<Entry>(collection.size());↵

9

    new BasicEList<Entry>(collection.size());↵

10

        if (isMany(feature))↵

10

        if (isMany(feature))↵

11

        {↵

11

        {↵

12

          if (feature.isUnique())↵

12

          if (feature.isUnique())↵

13

          {↵

13

          {↵

14

            for (Object object : collection)↵

14

            for (Object object : collection)↵

15

            {↵

15

            {↵

16

              if (!contains(feature, object))↵

16

              if (!contains(feature, object))↵

17

              {↵

17

              {↵

18

                Entry entry = createEntry(feature, object);↵

18

                Entry entry = createEntry(feature, object);↵

19

                if (!entryCollection.contains(entry))↵

19

                if (!entryCollection.contains(entry))↵

20

                {↵

20

                {↵

21

                  entryCollection.add(entry);↵

21

                  entryCollection.add(entry);↵

22

                }↵

22

                }↵

23

              }↵

23

              }↵

24

            }↵

24

            }↵

25

          }↵

25

          }↵

26

          else if (!isFeatureMap)↵

26

          else if (!isFeatureMap)↵

27

          {↵

27

          {↵

28

            for (Object object : collection)↵

28

            for (Object object : collection)↵

29

            {↵

29

            {↵

30

              Entry entry = createEntry(feature, object);↵

30

              Entry entry = createEntry(feature, object);↵

31

              entryCollection.add(entry);↵

31

              entryCollection.add(entry);↵

32

            }↵

32

            }↵

33

          }↵

33

          }↵

34

        }↵

34

        }↵

35

        else↵

35

        else↵

36

        {↵

36

        {↵

37

          if (collection.size() > 1)↵

37

          if (collection.size() > 1)↵

38

          {↵

38

          {↵

39

            throw new IllegalArgumentException("The multiplicity constraint is violated");↵

39

            throw new IllegalArgumentException("The multiplicity constraint is violated");↵

40

          }↵

40

          }↵

41

          if (isFeatureMap)↵

41

          if (isFeatureMap)↵

42

          {↵

42

          {↵

43

            if (contains(feature, collection.iterator().next()))↵

43

            if (contains(feature, collection.iterator().next()))↵

44

            {↵

44

            {↵

45

              return false;↵

45

              return false;↵

46

            }↵

46

            }↵

47

          }↵

47

          }↵

48

          else↵

48

          else↵

49

          {↵

49

          {↵

50

            FeatureMapUtil.Validator validator = FeatureMapUtil.getValidator(owner.eClass(), feature);↵

50

            FeatureMapUtil.Validator validator = FeatureMapUtil.getValidator(owner.eClass(), feature);↵

51

            Entry [] entries = (Entry[])data;↵

51

            ↵

52

            for (int i = 0; i < size; ++i)↵

52

    for (int i = 0, size = delegateSize(); i < size; ++i)↵

53

            {↵

53

            {↵

54

              Entry entry = entries[i];↵

54

              Entry entry = delegateGet(i);↵

55

              if (validator.isValid(entry.getEStructuralFeature()))↵

55

              if (validator.isValid(entry.getEStructuralFeature()))↵

56

              {↵

56

              {↵

57

                if (collection.contains(entry.getValue()))↵

57

                if (collection.contains(entry.getValue()))↵

58

                {↵

58

                {↵

59

                  return false;↵

59

                  return false;↵

60

                }↵

60

                }↵

61

                else↵

61

                else↵

62

                {↵

62

                {↵

63

                  throw new IllegalArgumentException("The multiplicity constraint is violated");↵

63

                  throw new IllegalArgumentException("The multiplicity constraint is violated");↵

64

                }↵

64

                }↵

65

              }↵

65

              }↵

66

            }↵

66

            }↵

67

            Entry entry = createEntry(feature, collection.iterator().next());↵

67

            Entry entry = createEntry(feature, collection.iterator().next());↵

68

            entryCollection.add(entry);↵

68

            entryCollection.add(entry);↵

69

          }↵

69

          }↵

70

        }↵

70

        }↵

71

        return doAddAll(index, entryCollection);

71

        return doAddAll(index, entryCollection);

See real code fragment |  | See real code fragment

Summary
Number of common nesting structure subtrees | 1
Number of refactorable cases | 0
Number of non-refactorable cases | 1
Time elapsed for finding largest common nesting structure subtrees (ms) | 4.4
Clones location | Clones are in different classes having the same super class
Number of node comparisons | 86

1. {Non-refactorable}

   Mapping Summary
   Number of mapped statements | 30
   Number of unmapped statements in the first code fragment | 1
   Number of unmapped statements in the second code fragment | 0
   Time elapsed for statement mapping (ms) | 68.0
   Clone type | Type 3

   Mapped Statements
   ID | Statement |  | ID | Statement
   --- | --- | --- | --- | ---

   1

       if (collection.size() == 0)

   1

       if (collection.size() == 0)

   2

       return false;

   2

       return false;

   3

       boolean isFeatureMap = FeatureMapUtil.isFeatureMap(feature);

   3

       boolean isFeatureMap = FeatureMapUtil.isFeatureMap(feature);

   4

       @SuppressWarnings("unchecked") Collection<Entry> entryCollection = isFeatureMap ? (Collection<Entry>)collection : new BasicEList<Entry>(collection.size());

   4

       @SuppressWarnings("unchecked") Collection<Entry> entryCollection = isFeatureMap ? (Collection<Entry>)collection : new BasicEList<Entry>(collection.size());

   5

       if (isMany(feature))

   5

       if (isMany(feature))

   6

       if (feature.isUnique())

   6

       if (feature.isUnique())

   7

       for (Object object : collection)

   7

       for (Object object : collection)

   8

       if (!contains(feature, object))

   8

       if (!contains(feature, object))

   9

       Entry entry = createEntry(feature, object);

   9

       Entry entry = createEntry(feature, object);

   10

       if (!entryCollection.contains(entry))

   10

       if (!entryCollection.contains(entry))

   11

       entryCollection.add(entry);

   11

       entryCollection.add(entry);

   12

       else if (!isFeatureMap)

   12

       else if (!isFeatureMap)

   13

       for (Object object : collection)

   13

       for (Object object : collection)

   14

       Entry entry = createEntry(feature, object);

   14

       Entry entry = createEntry(feature, object);

   15

       entryCollection.add(entry);

   15

       entryCollection.add(entry);

       else

       else

   16

       if (collection.size() > 1)

   16

       if (collection.size() > 1)

   17

       throw new IllegalArgumentException("The multiplicity constraint is violated");

   17

       throw new IllegalArgumentException("The multiplicity constraint is violated");

   18

       if (isFeatureMap)

   18

       if (isFeatureMap)

   19

       if (contains(feature, collection.iterator().next()))

   19

       if (contains(feature, collection.iterator().next()))

   20

       return false;

   20

       return false;

       else

       else

   21

       FeatureMapUtil.Validator validator = FeatureMapUtil.getValidator(owner.eClass(), feature);

   21

       FeatureMapUtil.Validator validator = FeatureMapUtil.getValidator(owner.eClass(), feature);

   22

       Entry[] entries = (Entry[])data;

   23

       for (int i = 0; i < size; ++i)

   22

       for (int i = 0, size = delegateSize(); i < size; ++i)

   24

       Entry entry = entries[i];

   24 | Entry entry = entries[i];
   23 | Entry entry = delegateGet(i);

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   entries[i] | delegateGet(i) | TYPE_COMPATIBLE_REPLACEMENT

   Preondition Violations
   Expression entries[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
   Expression delegateGet(i) cannot be parameterized, because it has dependencies to/from statements that will be extracted

   23

       Entry entry = delegateGet(i);

   25

       if (validator.isValid(entry.getEStructuralFeature()))

   24

       if (validator.isValid(entry.getEStructuralFeature()))

   26

       if (collection.contains(entry.getValue()))

   25

       if (collection.contains(entry.getValue()))

   27

       return false;

   26

       return false;

       else

       else

   28

       throw new IllegalArgumentException("The multiplicity constraint is violated");

   27

       throw new IllegalArgumentException("The multiplicity constraint is violated");

   29

       Entry entry = createEntry(feature, collection.iterator().next());

   28

       Entry entry = createEntry(feature, collection.iterator().next());

   30

       entryCollection.add(entry);

   29

       entryCollection.add(entry);

   31

       return doAddAll(index, entryCollection);

   30

       return doAddAll(index, entryCollection);

   Precondition Violations (3)
   Row | Violation
   --- | ---
   1 | Expression entries[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
   2 | Expression delegateGet(i) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   3 | The refactoring of the clones is infeasible, because classes org.eclipse.emf.ecore.util.BasicFeatureMap and org.eclipse.emf.ecore.util.DelegatingFeatureMap do not have a common superclass