+ /**
+ * Extract all the instances of {@code clazz} which were updated in the given set of modifications.
+ *
+ * @param changes The changes to process.
+ * @param clazz The class we're interested in.
+ * @param <T> The type of changes we're interested in.
+ * @param <U> The type of changes to process.
+ * @return The updated instances, mapped by instance identifier.
+ */
+ public static <T extends DataObject, U extends DataObject> Map<InstanceIdentifier<T>, T> extractUpdated(
+ Collection<DataTreeModification<U>> changes, Class<T> clazz) {
+ return extractCreatedOrUpdated(changes, clazz, hasDataBeforeAndDataAfter());
+ }
+
+ /**
+ * Extract all the instance of {@code clazz} which were created or updated in the given set of modifications, and
+ * which satisfy the given filter.
+ *
+ * @param changes The changes to process.
+ * @param clazz The class we're interested in.
+ * @param filter The filter the changes must satisfy.
+ * @param <T> The type of changes we're interested in.
+ * @param <U> The type of changes to process.
+ * @return The created or updated instances which satisfy the filter, mapped by instance identifier.
+ */
+ public static <T extends DataObject, U extends DataObject> Map<InstanceIdentifier<T>, T> extractCreatedOrUpdated(
+ Collection<DataTreeModification<U>> changes, Class<T> clazz,
+ Predicate<DataObjectModification<T>> filter) {
+ Map<InstanceIdentifier<T>, T> result = new HashMap<>();
+ for (Map.Entry<InstanceIdentifier<T>, DataObjectModification<T>> entry : extractDataObjectModifications(changes,
+ clazz, hasDataAfterAndMatchesFilter(filter)).entrySet()) {
+ result.put(entry.getKey(), entry.getValue().getDataAfter());
+ }
+ return result;
+ }
+
+ public static <T extends DataObject> Map<InstanceIdentifier<T>,T> extractCreatedOrUpdated(
+ AsyncDataChangeEvent<InstanceIdentifier<?>,DataObject> changes,Class<T> klazz) {
+ Map<InstanceIdentifier<T>,T> result = extractUpdated(changes,klazz);
+ result.putAll(extractCreated(changes,klazz));
+ return result;
+ }
+
+ /**
+ * Extract all the instances of {@code clazz} which were created or updated in the given set of modifications.
+ *
+ * @param changes The changes to process.
+ * @param clazz The class we're interested in.
+ * @param <T> The type of changes we're interested in.
+ * @param <U> The type of changes to process.
+ * @return The created or updated instances, mapped by instance identifier.
+ */
+ public static <T extends DataObject, U extends DataObject> Map<InstanceIdentifier<T>, T> extractCreatedOrUpdated(
+ Collection<DataTreeModification<U>> changes, Class<T> clazz) {
+ return extractCreatedOrUpdated(changes, clazz, matchesEverything());
+ }
+
+ public static <T extends DataObject> Map<InstanceIdentifier<T>, T> extractCreatedOrUpdatedOrRemoved(
+ AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes,
+ Class<T> klazz) {
+ Map<InstanceIdentifier<T>,T> result = extractCreatedOrUpdated(changes,klazz);
+ result.putAll(extractRemovedObjects(changes, klazz));
+ return result;
+ }
+
+ /**
+ * Extract all the instances of {@code clazz} which were created, updated, or removed in the given set of
+ * modifications. For instances which were created or updated, the new instances are returned; for instances
+ * which were removed, the old instances are returned.
+ *
+ * @param changes The changes to process.
+ * @param clazz The class we're interested in.
+ * @param <T> The type of changes we're interested in.
+ * @param <U> The type of changes to process.
+ * @return The created, updated or removed instances, mapped by instance identifier.
+ */
+ public static <T extends DataObject, U extends DataObject> Map<InstanceIdentifier<T>, T>
+ extractCreatedOrUpdatedOrRemoved(
+ Collection<DataTreeModification<U>> changes, Class<T> clazz) {
+ Map<InstanceIdentifier<T>, T> result = extractCreatedOrUpdated(changes, clazz);
+ result.putAll(extractRemovedObjects(changes, clazz));
+ return result;
+ }
+
+ public static <T extends DataObject> Map<InstanceIdentifier<T>,T> extractOriginal(
+ AsyncDataChangeEvent<InstanceIdentifier<?>,DataObject> changes,Class<T> klazz) {
+ return extract(changes.getOriginalData(),klazz);
+ }
+
+ /**
+ * Extract the original instances of class {@code clazz} in the given set of modifications.
+ *
+ * @param changes The changes to process.
+ * @param clazz The class we're interested in.
+ * @param <T> The type of changes we're interested in.
+ * @param <U> The type of changes to process.
+ * @return The original instances, mapped by instance identifier.
+ */
+ public static <T extends DataObject, U extends DataObject> Map<InstanceIdentifier<T>, T> extractOriginal(
+ Collection<DataTreeModification<U>> changes, Class<T> clazz) {
+ Map<InstanceIdentifier<T>, T> result = new HashMap<>();
+ for (Map.Entry<InstanceIdentifier<T>, DataObjectModification<T>> entry :
+ extractDataObjectModifications(changes, clazz, hasDataBefore()).entrySet()) {
+ result.put(entry.getKey(), entry.getValue().getDataBefore());
+ }
+ return result;
+ }
+
+ public static <T extends DataObject> Set<InstanceIdentifier<T>> extractRemoved(
+ AsyncDataChangeEvent<InstanceIdentifier<?>,DataObject> changes,Class<T> klazz) {
+ Set<InstanceIdentifier<T>> result = new HashSet<>();