From 97f1c854993a65b2c700426a1e3a83b23ea65337 Mon Sep 17 00:00:00 2001 From: Yin-Chia Yeh Date: Wed, 28 May 2014 16:36:05 -0700 Subject: Camera2: update the range of metering weight Limit the range of metering weight to 0-1000. Bug: 15315352 Change-Id: Iceb13b72508cb3c9f758bdcb1b69b6b11ec5aaf8 --- .../com/android/internal/util/Preconditions.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'core/java/com') diff --git a/core/java/com/android/internal/util/Preconditions.java b/core/java/com/android/internal/util/Preconditions.java index f6722a6..c0d1e88 100644 --- a/core/java/com/android/internal/util/Preconditions.java +++ b/core/java/com/android/internal/util/Preconditions.java @@ -183,6 +183,33 @@ public class Preconditions { } /** + * Ensures that the argument int value is within the inclusive range. + * + * @param value a int value + * @param lower the lower endpoint of the inclusive range + * @param upper the upper endpoint of the inclusive range + * @param valueName the name of the argument to use if the check fails + * + * @return the validated int value + * + * @throws IllegalArgumentException if {@code value} was not within the range + */ + public static int checkArgumentInRange(int value, int lower, int upper, + String valueName) { + if (value < lower) { + throw new IllegalArgumentException( + String.format( + "%s is out of range of [%d, %d] (too low)", valueName, lower, upper)); + } else if (value > upper) { + throw new IllegalArgumentException( + String.format( + "%s is out of range of [%d, %d] (too high)", valueName, lower, upper)); + } + + return value; + } + + /** * Ensures that the array is not {@code null}, and none if its elements are {@code null}. * * @param value an array of boxed objects -- cgit v1.1