| 1 |
/* ===================================================================== |
| 2 |
* JFreePDF : a fast, light-weight PDF library for the Java(tm) platform |
| 3 |
* ===================================================================== |
| 4 |
* |
| 5 |
* (C)opyright 2013-2022, by David Gilbert. All rights reserved. |
| 6 |
* |
| 7 |
* https://github.com/jfree/orsonpdf |
| 8 |
* |
| 9 |
* This program is free software: you can redistribute it and/or modify |
| 10 |
* it under the terms of the GNU General Public License as published by |
| 11 |
* the Free Software Foundation, either version 3 of the License, or |
| 12 |
* (at your option) any later version. |
| 13 |
* |
| 14 |
* This program is distributed in the hope that it will be useful, |
| 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
* GNU General Public License for more details. |
| 18 |
* |
| 19 |
* You should have received a copy of the GNU General Public License |
| 20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
* |
| 22 |
* [Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
| 23 |
* Other names may be trademarks of their respective owners.] |
| 24 |
* |
| 25 |
* If you do not wish to be bound by the terms of the GPL, an alternative |
| 26 |
* runtime license is available to JFree sponsors: |
| 27 |
* |
| 28 |
* https://github.com/sponsors/jfree |
| 29 |
* |
| 30 |
*/ |
| 31 |
|
| 32 |
package org.jfree.pdf.util; |
| 33 |
|
| 34 |
/** |
| 35 |
* A utility class that performs checks for method argument validity. |
| 36 |
*/ |
| 37 |
public class Args { |
| 38 |
|
| 39 |
private Args() { |
| 40 |
// no need to instantiate this |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Checks that an argument is non-{@code null} and throws an |
| 45 |
* {@code IllegalArgumentException} otherwise. |
| 46 |
* |
| 47 |
* @param obj the object to check for {@code null}. |
| 48 |
* @param ref the text name for the parameter (to include in the exception |
| 49 |
* message). |
| 50 |
*/ |
| 51 |
public static void nullNotPermitted(Object obj, String ref) { |
| 52 |
if (obj == null) { |
| 53 |
throw new IllegalArgumentException("Null '" + ref + "' argument."); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Checks an array to ensure it has the correct length and throws an |
| 59 |
* {@code IllegalArgumentException} if it does not. |
| 60 |
* |
| 61 |
* @param length the required length. |
| 62 |
* @param array the array to check. |
| 63 |
* @param ref the text name of the array parameter (to include in the |
| 64 |
* exception message). |
| 65 |
*/ |
| 66 |
public static void arrayMustHaveLength(int length, boolean[] array, |
| 67 |
String ref) { |
| 68 |
nullNotPermitted(array, "array"); |
| 69 |
if (array.length != length) { |
| 70 |
throw new IllegalArgumentException("Array '" + ref |
| 71 |
+ "' requires length " + length); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Checks an array to ensure it has the correct length and throws an |
| 77 |
* {@code IllegalArgumentException} if it does not. |
| 78 |
* |
| 79 |
* @param length the required length. |
| 80 |
* @param array the array to check. |
| 81 |
* @param ref the text name of the array parameter (to include in the |
| 82 |
* exception message). |
| 83 |
*/ |
| 84 |
public static void arrayMustHaveLength(int length, double[] array, |
| 85 |
String ref) { |
| 86 |
nullNotPermitted(array, "array"); |
| 87 |
if (array.length != length) { |
| 88 |
throw new IllegalArgumentException("Array '" + ref |
| 89 |
+ "' requires length " + length); |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
|