Class InstancesDiff
InstancesDiff allows to combine and filter two collections of InstanceDescription instances,
an "old" collection and a "new" collection.
The comparison between InstanceDescription instances 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 InstancesDiff with collections containing duplicated Sling id
will throw an IllegalArgumentException.
- Since:
- 1.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classTheInstanceCollectioncollection allows to filter the instances using a set of custom filter either implementingInstanceFilteror pre-defined ones. -
Constructor Summary
ConstructorsConstructorDescriptionInstancesDiff(@NotNull Collection<T> oldInstances, @NotNull Collection<T> newInstances) Create a newInstancesDiffbased on the provided old and newCollectioncollections of instances.InstancesDiff(@NotNull ClusterView oldView, @NotNull ClusterView newView) Create a newInstancesDiffbased on the instances from the old and newClusterViewcluster views provided.InstancesDiff(@NotNull TopologyEvent event) Create a newInstancesDiffbased on the instances from the old and newTopologyViewtopology views contained in theTopologyEventevent provided.InstancesDiff(@NotNull TopologyView oldView, @NotNull TopologyView newView) Create a newInstancesDiffbased on the instances from the old and newTopologyViewtopology views provided. -
Method Summary
Modifier and TypeMethodDescription@NotNull InstancesDiff.InstanceCollectionadded()Returns theInstanceCollectioncollection containing theInstanceDescriptioninstances that are contained in the new collection but not in the old collection.@NotNull InstancesDiff.InstanceCollectionall(boolean retainFromNewCollection) Returns theInstanceSetset containing theInstanceDescriptioninstances that are contained in either the old or the new collection.@NotNull InstancesDiff.InstanceCollectionremoved()Returns theInstanceCollectioncollection containing theInstanceDescriptioninstances that are contained in the old collection but not in the new collection.@NotNull InstancesDiff.InstanceCollectionretained(boolean retainFromNewCollection) Returns theInstanceSetcollection containing theInstanceDescriptioninstances that are contained in both the old collection and the new collection.@NotNull InstancesDiff.InstanceCollectionretained(boolean retainFromNewCollection, boolean propertyChanged) Returns theInstanceCollectioncollection containing theInstanceDescriptioninstances that are contained in both the old and the new collections.
-
Constructor Details
-
InstancesDiff
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:
IllegalArgumentException- if either of the collections contains duplicated Sling identifiers.
-
InstancesDiff
public InstancesDiff(@NotNull @NotNull TopologyView oldView, @NotNull @NotNull 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:
IllegalArgumentException- if either of the collections contains duplicated Sling identifiers.
-
InstancesDiff
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:
IllegalArgumentException- if either of the collections contains duplicated Sling identifiers.
-
InstancesDiff
public InstancesDiff(@NotNull @NotNull Collection<T> oldInstances, @NotNull @NotNull 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:
IllegalArgumentException- if either of the collections contains duplicated Sling identifiers.
-
-
Method Details
-
all
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
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
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
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
@NotNull public @NotNull 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.
-