1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.google.android.startop.iorap; 17 18 /** 19 * Convenience short-hand to throw {@link IllegalAccessException} when the arguments 20 * are out-of-range. 21 */ 22 public class CheckHelpers { 23 /** @throws IllegalAccessException if {@param type} is not in {@code [0..maxValue]} */ checkTypeInRange(int type, int maxValue)24 public static void checkTypeInRange(int type, int maxValue) { 25 if (type < 0) { 26 throw new IllegalArgumentException( 27 String.format("type must be non-negative (value=%d)", type)); 28 } 29 if (type > maxValue) { 30 throw new IllegalArgumentException( 31 String.format("type out of range (value=%d, max=%d)", type, maxValue)); 32 } 33 } 34 35 /** @throws IllegalAccessException if {@param state} is not in {@code [0..maxValue]} */ checkStateInRange(int state, int maxValue)36 public static void checkStateInRange(int state, int maxValue) { 37 if (state < 0) { 38 throw new IllegalArgumentException( 39 String.format("state must be non-negative (value=%d)", state)); 40 } 41 if (state > maxValue) { 42 throw new IllegalArgumentException( 43 String.format("state out of range (value=%d, max=%d)", state, maxValue)); 44 } 45 } 46 } 47