public static <T> ChangeNotifier<T> aggregate(Iterable<ChangeNotifier<T>> notifiers) { return new AggregatingChangeNotifier<T>(notifiers); }
private synchronized void checkChange() { Set<T> currentRecords = aggregateSet(); if (ChangeNotifiers.isNoLongerInitial(currentRecords, records) || !currentRecords.equals(records)) { final ChangeNotification<T> changeNotification = newChangeNotification(currentRecords, records); records = currentRecords; fireRecordsUpdated(changeNotification); } }
private Set<T> aggregateSet() { if (areAllInitial(changeNotifiers)) { return ChangeNotifiers.initialEmptyDataInstance(); } ImmutableSet.Builder<T> records = ImmutableSet.builder(); for (final ChangeNotifier<T> changeNotifier : changeNotifiers) { records.addAll(changeNotifier.current()); } return records.build(); }
/** * Create a new aggregating {@link ChangeNotifier}. * * @param changeNotifiers the notifiers to aggregate */ AggregatingChangeNotifier(final Iterable<ChangeNotifier<T>> changeNotifiers) { this.changeNotifiers = ImmutableList.copyOf(changeNotifiers); // Set up forwarding of listeners for (final ChangeNotifier<T> changeNotifier : this.changeNotifiers) { changeNotifier.setListener(new Listener<T>() { @Override public void onChange(final ChangeNotification<T> ignored) { checkChange(); } }, false); } records = aggregateSet(); }
private Set<T> aggregateSet() { if (areAllInitial(changeNotifiers)) { return ChangeNotifiers.initialEmptyDataInstance(); } ImmutableSet.Builder<T> records = ImmutableSet.builder(); for (final ChangeNotifier<T> changeNotifier : changeNotifiers) { records.addAll(changeNotifier.current()); } return records.build(); }
/** * Create a new aggregating {@link ChangeNotifier}. * * @param changeNotifiers the notifiers to aggregate */ AggregatingChangeNotifier(final Iterable<ChangeNotifier<T>> changeNotifiers) { this.changeNotifiers = ImmutableList.copyOf(changeNotifiers); // Set up forwarding of listeners for (final ChangeNotifier<T> changeNotifier : this.changeNotifiers) { changeNotifier.setListener(new Listener<T>() { @Override public void onChange(final ChangeNotification<T> ignored) { checkChange(); } }, false); } records = aggregateSet(); }
private synchronized void checkChange() { Set<T> currentRecords = aggregateSet(); if (ChangeNotifiers.isNoLongerInitial(currentRecords, records) || !currentRecords.equals(records)) { final ChangeNotification<T> changeNotification = newChangeNotification(currentRecords, records); records = currentRecords; fireRecordsUpdated(changeNotification); } }
public static <T> ChangeNotifier<T> aggregate(Iterable<ChangeNotifier<T>> notifiers) { return new AggregatingChangeNotifier<T>(notifiers); }