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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java_staging/src/org/chromium/chrome/browser/omaha/VersionNumber.java
diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/omaha/VersionNumber.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/omaha/VersionNumber.java
new file mode 100644
index 0000000000000000000000000000000000000000..10f7e3787ab4d880f40c1a83ae954f8cde14f821
--- /dev/null
+++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/omaha/VersionNumber.java
@@ -0,0 +1,62 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.omaha;
+
+import java.util.Locale;
+
+/**
+ * Utility for dealing with Chrome version numbers.
+ */
+public class VersionNumber {
+ private final int[] mVersion = {0, 0, 0, 0};
+
+ /**
+ * Parses out the version numbers from a given version string.
+ * @param str a version number of the format a.b.c.d, where each is an integer.
+ * @return A VersionNumber containing the version info, or null if it couldn't be parsed.
+ */
+ public static VersionNumber fromString(String str) {
+ if (str == null) {
+ return null;
+ }
+
+ // Parse out the version numbers.
+ String[] pieces = str.split("\\.");
+ if (pieces.length != 4) {
+ return null;
+ }
+
+ VersionNumber version = new VersionNumber();
+ try {
+ for (int i = 0; i < 4; ++i) {
+ version.mVersion[i] = Integer.parseInt(pieces[i]);
+ }
+ } catch (NumberFormatException e) {
+ return null;
+ }
+
+ return version;
+ }
+
+ @Override
+ public String toString() {
+ return String.format(Locale.US, "%d.%d.%d.%d", mVersion[0], mVersion[1], mVersion[2],
+ mVersion[3]);
+ }
+
+ /**
+ * @return whether this VersionNumber is smaller than the given one, going from left to right.
+ */
+ public boolean isSmallerThan(VersionNumber version) {
+ for (int i = 0; i < 4; ++i) {
+ if (mVersion[i] < version.mVersion[i]) {
+ return true;
+ } else if (mVersion[i] > version.mVersion[i]) {
+ return false;
+ }
+ }
+ return false;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698