|
| 1 | +/* |
| 2 | + * DISCLAIMER |
| 3 | + * |
| 4 | + * Copyright 2016 ArangoDB GmbH, Cologne, Germany |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + * |
| 18 | + * Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | + */ |
| 20 | + |
| 21 | + |
| 22 | +package com.arangodb.util; |
| 23 | + |
| 24 | + |
| 25 | +/** |
| 26 | + * @author Michele Rastelli |
| 27 | + */ |
| 28 | +public final class TestUtils { |
| 29 | + |
| 30 | + private TestUtils() { |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Parses {@param version} and checks whether it is greater or equal to |
| 35 | + * <{@param otherMajor}, {@param otherMinor}, {@param otherPatch}> |
| 36 | + * comparing the corresponding version components in lexicographical order. |
| 37 | + * |
| 38 | + * @param version |
| 39 | + * @param otherMajor |
| 40 | + * @param otherMinor |
| 41 | + * @param otherPatch |
| 42 | + */ |
| 43 | + public static boolean isAtLeastVersion(final String version, final int otherMajor, final int otherMinor, final int otherPatch) { |
| 44 | + String[] parts = version.split("-")[0].split("\\."); |
| 45 | + |
| 46 | + int major = Integer.parseInt(parts[0]); |
| 47 | + int minor = Integer.parseInt(parts[1]); |
| 48 | + int patch = Integer.parseInt(parts[2]); |
| 49 | + |
| 50 | + int majorComparison = Integer.compare(major, otherMajor); |
| 51 | + if (majorComparison != 0) { |
| 52 | + return majorComparison > 0; |
| 53 | + } |
| 54 | + |
| 55 | + int minorComparison = Integer.compare(minor, otherMinor); |
| 56 | + if (minorComparison != 0) { |
| 57 | + return minorComparison > 0; |
| 58 | + } |
| 59 | + |
| 60 | + int patchComparison = Integer.compare(patch, otherPatch); |
| 61 | + if (patchComparison != 0) { |
| 62 | + return patchComparison > 0; |
| 63 | + } |
| 64 | + |
| 65 | + return true; |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments