1 15 package org.apache.hivemind.util; 16 17 import org.apache.hivemind.HiveMindMessages; 18 19 25 public final class Defense 26 { 27 private Defense() 28 { 29 } 31 32 38 public static void notNull(Object parameter, String parameterName) 39 { 40 if (parameter == null) 41 throw new NullPointerException (HiveMindMessages.paramNotNull(parameterName)); 42 } 43 44 50 public static void fieldNotNull(Object value, String fieldName) 51 { 52 if (value == null) 53 throw new NullPointerException (HiveMindMessages.fieldNotNull(fieldName)); 54 } 55 56 62 63 public static void isAssignable(Object parameter, Class expectedType, String parameterName) 64 { 65 Defense.notNull(parameter, parameterName); 66 67 if (!expectedType.isAssignableFrom(parameter.getClass())) 68 throw new ClassCastException (HiveMindMessages.paramWrongType( 69 parameterName, 70 parameter, 71 expectedType)); 72 } 73 } | Popular Tags |