diff --git a/src/main/java/info/ebenoit/ebul/cmp/DependencyInfo.java b/src/main/java/info/ebenoit/ebul/cmp/DependencyInfo.java index 1521386..c528e6c 100644 --- a/src/main/java/info/ebenoit/ebul/cmp/DependencyInfo.java +++ b/src/main/java/info/ebenoit/ebul/cmp/DependencyInfo.java @@ -13,6 +13,25 @@ import java.util.Objects; public class DependencyInfo { + /** + * Checks that a class can be used as a dependency + * + * @param klass + * the class to check + * @throws ComponentDefinitionException + * if the specified "class" is in fact a primitive or array type + */ + public static void checkClassValidity( final Class< ? > klass ) + throws ComponentDefinitionException + { + if ( klass.isPrimitive( ) ) { + throw new ComponentDefinitionException( "specified dependency is a primitive type" ); + } + if ( klass.isArray( ) ) { + throw new ComponentDefinitionException( "specified dependency is an array type" ); + } + } + /** * The name of the component being depended upon, or null if the dependency information is based on * type. @@ -53,12 +72,7 @@ public class DependencyInfo Objects.requireNonNull( klass ); this.name = null; this.klass = klass; - if ( klass.isPrimitive( ) ) { - throw new ComponentDefinitionException( "specified dependency is a primitive type" ); - } - if ( klass.isArray( ) ) { - throw new ComponentDefinitionException( "specified dependency is an array type" ); - } + DependencyInfo.checkClassValidity( klass ); }