Package org.kiwiproject.registry.client
Class ServiceInstanceFilter
java.lang.Object
org.kiwiproject.registry.client.ServiceInstanceFilter
Utility class that provides version filtering of lists of
ServiceInstance
objects.
NOTE: For all List
of ServiceInstance
being passed into the utility methods, the assumption is that
all instances are for the same service name.
-
Method Summary
Modifier and TypeMethodDescriptionstatic List<ServiceInstance>
filterInstancesByVersion
(List<ServiceInstance> serviceInstances, RegistryClient.InstanceQuery query) Filter the given service instances using thequery
, by minimum and/or preferred versions if specified.static List<ServiceInstance>
findInstancesWithLatestVersion
(List<ServiceInstance> serviceInstances) Finds the latest version in the given list of service instances, then returns a new list containing only instances having that latest version.static boolean
versionIsAtLeast
(ServiceInstance instance, String version) Is the version of theServiceInstance
the same or higher thanversion
?static boolean
versionIsExactly
(ServiceInstance instance, String version) Is the version of theServiceInstance
the same asversion
?
-
Method Details
-
filterInstancesByVersion
public static List<ServiceInstance> filterInstancesByVersion(List<ServiceInstance> serviceInstances, RegistryClient.InstanceQuery query) Filter the given service instances using thequery
, by minimum and/or preferred versions if specified.- Parameters:
serviceInstances
- list of service instances to filterquery
- service instance query object- Returns:
- an immutable list containing instances meeting the version criteria
-
versionIsAtLeast
Is the version of theServiceInstance
the same or higher thanversion
?- Parameters:
instance
- the service instance to checkversion
- the version to compare- Returns:
- true if the
instance
version is equal to or greater than the givenversion
, else false - Implementation Note:
- Compares versions using Kiwi's
Versions.isHigherOrSameVersion(String, String)
-
versionIsExactly
Is the version of theServiceInstance
the same asversion
?- Parameters:
instance
- the service instance to checkversion
- the version to compare- Returns:
- true if the
instance
version is equal to the givenversion
, else false - Implementation Note:
- Compares versions using Kiwi's
Versions.isSameVersion(String, String)
-
findInstancesWithLatestVersion
public static List<ServiceInstance> findInstancesWithLatestVersion(List<ServiceInstance> serviceInstances) Finds the latest version in the given list of service instances, then returns a new list containing only instances having that latest version.- Parameters:
serviceInstances
- list of service instances to filter- Returns:
- a list containing service instances having the latest version seen in
serviceInstances
- Implementation Note:
- Compares versions using Kiwi's
Versions.versionCompare(String, String)
-