protected final void logManyChanges()

in impl/src/main/java/org/apache/tuscany/sdo/util/resource/ChangeSummaryStreamDeserializer.java [467:572]


    protected final void logManyChanges(PropertyMapChanges propertyMapChanges, EObject referent, Collection featureChanges) {
        for (Iterator lists = propertyMapChanges.lists.entrySet().iterator(); lists.hasNext();) {
            /*
             * Compute ListChanges out of comparision of old and new list
             */
            Map.Entry entry = (Map.Entry) lists.next();
            EStructuralFeature property = (EStructuralFeature) entry.getKey();
            Iterator values = ((Collection) entry.getValue()).iterator(); // old list
            Object value = referent.eGet(property);
            List list = value instanceof FeatureMap.Internal.Wrapper ? ((FeatureMap.Internal.Wrapper) value).featureMap() : (List) value; // new
            int change = 0;
            FeatureChange featureChange = changeSettingFactory == null ? changeFactory.createFeatureChange() : (FeatureChange) changeSettingFactory
                    .createChangeSummarySetting();
            featureChange.setFeature(property);
            Collection listChanges = featureChange.getListChanges(), adds = null;
            featureChanges.add(featureChange);
            if (property.getEType() instanceof EClass) {
                /*
                 * Log child DataObject changes
                 */
                int begin = 0, end = list.size();
                while (values.hasNext()) {
                    value = values.next();
                    if (value.getClass() == Ref.class) {
                        value = referent((Ref) value);
                        if (value == null)
                            continue;// report error?
                    }
                    // values.remove();
                    for (int index = begin;/* true */; ++index)
                        if (index == end) {
                            adds = add(adds, change, listChanges, value);
                            break;
                        } else if (list.get(index) == value) // List#indexOf uses equals
                        {
                            begin = remove(begin, index, change, listChanges, list);
                            ++begin;
                            adds = null;
                            break;
                        }
                    ++change;
                }
                remove(begin, end, change, listChanges, list);
            } else if (FeatureMapUtil.isFeatureMap(property)) {
                /*
                 * Log Sequence changes
                 */
                int begin = 0, end = list.size();
                while (values.hasNext()) {
                    FeatureMapEntry featureMapEntry = (FeatureMapEntry) values.next();
                    value = featureMapEntry.getValue();
                    if (value.getClass() == Ref.class) {
                        value = referent((Ref) value);
                        if (value == null)
                            continue;// report error?
                    }
                    // values.remove();
                    Comparator equality;
                    ETypedElement feature = featureMapEntry.getFeature();
                    if (((Type) feature.getEType()).isDataType())
                        if (value == null)
                            equality = EQUAL_NULL;
                        else
                            equality = EQUAL;
                    else
                        equality = SAME;
                    for (int index = begin;/* true */; ++index)
                        if (index == end) {
                            adds = add(adds, change, listChanges, featureMapEntry);
                            break;
                        } else {
                            FeatureMap.Entry fme = (FeatureMap.Entry) list.get(index);
                            if (feature == fme.getEStructuralFeature() && equality.compare(fme.getValue(), value) == 0) {
                                begin = remove(begin, index, change, listChanges, list);
                                ++begin;
                                adds = null;
                                break;
                            }
                        }
                    ++change;
                }
                remove(begin, end, change, listChanges, list);
            } else {
                /*
                 * Log simple value changes
                 */
                while (values.hasNext()) {
                    value = values.next();
                    // values.remove();
                    int index = list.indexOf(value);
                    switch (index) {
                    case -1:
                        adds = add(adds, change, listChanges, value);
                        break;
                    default:
                        remove(change, listChanges, list, 0, index);
                    case 0:
                        list = list.subList(++index, list.size());
                        adds = null;
                    }
                    ++change;
                }
                remove(0, list.size(), change, listChanges, list);
            }
        }
    }