blob: 9c5e9704070777f61915de21a33be5a881c438e3 [file] [log] [blame]
lishuai2ddc4692015-07-31 15:15:16 +08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.ovsdb.rfc.utils;
17
18/**
19 * Version utility class.
20 */
21public final class VersionUtil {
22
23 /**
24 * Constructs a VersionUtil object. Utility classes should not have a public
25 * or default constructor, otherwise IDE will compile unsuccessfully. This
26 * class should not be instantiated.
27 */
28 private VersionUtil() {
29 }
30
31 public static final String DEFAULT_VERSION_STRING = "0.0.0";
32 private static final String FORMAT = "(\\d+)\\.(\\d+)\\.(\\d+)";
33
34 /**
35 * Match version by the format.
36 * @param version the version String
37 * @throws IllegalArgumentException this is an illegal argument exception
38 */
39 public static void versionMatch(String version) {
40 if (!version.matches(FORMAT)) {
41 throw new IllegalArgumentException("<" + version
42 + "> does not match format " + FORMAT);
43 }
44 }
45
46 /**
47 * Compare fromVersion and toVersion.
48 * @param fromVersion the initial version
49 * @param toVersion the end of the version
50 * @return a long number
51 */
52 public static long versionCompare(String fromVersion, String toVersion) {
53 Long fromNum = Long.parseLong(fromVersion.replace(".", ""));
54 Long toNum = Long.parseLong(toVersion.replace(".", ""));
55 return (fromNum - toNum);
56 }
57}