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