diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-04-23 13:17:28 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-04-23 13:17:28 +0200 |
commit | f898d2c0851ca4a1d5aebcc347a71c801f4c0459 (patch) | |
tree | b48726f265d9c96f0b9a7493eeb384394a43d199 /vespajlib/src | |
parent | ad25b2bc2a4331da9f27fc5c6142ad01fc11401d (diff) |
Ensure that sameElement never accepts a WordAlternativesItem.
Diffstat (limited to 'vespajlib/src')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/protect/Validator.java | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/protect/Validator.java b/vespajlib/src/main/java/com/yahoo/protect/Validator.java index 49fe7716ba2..ee4a93c2f01 100644 --- a/vespajlib/src/main/java/com/yahoo/protect/Validator.java +++ b/vespajlib/src/main/java/com/yahoo/protect/Validator.java @@ -68,14 +68,10 @@ public abstract class Validator { * Throws an IllegalArgumentException if the first argument is not strictly * smaller than the second argument * - * @param smallDescription - * description of the smallest argument - * @param small - * the smallest argument - * @param largeDescription - * description of the largest argument - * @param large - * the largest argument + * @param smallDescription description of the smallest argument + * @param small the smallest argument + * @param largeDescription description of the largest argument + * @param large the largest argument */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static void ensureSmaller(String smallDescription, Comparable small, String largeDescription, Comparable large) { @@ -115,14 +111,10 @@ public abstract class Validator { /** * Ensures that an item is of a particular class * - * @param description - * a description of the item to be checked - * @param item - * the item to check the type of - * @param type - * the type the given item should be instanceof - * @throws IllegalArgumentException - * if the given item is not of the correct type + * @param description a description of the item to be checked + * @param item the item to check the type of + * @param type the type the given item should be instanceof + * @throws IllegalArgumentException if the given item is not of the correct type */ public static void ensureInstanceOf(String description, Object item, Class<?> type) { if ( ! type.isAssignableFrom(item.getClass())) { @@ -131,4 +123,19 @@ public abstract class Validator { } } + /** + * Ensures that an item is not of a particular class + * + * @param description a description of the item to be checked + * @param item the item to check the type of + * @param type the type the given item should NOT be instanceof + * @throws IllegalArgumentException if the given item is of the wrong type + */ + public static void ensureNotInstanceOf(String description, Object item, Class<?> type) { + if ( type.isAssignableFrom(item.getClass())) { + throw new IllegalArgumentException(description + " " + item + " should NOT be an instance of " + type + + " but is " + item.getClass()); + } + } + } |