Index: content/public/android/java/src/org/chromium/content/browser/input/Range.java |
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/Range.java b/content/public/android/java/src/org/chromium/content/browser/input/Range.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0a8cc4b4d0e6dc6e8bd60b378776332fff2e97de |
--- /dev/null |
+++ b/content/public/android/java/src/org/chromium/content/browser/input/Range.java |
@@ -0,0 +1,61 @@ |
+// Copyright 2016 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.content.browser.input; |
+ |
+import org.chromium.base.VisibleForTesting; |
+ |
+/** |
+ * A simple class to set start and end in int type. |
+ * TODO(changwan): replace this with android.util.Range when the default SDK |
+ * version becomes 21 or higher. |
+ */ |
+public class Range { |
+ private int mStart; |
+ private int mEnd; |
+ |
+ public Range(int start, int end) { |
+ mStart = Math.min(start, end); |
+ mEnd = Math.max(start, end); |
+ } |
+ |
+ public int start() { |
+ return mStart; |
+ } |
+ |
+ public int end() { |
+ return mEnd; |
+ } |
+ |
+ @VisibleForTesting |
+ public void set(int start, int end) { |
+ mStart = start; |
+ mEnd = end; |
+ } |
+ |
+ public void clamp(int start, int end) { |
+ if (mStart < start) mStart = start; |
+ if (mStart > end) mStart = end; |
+ if (mEnd > end) mEnd = end; |
+ if (mEnd < start) mEnd = start; |
+ } |
+ |
+ @Override |
+ public boolean equals(Object o) { |
+ if (!(o instanceof Range)) return false; |
+ if (o == this) return true; |
+ Range r = (Range) o; |
+ return mStart == r.mStart && mEnd == r.mEnd; |
+ } |
+ |
+ @Override |
+ public int hashCode() { |
+ return 11 * mStart + 31 * mEnd; |
+ } |
+ |
+ @Override |
+ public String toString() { |
+ return "[ " + mStart + ", " + mEnd + " ]"; |
+ } |
+} |