OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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.content.browser.input; |
| 6 |
| 7 import org.chromium.base.VisibleForTesting; |
| 8 |
| 9 /** |
| 10 * A simple class to set start and end in int type. |
| 11 * TODO(changwan): replace this with android.util.Range when the default SDK |
| 12 * version becomes 21 or higher. |
| 13 */ |
| 14 public class Range { |
| 15 private int mStart; |
| 16 private int mEnd; |
| 17 |
| 18 public Range(int start, int end) { |
| 19 mStart = Math.min(start, end); |
| 20 mEnd = Math.max(start, end); |
| 21 } |
| 22 |
| 23 public int start() { |
| 24 return mStart; |
| 25 } |
| 26 |
| 27 public int end() { |
| 28 return mEnd; |
| 29 } |
| 30 |
| 31 @VisibleForTesting |
| 32 public void set(int start, int end) { |
| 33 mStart = start; |
| 34 mEnd = end; |
| 35 } |
| 36 |
| 37 public void clamp(int start, int end) { |
| 38 if (mStart < start) mStart = start; |
| 39 if (mStart > end) mStart = end; |
| 40 if (mEnd > end) mEnd = end; |
| 41 if (mEnd < start) mEnd = start; |
| 42 } |
| 43 |
| 44 @Override |
| 45 public boolean equals(Object o) { |
| 46 if (!(o instanceof Range)) return false; |
| 47 if (o == this) return true; |
| 48 Range r = (Range) o; |
| 49 return mStart == r.mStart && mEnd == r.mEnd; |
| 50 } |
| 51 |
| 52 @Override |
| 53 public int hashCode() { |
| 54 return 11 * mStart + 31 * mEnd; |
| 55 } |
| 56 |
| 57 @Override |
| 58 public String toString() { |
| 59 return "[ " + mStart + ", " + mEnd + " ]"; |
| 60 } |
| 61 } |
OLD | NEW |