Class InstancesDiff
- java.lang.Object
-
- org.apache.sling.discovery.commons.InstancesDiff
-
public final class InstancesDiff extends java.lang.ObjectTheInstancesDiffallows to combine and filter two collections ofInstanceDescriptioninstances, an "old" collection and a "new" collection.The comparison between
InstanceDescriptioninstances is done only on the basis of the Sling identifier. Two instances with the same Sling identifier are considered as equal.Note: Each collection must contain only unique instances (no two instances with the same Sling identifier). Using the
InstancesDiffwith collections containing duplicated Sling id will throw anIllegalArgumentException.- Since:
- 1.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classInstancesDiff.InstanceCollectionTheInstanceCollectioncollection allows to filter the instances using a set of custom filter either implementingInstanceFilteror pre-defined ones.
-
Constructor Summary
Constructors Constructor Description InstancesDiff(java.util.Collection<T> oldInstances, java.util.Collection<T> newInstances)Create a newInstancesDiffbased on the provided old and newCollectioncollections of instances.InstancesDiff(ClusterView oldView, ClusterView newView)Create a newInstancesDiffbased on the instances from the old and newClusterViewcluster views provided.InstancesDiff(TopologyEvent event)Create a newInstancesDiffbased on the instances from the old and newTopologyViewtopology views contained in theTopologyEventevent provided.InstancesDiff(TopologyView oldView, TopologyView newView)Create a newInstancesDiffbased on the instances from the old and newTopologyViewtopology views provided.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InstancesDiff.InstanceCollectionadded()Returns theInstanceCollectioncollection containing theInstanceDescriptioninstances that are contained in the new collection but not in the old collection.InstancesDiff.InstanceCollectionall(boolean retainFromNewCollection)Returns theInstanceSetset containing theInstanceDescriptioninstances that are contained in either the old or the new collection.InstancesDiff.InstanceCollectionremoved()Returns theInstanceCollectioncollection containing theInstanceDescriptioninstances that are contained in the old collection but not in the new collection.InstancesDiff.InstanceCollectionretained(boolean retainFromNewCollection)Returns theInstanceSetcollection containing theInstanceDescriptioninstances that are contained in both the old collection and the new collection.InstancesDiff.InstanceCollectionretained(boolean retainFromNewCollection, boolean propertyChanged)Returns theInstanceCollectioncollection containing theInstanceDescriptioninstances that are contained in both the old and the new collections.
-
-
-
Constructor Detail
-
InstancesDiff
public InstancesDiff(@Nonnull TopologyEvent event)Create a newInstancesDiffbased on the instances from the old and newTopologyViewtopology views contained in theTopologyEventevent provided.- Parameters:
event- the nonnullevent from which the old and new topology views are used for computing. If either of the topology views arenull, then they will be substituted by an empty collection of instances.- Throws:
java.lang.IllegalArgumentException- if either of the collections contains duplicated Sling identifiers.
-
InstancesDiff
public InstancesDiff(@Nonnull TopologyView oldView, @Nonnull TopologyView newView)Create a newInstancesDiffbased on the instances from the old and newTopologyViewtopology views provided.- Parameters:
oldView- the nonnullold topology view from which the old collection is used for computing.newView- the nonnullnew topology view form which the new collection is used for computing.- Throws:
java.lang.IllegalArgumentException- if either of the collections contains duplicated Sling identifiers.
-
InstancesDiff
public InstancesDiff(@Nonnull ClusterView oldView, @Nonnull ClusterView newView)Create a newInstancesDiffbased on the instances from the old and newClusterViewcluster views provided.- Parameters:
oldView- the nonnullold cluster view used for computing.newView- the nonnullnew cluster view used for computing.- Throws:
java.lang.IllegalArgumentException- if either of the collections contains duplicated Sling identifiers.
-
InstancesDiff
public InstancesDiff(@Nonnull java.util.Collection<T> oldInstances, @Nonnull java.util.Collection<T> newInstances)Create a newInstancesDiffbased on the provided old and newCollectioncollections of instances.- Type Parameters:
T- the type of instance which must extendInstanceDescription.- Parameters:
oldInstances- the nonnullold collection of instances used for computing.newInstances- the nonnullnew collection of instances used for computing.- Throws:
java.lang.IllegalArgumentException- if either of the collections contains duplicated Sling identifiers.
-
-
Method Detail
-
all
@Nonnull public InstancesDiff.InstanceCollection all(boolean retainFromNewCollection)
Returns theInstanceSetset containing theInstanceDescriptioninstances that are contained in either the old or the new collection.For
InstanceDescriptioninstances contained in both the old and the new collections, the method will retain those from either of the collections depending on the parameter #retainFromNewView.- Parameters:
retainFromNewCollection-truein order to retain the instances from the new collection ;falsein order to retain the instances from the old collection.- Returns:
- the
InstanceCollectioncollection containing theInstanceDescriptioninstances from both collections.
-
added
@Nonnull public InstancesDiff.InstanceCollection added()
Returns theInstanceCollectioncollection containing theInstanceDescriptioninstances that are contained in the new collection but not in the old collection.- Returns:
- the
InstanceCollectioncollection containing the instances in the new topology collection but not in the old collection.
-
removed
@Nonnull public InstancesDiff.InstanceCollection removed()
Returns theInstanceCollectioncollection containing theInstanceDescriptioninstances that are contained in the old collection but not in the new collection.- Returns:
- the
InstanceSetset containing the instances in the old collection but not in the new collection.
-
retained
@Nonnull public InstancesDiff.InstanceCollection retained(boolean retainFromNewCollection)
Returns theInstanceSetcollection containing theInstanceDescriptioninstances that are contained in both the old collection and the new collection.The method will retain the
InstanceDescriptioninstances from either of the collections depending on the parameter #retainFromNewView.- Parameters:
retainFromNewCollection-truein order to retain the instances from the new collection ;falsein order to retain the instances from the old collection.- Returns:
- the
InstanceCollectioncollection containing theInstanceDescriptioninstances contained in both collections.
-
retained
@Nonnull public InstancesDiff.InstanceCollection retained(boolean retainFromNewCollection, boolean propertyChanged)
Returns theInstanceCollectioncollection containing theInstanceDescriptioninstances that are contained in both the old and the new collections.The method will retain the
InstanceDescriptioninstances from either of the collections depending on the parameter #retainFromNewView.- Parameters:
retainFromNewCollection-truein order to retain the instances from the new collection ;falsein order to retain the instances from the old collection.propertyChanged-truein order to keep only the instances which properties have changed between the old and new collections ;falsein order to keep only the instances which properties have not changed.- Returns:
- the
InstanceCollectioncollection containing theInstanceDescriptioninstances contained in both views.
-
-