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); entryCollection.add(entry); } } } else if (!isFeatureMap) { for (Object object : collection) { Entry entry = createEntry(feature, object); entryCollection.add(entry); } } } 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())) { throw new IllegalArgumentException("The multiplicity constraint is violated"); } } if (collection.size() > 1) { throw new IllegalArgumentException("The multiplicity constraint is violated"); } if (!isFeatureMap) { Entry entry = createEntry(feature, collection.iterator().next()); entryCollection.add(entry); } } return doAddAll(entryIndex(feature, 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); entryCollection.add(entry); } } } else if (!isFeatureMap) { for (Object object : collection) { Entry entry = createEntry(feature, object); entryCollection.add(entry); } } } 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())) { throw new IllegalArgumentException("The multiplicity constraint is violated"); } } if (collection.size() > 1) { throw new IllegalArgumentException("The multiplicity constraint is violated"); } if (!isFeatureMap) { Entry entry = createEntry(feature, collection.iterator().next()); entryCollection.add(entry); } } return doAddAll(entryIndex(feature, 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(EStructuralFeature, int, Collection) Method name: boolean addAll(EStructuralFeature, int, Collection)
Number of AST nodes: 26 Number of AST nodes: 25
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
            entryCollection.add(entry);
19
            entryCollection.add(entry);
20
          }
20
          }
21
        }
21
        }
22
      }
22
      }
23
      else if (!isFeatureMap)
23
      else if (!isFeatureMap)
24
      {
24
      {
25
        for (Object object : collection)
25
        for (Object object : collection)
26
        {
26
        {
27
          Entry entry = createEntry(feature, object);
27
          Entry entry = createEntry(feature, object);
28
          entryCollection.add(entry);
28
          entryCollection.add(entry);
29
        }
29
        }
30
      }
30
      }
31
    }
31
    }
32
    else
32
    else
33
    {
33
    {
34
      FeatureMapUtil.Validator validator = FeatureMapUtil.getValidator(owner.eClass(), feature);
34
      FeatureMapUtil.Validator validator = FeatureMapUtil.getValidator(owner.eClass(), feature);
35
      Entry [] entries = (Entry[])data;
35
      
36
      for (int i = 0; i < size; ++i)
36
for (int i = 0, size = delegateSize(); i < size; ++i)
37
      {
37
      {
38
        Entry entry = entries[i];
38
        Entry entry = delegateGet(i);
39
        if (validator.isValid(entry.getEStructuralFeature()))
39
        if (validator.isValid(entry.getEStructuralFeature()))
40
        {
40
        {
41
          throw new IllegalArgumentException("The multiplicity constraint is violated");
41
          throw new IllegalArgumentException("The multiplicity constraint is violated");
42
        }
42
        }
43
      }
43
      }
44
      if (collection.size() > 1)
44
      if (collection.size() > 1)
45
      {
45
      {
46
        throw new IllegalArgumentException("The multiplicity constraint is violated");
46
        throw new IllegalArgumentException("The multiplicity constraint is violated");
47
      }
47
      }
48
      if (!isFeatureMap)
48
      if (!isFeatureMap)
49
      {
49
      {
50
        Entry entry = createEntry(feature, collection.iterator().next());
50
        Entry entry = createEntry(feature, collection.iterator().next());
51
        entryCollection.add(entry);
51
        entryCollection.add(entry);
52
      }
52
      }
53
    }
53
    }
54
    return doAddAll(entryIndex(feature, index), entryCollection);
54
    return doAddAll(entryIndex(feature, index), entryCollection);
Summary
Number of common nesting structure subtrees2
Number of refactorable cases2
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.8
Clones locationClones are in different classes having the same super class
Number of node comparisons23
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements3
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)2.6
    Clone typeType 1
    Mapped Statements
    ID Statement ID Statement
    8
    if (!contains(feature, object))
    8
    if (!contains(feature, object))
    9
    Entry entry = createEntry(feature, object);
    9
    Entry entry = createEntry(feature, object);
    10
    entryCollection.add(entry);
    10
    entryCollection.add(entry);
    Precondition Violations (0)
    Row Violation
  2. {Refactorable}
    Mapping Summary
    Number of mapped statements3
    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.8
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    18
    Entry entry = entries[i];
    18
    Entry entry = entries[i];
    17
    Entry entry = delegateGet(i);
    Differences
    Expression1Expression2Difference
    entries[i]delegateGet(i)TYPE_COMPATIBLE_REPLACEMENT
    17
    Entry entry = delegateGet(i);
    19
    if (validator.isValid(entry.getEStructuralFeature()))
    18
    if (validator.isValid(entry.getEStructuralFeature()))
    20
    throw new IllegalArgumentException("The multiplicity constraint is violated");
    19
    throw new IllegalArgumentException("The multiplicity constraint is violated");
    Precondition Violations (0)
    Row Violation