Class InstancesDiff
- java.lang.Object
-
- org.apache.sling.discovery.commons.InstancesDiff
-
public final class InstancesDiff extends java.lang.Object
TheInstancesDiff
allows to combine and filter two collections ofInstanceDescription
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 anIllegalArgumentException
.- Since:
- 1.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
InstancesDiff.InstanceCollection
TheInstanceCollection
collection allows to filter the instances using a set of custom filter either implementingInstanceFilter
or pre-defined ones.
-
Constructor Summary
Constructors Constructor Description InstancesDiff(java.util.Collection<T> oldInstances, java.util.Collection<T> newInstances)
Create a newInstancesDiff
based on the provided old and newCollection
collections of instances.InstancesDiff(ClusterView oldView, ClusterView newView)
Create a newInstancesDiff
based on the instances from the old and newClusterView
cluster views provided.InstancesDiff(TopologyEvent event)
Create a newInstancesDiff
based on the instances from the old and newTopologyView
topology views contained in theTopologyEvent
event provided.InstancesDiff(TopologyView oldView, TopologyView newView)
Create a newInstancesDiff
based on the instances from the old and newTopologyView
topology views provided.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InstancesDiff.InstanceCollection
added()
Returns theInstanceCollection
collection containing theInstanceDescription
instances that are contained in the new collection but not in the old collection.InstancesDiff.InstanceCollection
all(boolean retainFromNewCollection)
Returns theInstanceSet
set containing theInstanceDescription
instances that are contained in either the old or the new collection.InstancesDiff.InstanceCollection
removed()
Returns theInstanceCollection
collection containing theInstanceDescription
instances that are contained in the old collection but not in the new collection.InstancesDiff.InstanceCollection
retained(boolean retainFromNewCollection)
Returns theInstanceSet
collection containing theInstanceDescription
instances that are contained in both the old collection and the new collection.InstancesDiff.InstanceCollection
retained(boolean retainFromNewCollection, boolean propertyChanged)
Returns theInstanceCollection
collection containing theInstanceDescription
instances that are contained in both the old and the new collections.
-
-
-
Constructor Detail
-
InstancesDiff
public InstancesDiff(@Nonnull TopologyEvent event)
Create a newInstancesDiff
based on the instances from the old and newTopologyView
topology views contained in theTopologyEvent
event provided.- Parameters:
event
- the nonnull
event 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 newInstancesDiff
based on the instances from the old and newTopologyView
topology views provided.- Parameters:
oldView
- the nonnull
old topology view from which the old collection is used for computing.newView
- the nonnull
new 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 newInstancesDiff
based on the instances from the old and newClusterView
cluster views provided.- Parameters:
oldView
- the nonnull
old cluster view used for computing.newView
- the nonnull
new 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 newInstancesDiff
based on the provided old and newCollection
collections of instances.- Type Parameters:
T
- the type of instance which must extendInstanceDescription
.- Parameters:
oldInstances
- the nonnull
old collection of instances used for computing.newInstances
- the nonnull
new 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 theInstanceSet
set containing theInstanceDescription
instances that are contained in either the old or the new collection.For
InstanceDescription
instances 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
-true
in order to retain the instances from the new collection ;false
in order to retain the instances from the old collection.- Returns:
- the
InstanceCollection
collection containing theInstanceDescription
instances from both collections.
-
added
@Nonnull public InstancesDiff.InstanceCollection added()
Returns theInstanceCollection
collection containing theInstanceDescription
instances that are contained in the new collection but not in the old collection.- Returns:
- the
InstanceCollection
collection containing the instances in the new topology collection but not in the old collection.
-
removed
@Nonnull public InstancesDiff.InstanceCollection removed()
Returns theInstanceCollection
collection containing theInstanceDescription
instances that are contained in the old collection but not in the new collection.- Returns:
- the
InstanceSet
set containing the instances in the old collection but not in the new collection.
-
retained
@Nonnull public InstancesDiff.InstanceCollection retained(boolean retainFromNewCollection)
Returns theInstanceSet
collection containing theInstanceDescription
instances that are contained in both the old collection and the new collection.The method will retain the
InstanceDescription
instances from either of the collections depending on the parameter #retainFromNewView.- Parameters:
retainFromNewCollection
-true
in order to retain the instances from the new collection ;false
in order to retain the instances from the old collection.- Returns:
- the
InstanceCollection
collection containing theInstanceDescription
instances contained in both collections.
-
retained
@Nonnull public InstancesDiff.InstanceCollection retained(boolean retainFromNewCollection, boolean propertyChanged)
Returns theInstanceCollection
collection containing theInstanceDescription
instances that are contained in both the old and the new collections.The method will retain the
InstanceDescription
instances from either of the collections depending on the parameter #retainFromNewView.- Parameters:
retainFromNewCollection
-true
in order to retain the instances from the new collection ;false
in order to retain the instances from the old collection.propertyChanged
-true
in order to keep only the instances which properties have changed between the old and new collections ;false
in order to keep only the instances which properties have not changed.- Returns:
- the
InstanceCollection
collection containing theInstanceDescription
instances contained in both views.
-
-