/** * Creates a {@link ChangeNotifier} that aggregates the records provided by a list of notifiers. * * <p>A change event on any of the input notifiers will propagate up the the returned notifier. * The set of previous and current records contained in the event will be the union of all * records in the input notifiers, before and after the change event. * * @param notifiers A list of notifiers to aggregate * @param <T> The record type * @return A notifier with the described behaviour */ public static <T> ChangeNotifier<T> aggregate(ChangeNotifier<T>... notifiers) { return aggregate(Arrays.asList(notifiers)); }
static <T> boolean isNoLongerInitial(Set<T> current, Set<T> previous) { return isInitialEmptyData(previous) && !isInitialEmptyData(current); }
/** * Create a {@link ChangeNotifier} with a static set of records. * * <p>This notifier will never generate any change events. Thus any attached * {@link ChangeNotifier.Listener} will at most get one initial call to * {@link ChangeNotifier.Listener#onChange(ChangeNotifier.ChangeNotification)} * if they are attached with the {@code fire} argument set to {@code true}. * * @param records The records that the notifier will contain * @param <T> The record type * @return A notifier with a static set of records */ public static <T> ChangeNotifier<T> staticRecords(T... records) { return staticRecords(Sets.newHashSet(records)); }
@Override public void run() { if (!run) { return; } final Set<T> current = recordsSupplier.get(); if (ChangeNotifiers.isNoLongerInitial(current, records) || !current.equals(records)) { final ChangeNotification<T> changeNotification = newChangeNotification(current, records); records = current; 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(); }
public static <T> RunnableChangeNotifier<T> direct(AtomicReference<Set<T>> recordsHolder) { return new DirectChangeNotifier<T>(supplierFromRef(recordsHolder)); }
@Override public void run() { if (!run) { return; } final Set<T> current = recordsSupplier.get(); if (ChangeNotifiers.isNoLongerInitial(current, records) || !current.equals(records)) { final ChangeNotification<T> changeNotification = newChangeNotification(current, records); records = current; 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(); }
public static <T> RunnableChangeNotifier<T> direct(AtomicReference<Set<T>> recordsHolder) { return new DirectChangeNotifier<T>(supplierFromRef(recordsHolder)); }
static <T> boolean isNoLongerInitial(Set<T> current, Set<T> previous) { return isInitialEmptyData(previous) && !isInitialEmptyData(current); }
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); } }
/** * Creates a {@link ChangeNotifier} that aggregates the records provided by a list of notifiers. * * <p>A change event on any of the input notifiers will propagate up the the returned notifier. * The set of previous and current records contained in the event will be the union of all * records in the input notifiers, before and after the change event. * * @param notifiers A list of notifiers to aggregate * @param <T> The record type * @return A notifier with the described behaviour */ public static <T> ChangeNotifier<T> aggregate(ChangeNotifier<T>... notifiers) { return aggregate(Arrays.asList(notifiers)); }
/** * Create a {@link ChangeNotifier} with a static set of records. * * <p>This notifier will never generate any change events. Thus any attached * {@link ChangeNotifier.Listener} will at most get one initial call to * {@link ChangeNotifier.Listener#onChange(ChangeNotifier.ChangeNotification)} * if they are attached with the {@code fire} argument set to {@code true}. * * @param records The records that the notifier will contain * @param <T> The record type * @return A notifier with a static set of records */ public static <T> ChangeNotifier<T> staticRecords(T... records) { return staticRecords(Sets.newHashSet(records)); }
private Set<T> unmodifiable(Set<T> set) { if (ChangeNotifiers.isInitialEmptyData(set)) { return set; } if (set instanceof ImmutableSet) { return set; } return Collections.unmodifiableSet(set); }
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> unmodifiable(Set<T> set) { if (ChangeNotifiers.isInitialEmptyData(set)) { return set; } if (set instanceof ImmutableSet) { return set; } return Collections.unmodifiableSet(set); }
if (ChangeNotifiers.isNoLongerInitial(current, records) || !current.equals(records)) {
private boolean areAllInitial(List<ChangeNotifier<T>> changeNotifiers) { for (final ChangeNotifier<T> changeNotifier : changeNotifiers) { if (!ChangeNotifiers.isInitialEmptyData(changeNotifier.current())) { return false; } } return true; } }
if (ChangeNotifiers.isNoLongerInitial(current, records) || !current.equals(records)) {
private boolean areAllInitial(List<ChangeNotifier<T>> changeNotifiers) { for (final ChangeNotifier<T> changeNotifier : changeNotifiers) { if (!ChangeNotifiers.isInitialEmptyData(changeNotifier.current())) { return false; } } return true; } }