summaryrefslogtreecommitdiffstats
path: root/core/java/android/util/Range.java
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2014-06-07 00:35:36 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-06-07 00:35:36 +0000
commit2f98a26bbf24fdc40ef53a653bb152c7f5a5d0dd (patch)
tree4222bc88e7e9c5314fa5cd9454cd62cba1ed60c9 /core/java/android/util/Range.java
parente6a4613cf3cfbcca14736cd97b9f8ba7bc01d1f0 (diff)
parent007bfb14d2d720cdd699cfbb36ce206246901cef (diff)
downloadframeworks_base-2f98a26bbf24fdc40ef53a653bb152c7f5a5d0dd.zip
frameworks_base-2f98a26bbf24fdc40ef53a653bb152c7f5a5d0dd.tar.gz
frameworks_base-2f98a26bbf24fdc40ef53a653bb152c7f5a5d0dd.tar.bz2
Merge "util: Make Rational a Number/Comparable; add Range#inRange" into lmp-preview-dev
Diffstat (limited to 'core/java/android/util/Range.java')
-rw-r--r--core/java/android/util/Range.java30
1 files changed, 24 insertions, 6 deletions
diff --git a/core/java/android/util/Range.java b/core/java/android/util/Range.java
index d7e8cf0..3907e77 100644
--- a/core/java/android/util/Range.java
+++ b/core/java/android/util/Range.java
@@ -97,6 +97,27 @@ public final class Range<T extends Comparable<? super T>> {
}
/**
+ * Checks if the {@code value} is within the bounds of this range.
+ *
+ * <p>A value is considered to be within this range if it's {@code >=} then
+ * the lower endpoint <i>and</i> {@code <=} to the upper endpoint (using the {@link Comparable}
+ * interface.</p>
+ *
+ * @param value a non-{@code null} {@code T} reference
+ * @return {@code true} if the value is within this inclusive range, {@code false} otherwise
+ *
+ * @throws NullPointerException if {@code value} was {@code null}
+ */
+ public boolean inRange(T value) {
+ checkNotNull(value, "value must not be null");
+
+ boolean gteLower = value.compareTo(mLower) >= 0;
+ boolean lteUpper = value.compareTo(mUpper) <= 0;
+
+ return gteLower && lteUpper;
+ }
+
+ /**
* Compare two ranges for equality.
*
* <p>A range is considered equal if and only if both the lower and upper endpoints
@@ -105,16 +126,13 @@ public final class Range<T extends Comparable<? super T>> {
* @return {@code true} if the ranges are equal, {@code false} otherwise
*/
@Override
- public boolean equals(final Object obj) {
+ public boolean equals(Object obj) {
if (obj == null) {
return false;
- }
- if (this == obj) {
+ } else if (this == obj) {
return true;
- }
- if (obj instanceof Range) {
+ } else if (obj instanceof Range) {
@SuppressWarnings("rawtypes")
- final
Range other = (Range) obj;
return mLower.equals(other.mLower) && mUpper.equals(other.mUpper);
}