Class ServiceInstanceFilter

java.lang.Object
org.kiwiproject.registry.client.ServiceInstanceFilter

public final class ServiceInstanceFilter extends Object
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 Details

    • filterInstancesByVersion

      public static List<ServiceInstance> filterInstancesByVersion(List<ServiceInstance> serviceInstances, RegistryClient.InstanceQuery query)
      Filter the given service instances using the query, by minimum and/or preferred versions if specified.
      Parameters:
      serviceInstances - list of service instances to filter
      query - service instance query object
      Returns:
      an immutable list containing instances meeting the version criteria
    • versionIsAtLeast

      public static boolean versionIsAtLeast(ServiceInstance instance, String version)
      Is the version of the ServiceInstance the same or higher than version?
      Parameters:
      instance - the service instance to check
      version - the version to compare
      Returns:
      true if the instance version is equal to or greater than the given version, else false
      Implementation Note:
      Compares versions using Kiwi's Versions.isHigherOrSameVersion(String, String)
    • versionIsExactly

      public static boolean versionIsExactly(ServiceInstance instance, String version)
      Is the version of the ServiceInstance the same as version?
      Parameters:
      instance - the service instance to check
      version - the version to compare
      Returns:
      true if the instance version is equal to the given version, 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)