summaryrefslogtreecommitdiff
path: root/src/android/net/util/NetworkStackUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/net/util/NetworkStackUtils.java')
-rwxr-xr-xsrc/android/net/util/NetworkStackUtils.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/android/net/util/NetworkStackUtils.java b/src/android/net/util/NetworkStackUtils.java
index 99563ee..19ca4b5 100755
--- a/src/android/net/util/NetworkStackUtils.java
+++ b/src/android/net/util/NetworkStackUtils.java
@@ -436,4 +436,22 @@ public class NetworkStackUtils {
return addr instanceof Inet6Address
&& ((addr.getAddress()[0] & 0xfe) == 0xfc);
}
+
+ /**
+ * Returns the {@code int} nearest in value to {@code value}.
+ *
+ * @param value any {@code long} value
+ * @return the same value cast to {@code int} if it is in the range of the {@code int}
+ * type, {@link Integer#MAX_VALUE} if it is too large, or {@link Integer#MIN_VALUE} if
+ * it is too small
+ */
+ public static int saturatedCast(long value) {
+ if (value > Integer.MAX_VALUE) {
+ return Integer.MAX_VALUE;
+ }
+ if (value < Integer.MIN_VALUE) {
+ return Integer.MIN_VALUE;
+ }
+ return (int) value;
+ }
}