/** * Sets the service protocol version that will be used for requests associated * with this service. * * @param v new service protocol version. */ public void setProtocolVersion(Version v) { // Ensure that any set version is appropriate for this service type, based // upon the default type that was computed at construction time. if (!protocolVersion.getServiceClass().equals(v.getServiceClass())) { throw new IllegalArgumentException("Invalid service class, " + "was: " + v.getServiceClass() + ", expected: " + protocolVersion.getServiceClass()); } protocolVersion = v; }
/** * Sets the service protocol version that will be used for requests associated * with this service. * * @param v new service protocol version. */ public void setProtocolVersion(Version v) { // Ensure that any set version is appropriate for this service type, based // upon the default type that was computed at construction time. if (!protocolVersion.getServiceClass().equals(v.getServiceClass())) { throw new IllegalArgumentException("Invalid service class, " + "was: " + v.getServiceClass() + ", expected: " + protocolVersion.getServiceClass()); } protocolVersion = v; }
/** * Sets the service protocol version that will be used for requests associated * with this service. * * @param v new service protocol version. */ public void setProtocolVersion(Version v) { // Ensure that any set version is appropriate for this service type, based // upon the default type that was computed at construction time. if (!protocolVersion.getServiceClass().equals(v.getServiceClass())) { throw new IllegalArgumentException("Invalid service class, " + "was: " + v.getServiceClass() + ", expected: " + protocolVersion.getServiceClass()); } protocolVersion = v; }
/** * Finds a matching version for {@code serviceClass} in a list of versions, * or returns {@code null} otherwise. * @param versionList the list of versions to search. * @param serviceClass the service class to match. * @return the matching version or {@code null}. */ public static Version findServiceVersion( Collection<? extends Version> versionList, Class<? extends Service> serviceClass) { for (Version v : versionList) { if (v.getServiceClass().equals(serviceClass)) { return v; } } return null; }
/** * Finds a matching version for {@code serviceClass} in a list of versions, * or returns {@code null} otherwise. * @param versionList the list of versions to search. * @param serviceClass the service class to match. * @return the matching version or {@code null}. */ public static Version findServiceVersion( Collection<? extends Version> versionList, Class<? extends Service> serviceClass) { for (Version v : versionList) { if (v.getServiceClass().equals(serviceClass)) { return v; } } return null; }
/** * Finds a matching version for {@code serviceClass} in a list of versions, * or returns {@code null} otherwise. * @param versionList the list of versions to search. * @param serviceClass the service class to match. * @return the matching version or {@code null}. */ public static Version findServiceVersion( Collection<? extends Version> versionList, Class<? extends Service> serviceClass) { for (Version v : versionList) { if (v.getServiceClass().equals(serviceClass)) { return v; } } return null; }
/** * Takes a list of {@link Version} instances and merges it into another * list. A version in the source list will overwrite any value for the * same service (if any) in the target list. * @param target the target list of versions to merge into. * @param source the source list of versions that will be merged. */ @VisibleForTesting static void mergeVersions(List<Version> target, List<Version> source) { // Check for conflicts with target list before making any changes, // accumulating the list of changed versions. for (Version checkVersion : source) { Version currentVersion = Version.findServiceVersion(target, checkVersion.getServiceClass()); if (currentVersion != null) { target.remove(currentVersion); } } // Add all of the new versions. target.addAll(source); }
/** * Takes a list of {@link Version} instances and merges it into another * list. A version in the source list will overwrite any value for the * same service (if any) in the target list. * @param target the target list of versions to merge into. * @param source the source list of versions that will be merged. */ @VisibleForTesting static void mergeVersions(List<Version> target, List<Version> source) { // Check for conflicts with target list before making any changes, // accumulating the list of changed versions. for (Version checkVersion : source) { Version currentVersion = Version.findServiceVersion(target, checkVersion.getServiceClass()); if (currentVersion != null) { target.remove(currentVersion); } } // Add all of the new versions. target.addAll(source); }
/** * Takes a list of {@link Version} instances and merges it into another * list. A version in the source list will overwrite any value for the * same service (if any) in the target list. * @param target the target list of versions to merge into. * @param source the source list of versions that will be merged. */ @VisibleForTesting static void mergeVersions(List<Version> target, List<Version> source) { // Check for conflicts with target list before making any changes, // accumulating the list of changed versions. for (Version checkVersion : source) { Version currentVersion = Version.findServiceVersion(target, checkVersion.getServiceClass()); if (currentVersion != null) { target.remove(currentVersion); } } // Add all of the new versions. target.addAll(source); }
/** * Returns a version that matches the input service type and major version but * {@link #ANY} minor version. * * @param v input version type * @return equivalent version with any minor version */ public static Version anyMinorVersionOf(Version v) { return new Version(v.getServiceClass(), v.getMajor(), Version.ANY); }
/** * Returns a version that matches the input service type and major version but * {@link #ANY} minor version. * * @param v input version type * @return equivalent version with any minor version */ public static Version anyMinorVersionOf(Version v) { return new Version(v.getServiceClass(), v.getMajor(), Version.ANY); }
/** * Returns a version that matches the input service type and major version but * {@link #ANY} minor version. * * @param v input version type * @return equivalent version with any minor version */ public static Version anyMinorVersionOf(Version v) { return new Version(v.getServiceClass(), v.getMajor(), Version.ANY); }
/** * Returns {@code true} if this version is a earlier version than the * argument, on the basis of comparing the major and minor versions. For the * purposes of comparison, a value of {@link #ANY} is considered to be * {@link Integer#MIN_VALUE}, so no finite version number may come before it. * * @param v version to compare against * @return {@code true} if this version is later than the argument * @throws IllegalArgumentException if the provided version is not for the * same service as this version or for one implied by this version. */ public final boolean isBefore(Version v) { Version serviceVersion = findServiceVersion(impliedVersions, v.getServiceClass()); Preconditions.checkArgument(serviceVersion != null, "No relationship between versions"); // No need to normalize the value of ANY here, since it's value (-1) // is already less than all concrete versions if (serviceVersion.major != v.major) { return serviceVersion.major < v.major; } else { return serviceVersion.minor < v.minor; } }
/** * Returns {@code true} if this version is a earlier version than the * argument, on the basis of comparing the major and minor versions. For the * purposes of comparison, a value of {@link #ANY} is considered to be * {@link Integer#MIN_VALUE}, so no finite version number may come before it. * * @param v version to compare against * @return {@code true} if this version is later than the argument * @throws IllegalArgumentException if the provided version is not for the * same service as this version or for one implied by this version. */ public final boolean isBefore(Version v) { Version serviceVersion = findServiceVersion(impliedVersions, v.getServiceClass()); Preconditions.checkArgument(serviceVersion != null, "No relationship between versions"); // No need to normalize the value of ANY here, since it's value (-1) // is already less than all concrete versions if (serviceVersion.major != v.major) { return serviceVersion.major < v.major; } else { return serviceVersion.minor < v.minor; } }
/** * Returns {@code true} if this version is a earlier version than the * argument, on the basis of comparing the major and minor versions. For the * purposes of comparison, a value of {@link #ANY} is considered to be * {@link Integer#MIN_VALUE}, so no finite version number may come before it. * * @param v version to compare against * @return {@code true} if this version is later than the argument * @throws IllegalArgumentException if the provided version is not for the * same service as this version or for one implied by this version. */ public final boolean isBefore(Version v) { Version serviceVersion = findServiceVersion(impliedVersions, v.getServiceClass()); Preconditions.checkArgument(serviceVersion != null, "No relationship between versions"); // No need to normalize the value of ANY here, since it's value (-1) // is already less than all concrete versions if (serviceVersion.major != v.major) { return serviceVersion.major < v.major; } else { return serviceVersion.minor < v.minor; } }
/** * Compares two versions, where either may be null. */ static int compareVersion(Version a, Version b) { if (a == b) { return 0; } if (a == null) { return -1; } if (b == null) { return 1; } int compare = MetadataKey.compareClass( a.getServiceClass(), b.getServiceClass()); if (compare != 0) { return compare; } int aMajor = a.getMajor(); int bMajor = b.getMajor(); if (aMajor != bMajor) { return aMajor < bMajor ? -1 : 1; } int aMinor = a.getMinor(); int bMinor = b.getMinor(); return aMinor < bMinor ? -1 : (aMinor == bMinor ? 0 : 1); }
/** * Compares two versions, where either may be null. */ static int compareVersion(Version a, Version b) { if (a == b) { return 0; } if (a == null) { return -1; } if (b == null) { return 1; } int compare = MetadataKey.compareClass( a.getServiceClass(), b.getServiceClass()); if (compare != 0) { return compare; } int aMajor = a.getMajor(); int bMajor = b.getMajor(); if (aMajor != bMajor) { return aMajor < bMajor ? -1 : 1; } int aMinor = a.getMinor(); int bMinor = b.getMinor(); return aMinor < bMinor ? -1 : (aMinor == bMinor ? 0 : 1); }
/** * Returns {@code true} if this version is a later version than the argument, * on the basis of comparing the major and minor versions. For the purposes of * comparison, a value of {@link #ANY} is considered to be * {@link Integer#MAX_VALUE}, so no finite version number may come after it. * * @param v version to compare against * @return {@code true} if this version is later than the argument * @throws IllegalArgumentException if the provided version is not for the * same service as this version or for one implied by this version. */ public final boolean isAfter(Version v) { Version serviceVersion = findServiceVersion(impliedVersions, v.getServiceClass()); Preconditions.checkArgument(serviceVersion != null, "No relationship between versions"); int serviceMajor = raiseAny(serviceVersion.major); int vMajor = raiseAny(v.major); if (serviceMajor != vMajor) { return serviceMajor > vMajor; } else { return raiseAny(serviceVersion.minor) > raiseAny(v.minor); } }
/** * Returns {@code true} if this version is a later version than the argument, * on the basis of comparing the major and minor versions. For the purposes of * comparison, a value of {@link #ANY} is considered to be * {@link Integer#MAX_VALUE}, so no finite version number may come after it. * * @param v version to compare against * @return {@code true} if this version is later than the argument * @throws IllegalArgumentException if the provided version is not for the * same service as this version or for one implied by this version. */ public final boolean isAfter(Version v) { Version serviceVersion = findServiceVersion(impliedVersions, v.getServiceClass()); Preconditions.checkArgument(serviceVersion != null, "No relationship between versions"); int serviceMajor = raiseAny(serviceVersion.major); int vMajor = raiseAny(v.major); if (serviceMajor != vMajor) { return serviceMajor > vMajor; } else { return raiseAny(serviceVersion.minor) > raiseAny(v.minor); } }
/** * Returns {@code true} if this version is a later version than the argument, * on the basis of comparing the major and minor versions. For the purposes of * comparison, a value of {@link #ANY} is considered to be * {@link Integer#MAX_VALUE}, so no finite version number may come after it. * * @param v version to compare against * @return {@code true} if this version is later than the argument * @throws IllegalArgumentException if the provided version is not for the * same service as this version or for one implied by this version. */ public final boolean isAfter(Version v) { Version serviceVersion = findServiceVersion(impliedVersions, v.getServiceClass()); Preconditions.checkArgument(serviceVersion != null, "No relationship between versions"); int serviceMajor = raiseAny(serviceVersion.major); int vMajor = raiseAny(v.major); if (serviceMajor != vMajor) { return serviceMajor > vMajor; } else { return raiseAny(serviceVersion.minor) > raiseAny(v.minor); } }