public static Specifier make()

in src/org/jetbrains/ether/dependencyView/Difference.java [33:108]


    public static <T> Specifier<T> make(final Set<T> past, final Set<T> now) {
        if (past == null) {
            final Collection<T> removed = new HashSet<T>();
            final Collection<Pair<T, Difference>> changed = new HashSet<Pair<T, Difference>>();

            return new Specifier<T>() {
                public Collection<T> added() {
                    return now;
                }

                public Collection<T> removed() {
                    return removed;
                }

                public Collection<Pair<T, Difference>> changed() {
                    return changed;
                }

                public boolean unchanged() {
                    return false;
                }
            };
        }

        final Set<T> added = new HashSet<T>(now);

        added.removeAll(past);

        final Set<T> removed = new HashSet<T>(past);

        removed.removeAll(now);

        final Set<Pair<T, Difference>> changed = new HashSet<Pair<T, Difference>>();
        final Set<T> intersect = new HashSet<T>(past);
        final Map<T, T> nowMap = new HashMap<T, T>();

        for (T s : now) {
            if (intersect.contains(s)) {
                nowMap.put(s, s);
            }
        }

        intersect.retainAll(now);

        for (T x : intersect) {
            final T y = nowMap.get(x);

            if (x instanceof Proto) {
                final Proto px = (Proto) x;
                final Proto py = (Proto) y;
                final Difference diff = py.difference(px);

                if (!diff.no()) {
                    changed.add(new Pair<T, Difference>(x, diff));
                }
            }
        }

        return new Specifier<T>() {
            public Collection<T> added() {
                return added;
            }

            public Collection<T> removed() {
                return removed;
            }

            public Collection<Pair<T, Difference>> changed() {
                return changed;
            }

            public boolean unchanged() {
                return changed.isEmpty() && added.isEmpty() && removed.isEmpty();
            }
        };
    }