Utility method for getting the first version prior to given version

This commit is contained in:
Jason Tedor 2015-08-21 09:09:43 -04:00
parent 38085cf90a
commit f0aae96f11
1 changed files with 8 additions and 2 deletions

View File

@ -64,10 +64,16 @@ public class VersionUtils {
public static List<Version> allVersions() { public static List<Version> allVersions() {
return Collections.unmodifiableList(SORTED_VERSIONS); return Collections.unmodifiableList(SORTED_VERSIONS);
} }
public static Version getPreviousVersion(Version version) {
int index = SORTED_VERSIONS.indexOf(version);
assert index > 0;
return SORTED_VERSIONS.get(index - 1);
}
/** Returns the {@link Version} before the {@link Version#CURRENT} */ /** Returns the {@link Version} before the {@link Version#CURRENT} */
public static Version getPreviousVersion() { public static Version getPreviousVersion() {
Version version = SORTED_VERSIONS.get(SORTED_VERSIONS.size() - 2); Version version = getPreviousVersion(Version.CURRENT);
assert version.before(Version.CURRENT); assert version.before(Version.CURRENT);
return version; return version;
} }