Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/omaha/VersionNumber.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.omaha;
6
7 import java.util.Locale;
8
9 /**
10 * Utility for dealing with Chrome version numbers.
11 */
12 public class VersionNumber {
13 private final int[] mVersion = {0, 0, 0, 0};
14
15 /**
16 * Parses out the version numbers from a given version string.
17 * @param str a version number of the format a.b.c.d, where each is an integ er.
18 * @return A VersionNumber containing the version info, or null if it couldn 't be parsed.
19 */
20 public static VersionNumber fromString(String str) {
21 if (str == null) {
22 return null;
23 }
24
25 // Parse out the version numbers.
26 String[] pieces = str.split("\\.");
27 if (pieces.length != 4) {
28 return null;
29 }
30
31 VersionNumber version = new VersionNumber();
32 try {
33 for (int i = 0; i < 4; ++i) {
34 version.mVersion[i] = Integer.parseInt(pieces[i]);
35 }
36 } catch (NumberFormatException e) {
37 return null;
38 }
39
40 return version;
41 }
42
43 @Override
44 public String toString() {
45 return String.format(Locale.US, "%d.%d.%d.%d", mVersion[0], mVersion[1], mVersion[2],
46 mVersion[3]);
47 }
48
49 /**
50 * @return whether this VersionNumber is smaller than the given one, going f rom left to right.
51 */
52 public boolean isSmallerThan(VersionNumber version) {
53 for (int i = 0; i < 4; ++i) {
54 if (mVersion[i] < version.mVersion[i]) {
55 return true;
56 } else if (mVersion[i] > version.mVersion[i]) {
57 return false;
58 }
59 }
60 return false;
61 }
62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698