Refactored checkCounterNumber to checkRange for argument range checks.

This commit renames checkCounterNumber to a more generic name,
checkRange, to reflect its updated functionality. It now supports
checking the provided argument against a range of values instead of just
specific counter numbers.

Bug: 293811969
Test: TH
Change-Id: I203afb71b68e892fd024f7935cc18ca5ae43f156
diff --git a/src/android/net/apf/ApfGenerator.java b/src/android/net/apf/ApfGenerator.java
index 0c4007b..31581dd 100644
--- a/src/android/net/apf/ApfGenerator.java
+++ b/src/android/net/apf/ApfGenerator.java
@@ -16,6 +16,8 @@
 
 package android.net.apf;
 
+import androidx.annotation.NonNull;
+
 import com.android.internal.annotations.VisibleForTesting;
 
 import java.util.ArrayList;
@@ -898,7 +900,8 @@
      */
     public ApfGenerator addCountAndPass(int counterNumber) throws IllegalInstructionException {
         requireApfVersion(MIN_APF_VERSION_IN_DEV);
-        checkCounterNumber(counterNumber);
+        checkRange("CounterNumber", counterNumber /* value */, 1 /* lowerBound */,
+                1000 /* upperBound */);
         Instruction instruction = new Instruction(Opcodes.PASS, Register.R0);
         instruction.addUnsignedImm(counterNumber);
         addInstruction(instruction);
@@ -921,7 +924,8 @@
      */
     public ApfGenerator addCountAndDrop(int counterNumber) throws IllegalInstructionException {
         requireApfVersion(MIN_APF_VERSION_IN_DEV);
-        checkCounterNumber(counterNumber);
+        checkRange("CounterNumber", counterNumber /* value */, 1 /* lowerBound */,
+                1000 /* upperBound */);
         Instruction instruction = new Instruction(Opcodes.DROP, Register.R1);
         instruction.addUnsignedImm(counterNumber);
         addInstruction(instruction);
@@ -1129,11 +1133,14 @@
         }
     }
 
-    private void checkCounterNumber(int counterNumber) {
-        if (counterNumber < 1 || counterNumber > 1000) {
-            throw new IllegalArgumentException(
-                    "Counter number must be in range (0, 1000], counterNumber: " + counterNumber);
+    private void checkRange(@NonNull String variableName, int value, int lowerBound,
+            int upperBound) {
+        if (value >= lowerBound && value <= upperBound) {
+            return;
         }
+        throw new IllegalArgumentException(
+                String.format("%s: %d, must be in range [%d, %d]", variableName, value, lowerBound,
+                        upperBound));
     }
 
     /**