Reduced cyclomatic complexity by using Preconditions 57/957/3
authorTony Tkacik <ttkacik@cisco.com>
Thu, 22 Aug 2013 10:44:52 +0000 (12:44 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Thu, 22 Aug 2013 11:45:24 +0000 (13:45 +0200)
Change-Id: Id267a876829d28f3359c1f2c3209d43ccbaa81bc
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
code-generator/binding-generator-impl/pom.xml
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java
pom.xml

index 5a722efd98ad3d997c57c46520a9f7f2c1d538a8..9a1fc491eede57675e76bdba391c1de415b1cc85 100644 (file)
             <artifactId>commons-lang</artifactId>\r
             <version>2.1</version>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>com.google.guava</groupId>\r
+            <artifactId>guava</artifactId>\r
+        </dependency>\r
     </dependencies>\r
 \r
 </project>\r
index 1760a7e13d254364bd30aafaf14d9bbfde34acce..d8c9b93e6d242254435b515cea58ad73053a93eb 100644 (file)
@@ -71,6 +71,9 @@ import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
 import org.opendaylight.yangtools.yang.model.util.UnionType;
 
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicates;
+
 public final class BindingGeneratorImpl implements BindingGenerator {
 
     /**
@@ -139,13 +142,8 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      */
     @Override
     public List<Type> generateTypes(final SchemaContext context) {
-        if (context == null) {
-            throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
-        }
-        if (context.getModules() == null) {
-            throw new IllegalStateException("Schema Context does not contain defined modules!");
-        }
-
+        Preconditions.checkArgument(context != null,"Schema Context reference cannot be NULL.");
+        Preconditions.checkState(context.getModules() != null,"Schema Context does not contain defined modules.");
         final List<Type> generatedTypes = new ArrayList<>();
         schemaContext = context;
         typeProvider = new TypeProviderImpl(context);
@@ -201,15 +199,9 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      */
     @Override
     public List<Type> generateTypes(final SchemaContext context, final Set<Module> modules) {
-        if (context == null) {
-            throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
-        }
-        if (context.getModules() == null) {
-            throw new IllegalStateException("Schema Context does not contain defined modules!");
-        }
-        if (modules == null) {
-            throw new IllegalArgumentException("Sef of Modules cannot be NULL!");
-        }
+        Preconditions.checkArgument(context != null,"Schema Context reference cannot be NULL.");
+        Preconditions.checkState(context.getModules() != null,"Schema Context does not contain defined modules.");
+        Preconditions.checkArgument(modules != null,"Sef of Modules cannot be NULL.");
 
         final List<Type> filteredGenTypes = new ArrayList<>();
         schemaContext = context;
@@ -256,15 +248,9 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      *
      */
     private List<Type> allTypeDefinitionsToGenTypes(final Module module) {
-        if (module == null) {
-            throw new IllegalArgumentException("Module reference cannot be NULL!");
-        }
-        if (module.getName() == null) {
-            throw new IllegalArgumentException("Module name cannot be NULL!");
-        }
-        if (module.getTypeDefinitions() == null) {
-            throw new IllegalArgumentException("Type Definitions for module " + module.getName() + " cannot be NULL!");
-        }
+        Preconditions.checkArgument(module != null,"Module reference cannot be NULL.");
+        Preconditions.checkArgument(module.getName() != null,"Module name cannot be NULL.");
+        Preconditions.checkArgument(module.getTypeDefinitions() != null,"Type Definitions for module " + module.getName() + " cannot be NULL.");
 
         final Set<TypeDefinition<?>> typeDefinitions = module.getTypeDefinitions();
         final List<Type> generatedTypes = new ArrayList<>();
@@ -297,17 +283,13 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      *
      */
     private List<Type> allContainersToGenTypes(final Module module) {
-        if (module == null) {
-            throw new IllegalArgumentException("Module reference cannot be NULL!");
-        }
+        Preconditions.checkArgument(module != null,"Module reference cannot be NULL.");
 
-        if (module.getName() == null) {
-            throw new IllegalArgumentException("Module name cannot be NULL!");
-        }
+        Preconditions.checkArgument(module.getName() != null,"Module name cannot be NULL.");
 
         if (module.getChildNodes() == null) {
             throw new IllegalArgumentException("Reference to Set of Child Nodes in module " + module.getName()
-                    + " cannot be NULL!");
+                    + " cannot be NULL.");
         }
 
         final List<Type> generatedTypes = new ArrayList<>();
@@ -340,17 +322,13 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      *
      */
     private List<Type> allListsToGenTypes(final Module module) {
-        if (module == null) {
-            throw new IllegalArgumentException("Module reference cannot be NULL!");
-        }
+        Preconditions.checkArgument(module != null,"Module reference cannot be NULL.");
 
-        if (module.getName() == null) {
-            throw new IllegalArgumentException("Module name cannot be NULL!");
-        }
+        Preconditions.checkArgument(module.getName() != null,"Module name cannot be NULL.");
 
         if (module.getChildNodes() == null) {
             throw new IllegalArgumentException("Reference to Set of Child Nodes in module " + module.getName()
-                    + " cannot be NULL!");
+                    + " cannot be NULL.");
         }
 
         final List<Type> generatedTypes = new ArrayList<>();
@@ -384,12 +362,8 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      *
      */
     private List<GeneratedType> allChoicesToGenTypes(final Module module) {
-        if (module == null) {
-            throw new IllegalArgumentException("Module reference cannot be NULL!");
-        }
-        if (module.getName() == null) {
-            throw new IllegalArgumentException("Module name cannot be NULL!");
-        }
+        Preconditions.checkArgument(module != null,"Module reference cannot be NULL.");
+        Preconditions.checkArgument(module.getName() != null,"Module name cannot be NULL.");
 
         final DataNodeIterator it = new DataNodeIterator(module);
         final List<ChoiceNode> choiceNodes = it.allChoices();
@@ -422,15 +396,11 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      *
      */
     private List<Type> allAugmentsToGenTypes(final Module module) {
-        if (module == null) {
-            throw new IllegalArgumentException("Module reference cannot be NULL!");
-        }
-        if (module.getName() == null) {
-            throw new IllegalArgumentException("Module name cannot be NULL!");
-        }
+        Preconditions.checkArgument(module != null,"Module reference cannot be NULL.");
+        Preconditions.checkArgument(module.getName() != null,"Module name cannot be NULL.");
         if (module.getChildNodes() == null) {
             throw new IllegalArgumentException("Reference to Set of Augmentation Definitions in module "
-                    + module.getName() + " cannot be NULL!");
+                    + module.getName() + " cannot be NULL.");
         }
 
         final List<Type> generatedTypes = new ArrayList<>();
@@ -459,12 +429,8 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      *
      */
     private List<AugmentationSchema> resolveAugmentations(final Module module) {
-        if (module == null) {
-            throw new IllegalArgumentException("Module reference cannot be NULL!");
-        }
-        if (module.getAugmentations() == null) {
-            throw new IllegalStateException("Augmentations Set cannot be NULL!");
-        }
+        Preconditions.checkArgument(module != null,"Module reference cannot be NULL.");
+        Preconditions.checkState(module.getAugmentations() != null,"Augmentations Set cannot be NULL.");
 
         final Set<AugmentationSchema> augmentations = module.getAugmentations();
         final List<AugmentationSchema> sortedAugmentations = new ArrayList<>(augmentations);
@@ -501,9 +467,7 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      *
      */
     private GeneratedType moduleToDataType(final Module module) {
-        if (module == null) {
-            throw new IllegalArgumentException("Module reference cannot be NULL!");
-        }
+        Preconditions.checkArgument(module != null,"Module reference cannot be NULL.");
 
         final GeneratedTypeBuilder moduleDataTypeBuilder = moduleTypeBuilder(module, "Data");
         addImplementedInterfaceFromUses(module, moduleDataTypeBuilder);
@@ -536,17 +500,13 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      *
      */
     private List<Type> allRPCMethodsToGenType(final Module module) {
-        if (module == null) {
-            throw new IllegalArgumentException("Module reference cannot be NULL!");
-        }
+        Preconditions.checkArgument(module != null,"Module reference cannot be NULL.");
 
-        if (module.getName() == null) {
-            throw new IllegalArgumentException("Module name cannot be NULL!");
-        }
+        Preconditions.checkArgument(module.getName() != null,"Module name cannot be NULL.");
 
         if (module.getChildNodes() == null) {
             throw new IllegalArgumentException("Reference to Set of RPC Method Definitions in module "
-                    + module.getName() + " cannot be NULL!");
+                    + module.getName() + " cannot be NULL.");
         }
 
         final String basePackageName = moduleNamespaceToPackageName(module);
@@ -640,17 +600,13 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      *
      */
     private List<Type> allNotificationsToGenType(final Module module) {
-        if (module == null) {
-            throw new IllegalArgumentException("Module reference cannot be NULL!");
-        }
+        Preconditions.checkArgument(module != null,"Module reference cannot be NULL.");
 
-        if (module.getName() == null) {
-            throw new IllegalArgumentException("Module name cannot be NULL!");
-        }
+        Preconditions.checkArgument(module.getName() != null,"Module name cannot be NULL.");
 
         if (module.getChildNodes() == null) {
             throw new IllegalArgumentException("Reference to Set of Notification Definitions in module "
-                    + module.getName() + " cannot be NULL!");
+                    + module.getName() + " cannot be NULL.");
         }
 
         final String basePackageName = moduleNamespaceToPackageName(module);
@@ -775,9 +731,7 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      *
      */
     private List<Type> allGroupingsToGenTypes(final Module module) {
-        if (module == null) {
-            throw new IllegalArgumentException("Module parameter can not be null");
-        }
+        Preconditions.checkArgument(module != null,"Module parameter can not be null");
         final List<Type> genTypes = new ArrayList<>();
         final String basePackageName = moduleNamespaceToPackageName(module);
         final Set<GroupingDefinition> groupings = module.getGroupings();
@@ -887,9 +841,7 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      *             if <code>module</code> equals null
      */
     private GeneratedTypeBuilder moduleTypeBuilder(final Module module, final String postfix) {
-        if (module == null) {
-            throw new IllegalArgumentException("Module reference cannot be NULL!");
-        }
+        Preconditions.checkArgument(module != null,"Module reference cannot be NULL.");
         String packageName = moduleNamespaceToPackageName(module);
         final String moduleName = parseToClassName(module.getName()) + postfix;
 
@@ -920,15 +872,9 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      *             </ul>
      */
     private List<Type> augmentationToGenTypes(final String augmentPackageName, final AugmentationSchema augSchema) {
-        if (augmentPackageName == null) {
-            throw new IllegalArgumentException("Package Name cannot be NULL!");
-        }
-        if (augSchema == null) {
-            throw new IllegalArgumentException("Augmentation Schema cannot be NULL!");
-        }
-        if (augSchema.getTargetPath() == null) {
-            throw new IllegalStateException("Augmentation Schema does not contain Target Path (Target Path is NULL).");
-        }
+        Preconditions.checkArgument(augmentPackageName != null,"Package Name cannot be NULL.");
+        Preconditions.checkArgument(augSchema != null,"Augmentation Schema cannot be NULL.");
+        Preconditions.checkState(augSchema.getTargetPath() != null,"Augmentation Schema does not contain Target Path (Target Path is NULL).");
 
         final List<Type> genTypes = new ArrayList<>();
 
@@ -1253,15 +1199,9 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      */
     private void resolveChoiceSchemaNode(final String basePackageName, final GeneratedTypeBuilder typeBuilder,
             final ChoiceNode choiceNode) {
-        if (basePackageName == null) {
-            throw new IllegalArgumentException("Base Package Name cannot be NULL!");
-        }
-        if (typeBuilder == null) {
-            throw new IllegalArgumentException("Generated Type Builder cannot be NULL!");
-        }
-        if (choiceNode == null) {
-            throw new IllegalArgumentException("Choice Schema Node cannot be NULL!");
-        }
+        Preconditions.checkArgument(basePackageName != null,"Base Package Name cannot be NULL.");
+        Preconditions.checkArgument(typeBuilder != null,"Generated Type Builder cannot be NULL.");
+        Preconditions.checkArgument(choiceNode != null,"Choice Schema Node cannot be NULL.");
 
         final String choiceName = choiceNode.getQName().getLocalName();
         if (choiceName != null && !choiceNode.isAddedByUses()) {
@@ -1295,12 +1235,8 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      *
      */
     private List<GeneratedType> choiceToGeneratedType(final String basePackageName, final ChoiceNode choiceNode) {
-        if (basePackageName == null) {
-            throw new IllegalArgumentException("Base Package Name cannot be NULL!");
-        }
-        if (choiceNode == null) {
-            throw new IllegalArgumentException("Choice Schema Node cannot be NULL!");
-        }
+        Preconditions.checkArgument(basePackageName != null,"Base Package Name cannot be NULL.");
+        Preconditions.checkArgument(choiceNode != null,"Choice Schema Node cannot be NULL.");
 
         final List<GeneratedType> generatedTypes = new ArrayList<>();
         final String packageName = packageNameForGeneratedType(basePackageName, choiceNode.getPath());
@@ -1344,15 +1280,9 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      */
     private List<GeneratedType> generateTypesFromChoiceCases(final String basePackageName, final Type refChoiceType,
             final Set<ChoiceCaseNode> caseNodes) {
-        if (basePackageName == null) {
-            throw new IllegalArgumentException("Base Package Name cannot be NULL!");
-        }
-        if (refChoiceType == null) {
-            throw new IllegalArgumentException("Referenced Choice Type cannot be NULL!");
-        }
-        if (caseNodes == null) {
-            throw new IllegalArgumentException("Set of Choice Case Nodes cannot be NULL!");
-        }
+        Preconditions.checkArgument(basePackageName != null,"Base Package Name cannot be NULL.");
+        Preconditions.checkArgument(refChoiceType != null,"Referenced Choice Type cannot be NULL.");
+        Preconditions.checkArgument(caseNodes != null,"Set of Choice Case Nodes cannot be NULL.");
 
         final List<GeneratedType> generatedTypes = new ArrayList<>();
         for (final ChoiceCaseNode caseNode : caseNodes) {
@@ -1399,15 +1329,9 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      */
     private List<GeneratedType> generateTypesFromAugmentedChoiceCases(final String basePackageName,
             final Type refChoiceType, final Set<ChoiceCaseNode> caseNodes) {
-        if (basePackageName == null) {
-            throw new IllegalArgumentException("Base Package Name cannot be NULL!");
-        }
-        if (refChoiceType == null) {
-            throw new IllegalArgumentException("Referenced Choice Type cannot be NULL!");
-        }
-        if (caseNodes == null) {
-            throw new IllegalArgumentException("Set of Choice Case Nodes cannot be NULL!");
-        }
+        Preconditions.checkArgument(basePackageName != null,"Base Package Name cannot be NULL.");
+        Preconditions.checkArgument(refChoiceType != null,"Referenced Choice Type cannot be NULL.");
+        Preconditions.checkArgument(caseNodes != null,"Set of Choice Case Nodes cannot be NULL.");
 
         final List<GeneratedType> generatedTypes = new ArrayList<>();
         for (final ChoiceCaseNode caseNode : caseNodes) {
@@ -1734,19 +1658,11 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      */
     private GeneratedTypeBuilder addRawInterfaceDefinition(final String packageName, final SchemaNode schemaNode,
             final String prefix) {
-        if (schemaNode == null) {
-            throw new IllegalArgumentException("Data Schema Node cannot be NULL!");
-        }
-        if (packageName == null) {
-            throw new IllegalArgumentException("Package Name for Generated Type cannot be NULL!");
-        }
-        if (schemaNode.getQName() == null) {
-            throw new IllegalArgumentException("QName for Data Schema Node cannot be NULL!");
-        }
+        Preconditions.checkArgument(schemaNode != null,"Data Schema Node cannot be NULL.");
+        Preconditions.checkArgument(packageName != null,"Package Name for Generated Type cannot be NULL.");
+        Preconditions.checkArgument(schemaNode.getQName() != null,"QName for Data Schema Node cannot be NULL.");
         final String schemaNodeName = schemaNode.getQName().getLocalName();
-        if (schemaNodeName == null) {
-            throw new IllegalArgumentException("Local Name of QName for Data Schema Node cannot be NULL!");
-        }
+        Preconditions.checkArgument(schemaNodeName != null,"Local Name of QName for Data Schema Node cannot be NULL.");
 
         final String genTypeName;
         if (prefix == null) {
@@ -1865,12 +1781,8 @@ public final class BindingGeneratorImpl implements BindingGenerator {
     }
 
     private List<Type> listToGenType(final String basePackageName, final ListSchemaNode list) {
-        if (basePackageName == null) {
-            throw new IllegalArgumentException("Package Name for Generated Type cannot be NULL!");
-        }
-        if (list == null) {
-            throw new IllegalArgumentException("List Schema Node cannot be NULL!");
-        }
+        Preconditions.checkArgument(basePackageName != null,"Package Name for Generated Type cannot be NULL.");
+        Preconditions.checkArgument(list != null,"List Schema Node cannot be NULL.");
 
         final String packageName = packageNameForGeneratedType(basePackageName, list.getPath());
         // final GeneratedTypeBuilder typeBuilder =
@@ -1923,13 +1835,9 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      */
     private void addSchemaNodeToListBuilders(final String basePackageName, final DataSchemaNode schemaNode,
             final GeneratedTypeBuilder typeBuilder, final GeneratedTOBuilder genTOBuilder, final List<String> listKeys) {
-        if (schemaNode == null) {
-            throw new IllegalArgumentException("Data Schema Node cannot be NULL!");
-        }
+        Preconditions.checkArgument(schemaNode != null,"Data Schema Node cannot be NULL.");
 
-        if (typeBuilder == null) {
-            throw new IllegalArgumentException("Generated Type Builder cannot be NULL!");
-        }
+        Preconditions.checkArgument(typeBuilder != null,"Generated Type Builder cannot be NULL.");
 
         if (schemaNode instanceof LeafSchemaNode) {
             final LeafSchemaNode leaf = (LeafSchemaNode) schemaNode;
@@ -1950,9 +1858,7 @@ public final class BindingGeneratorImpl implements BindingGenerator {
 
     private List<Type> typeBuildersToGenTypes(final GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder) {
         final List<Type> genTypes = new ArrayList<>();
-        if (typeBuilder == null) {
-            throw new IllegalArgumentException("Generated Type Builder cannot be NULL!");
-        }
+        Preconditions.checkArgument(typeBuilder != null,"Generated Type Builder cannot be NULL.");
 
         if (genTOBuilder != null) {
             final GeneratedTransferObject genTO = genTOBuilder.toInstance();
index 01862296fa8bbaab40f295fd3f3766512e951a5d..7edc86a0e68850dce68bae9e405fe91adf11516a 100644 (file)
@@ -55,6 +55,8 @@ import org.opendaylight.yangtools.yang.model.util.StringType;
 import org.opendaylight.yangtools.yang.model.util.UnionType;
 import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort;
 
+import com.google.common.base.Preconditions;
+
 public final class TypeProviderImpl implements TypeProvider {
     /**
      * Contains the schema data red from YANG files.
@@ -82,9 +84,7 @@ public final class TypeProviderImpl implements TypeProvider {
      *             if <code>schemaContext</code> equal null.
      */
     public TypeProviderImpl(final SchemaContext schemaContext) {
-        if (schemaContext == null) {
-            throw new IllegalArgumentException("Schema Context cannot be null!");
-        }
+        Preconditions.checkArgument(schemaContext != null,"Schema Context cannot be null!");
 
         this.schemaContext = schemaContext;
         this.genTypeDefsContextMap = new HashMap<>();
@@ -107,13 +107,9 @@ public final class TypeProviderImpl implements TypeProvider {
      * 
      */
     public void putReferencedType(final SchemaPath refTypePath, final Type refType) {
-        if (refTypePath == null) {
-            throw new IllegalArgumentException("Path reference of " + "Enumeration Type Definition cannot be NULL!");
-        }
+        Preconditions.checkArgument(refTypePath != null,"Path reference of Enumeration Type Definition cannot be NULL!");
 
-        if (refType == null) {
-            throw new IllegalArgumentException("Reference to Enumeration " + "Type cannot be NULL!");
-        }
+        Preconditions.checkArgument(refType != null,"Reference to Enumeration Type cannot be NULL!");
         referencedTypes.put(refTypePath, refType);
     }
 
@@ -148,16 +144,12 @@ public final class TypeProviderImpl implements TypeProvider {
     @Override
     public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> typeDefinition) {
         Type returnType = null;
-        if (typeDefinition == null) {
-            throw new IllegalArgumentException("Type Definition cannot be NULL!");
-        }
+        Preconditions.checkArgument(typeDefinition != null,"Type Definition cannot be NULL!");
         if (typeDefinition.getQName() == null) {
             throw new IllegalArgumentException(
                     "Type Definition cannot have non specified QName (QName cannot be NULL!)");
         }
-        if (typeDefinition.getQName().getLocalName() == null) {
-            throw new IllegalArgumentException("Type Definitions Local Name cannot be NULL!");
-        }
+        Preconditions.checkArgument(typeDefinition.getQName().getLocalName() != null,"Type Definitions Local Name cannot be NULL!");
 
         if (typeDefinition instanceof ExtendedType) {
             returnType = javaTypeForExtendedType(typeDefinition);
@@ -255,9 +247,7 @@ public final class TypeProviderImpl implements TypeProvider {
                 identity = id;
             }
         }
-        if (identity == null) {
-            throw new IllegalArgumentException("Target identity '" + baseIdQName + "' do not exists");
-        }
+        Preconditions.checkArgument(identity != null,"Target identity '" + baseIdQName + "' do not exists");
 
         final String basePackageName = moduleNamespaceToPackageName(module);
         final String packageName = packageNameForGeneratedType(basePackageName, identity.getPath());
@@ -285,16 +275,12 @@ public final class TypeProviderImpl implements TypeProvider {
      */
     public Type generatedTypeForExtendedDefinitionType(final TypeDefinition<?> typeDefinition) {
         Type returnType = null;
-        if (typeDefinition == null) {
-            throw new IllegalArgumentException("Type Definition cannot be NULL!");
-        }
+        Preconditions.checkArgument(typeDefinition != null,"Type Definition cannot be NULL!");
         if (typeDefinition.getQName() == null) {
             throw new IllegalArgumentException(
                     "Type Definition cannot have non specified QName (QName cannot be NULL!)");
         }
-        if (typeDefinition.getQName().getLocalName() == null) {
-            throw new IllegalArgumentException("Type Definitions Local Name cannot be NULL!");
-        }
+        Preconditions.checkArgument(typeDefinition.getQName().getLocalName() != null,"Type Definitions Local Name cannot be NULL!");
 
         final String typedefName = typeDefinition.getQName().getLocalName();
         if (typeDefinition instanceof ExtendedType) {
@@ -325,9 +311,7 @@ public final class TypeProviderImpl implements TypeProvider {
      *             if <code>extendTypeDef</code> equal null
      */
     private TypeDefinition<?> baseTypeDefForExtendedType(final TypeDefinition<?> extendTypeDef) {
-        if (extendTypeDef == null) {
-            throw new IllegalArgumentException("Type Definiition reference cannot be NULL!");
-        }
+        Preconditions.checkArgument(extendTypeDef != null,"Type Definiition reference cannot be NULL!");
         final TypeDefinition<?> baseTypeDef = extendTypeDef.getBaseType();
         if (baseTypeDef instanceof ExtendedType) {
             return baseTypeDefForExtendedType(baseTypeDef);
@@ -356,13 +340,9 @@ public final class TypeProviderImpl implements TypeProvider {
      */
     public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType) {
         Type returnType = null;
-        if (leafrefType == null) {
-            throw new IllegalArgumentException("Leafref Type Definition reference cannot be NULL!");
-        }
+        Preconditions.checkArgument(leafrefType != null,"Leafref Type Definition reference cannot be NULL!");
 
-        if (leafrefType.getPathStatement() == null) {
-            throw new IllegalArgumentException("The Path Statement for Leafref Type Definition cannot be NULL!");
-        }
+        Preconditions.checkArgument(leafrefType.getPathStatement() != null,"The Path Statement for Leafref Type Definition cannot be NULL!");
 
         final RevisionAwareXPath xpath = leafrefType.getPathStatement();
         final String strXPath = xpath.toString();
@@ -460,18 +440,10 @@ public final class TypeProviderImpl implements TypeProvider {
      *             </ul>
      */
     private Enumeration provideTypeForEnum(final EnumTypeDefinition enumTypeDef, final String enumName) {
-        if (enumTypeDef == null) {
-            throw new IllegalArgumentException("EnumTypeDefinition reference cannot be NULL!");
-        }
-        if (enumTypeDef.getValues() == null) {
-            throw new IllegalArgumentException("EnumTypeDefinition MUST contain at least ONE value definition!");
-        }
-        if (enumTypeDef.getQName() == null) {
-            throw new IllegalArgumentException("EnumTypeDefinition MUST contain NON-NULL QName!");
-        }
-        if (enumTypeDef.getQName().getLocalName() == null) {
-            throw new IllegalArgumentException("Local Name in EnumTypeDefinition QName cannot be NULL!");
-        }
+        Preconditions.checkArgument(enumTypeDef != null,"EnumTypeDefinition reference cannot be NULL!");
+        Preconditions.checkArgument(enumTypeDef.getValues() != null,"EnumTypeDefinition MUST contain at least ONE value definition!");
+        Preconditions.checkArgument(enumTypeDef.getQName() != null,"EnumTypeDefinition MUST contain NON-NULL QName!");
+        Preconditions.checkArgument(enumTypeDef.getQName().getLocalName() != null,"Local Name in EnumTypeDefinition QName cannot be NULL!");
 
         final String enumerationName = parseToClassName(enumName);
 
@@ -508,21 +480,11 @@ public final class TypeProviderImpl implements TypeProvider {
      */
     private Enumeration addInnerEnumerationToTypeBuilder(final EnumTypeDefinition enumTypeDef, final String enumName,
             final GeneratedTypeBuilder typeBuilder) {
-        if (enumTypeDef == null) {
-            throw new IllegalArgumentException("EnumTypeDefinition reference cannot be NULL!");
-        }
-        if (enumTypeDef.getValues() == null) {
-            throw new IllegalArgumentException("EnumTypeDefinition MUST contain at least ONE value definition!");
-        }
-        if (enumTypeDef.getQName() == null) {
-            throw new IllegalArgumentException("EnumTypeDefinition MUST contain NON-NULL QName!");
-        }
-        if (enumTypeDef.getQName().getLocalName() == null) {
-            throw new IllegalArgumentException("Local Name in EnumTypeDefinition QName cannot be NULL!");
-        }
-        if (typeBuilder == null) {
-            throw new IllegalArgumentException("Generated Type Builder reference cannot be NULL!");
-        }
+        Preconditions.checkArgument(enumTypeDef != null,"EnumTypeDefinition reference cannot be NULL!");
+        Preconditions.checkArgument(enumTypeDef.getValues() != null,"EnumTypeDefinition MUST contain at least ONE value definition!");
+        Preconditions.checkArgument(enumTypeDef.getQName() != null,"EnumTypeDefinition MUST contain NON-NULL QName!");
+        Preconditions.checkArgument(enumTypeDef.getQName().getLocalName() != null,"Local Name in EnumTypeDefinition QName cannot be NULL!");
+        Preconditions.checkArgument(typeBuilder != null,"Generated Type Builder reference cannot be NULL!");
 
         final String enumerationName = parseToClassName(enumName);
 
@@ -568,9 +530,7 @@ public final class TypeProviderImpl implements TypeProvider {
      */
     private void resolveTypeDefsFromContext() {
         final Set<Module> modules = schemaContext.getModules();
-        if (modules == null) {
-            throw new IllegalArgumentException("Sef of Modules cannot be NULL!");
-        }
+        Preconditions.checkArgument(modules != null,"Sef of Modules cannot be NULL!");
         final Module[] modulesArray = new Module[modules.size()];
         int i = 0;
         for (Module modul : modules) {
@@ -743,12 +703,8 @@ public final class TypeProviderImpl implements TypeProvider {
      */
     public List<GeneratedTOBuilder> provideGeneratedTOBuildersForUnionTypeDef(final String basePackageName,
             final TypeDefinition<?> typedef, final String typeDefName) {
-        if (basePackageName == null) {
-            throw new IllegalArgumentException("Base Package Name cannot be NULL!");
-        }
-        if (typedef == null) {
-            throw new IllegalArgumentException("Type Definition cannot be NULL!");
-        }
+        Preconditions.checkArgument(basePackageName != null,"Base Package Name cannot be NULL!");
+        Preconditions.checkArgument(typedef != null,"Type Definition cannot be NULL!");
         if (typedef.getQName() == null) {
             throw new IllegalArgumentException(
                     "Type Definition cannot have non specified QName (QName cannot be NULL!)");
@@ -993,12 +949,8 @@ public final class TypeProviderImpl implements TypeProvider {
     public GeneratedTOBuilder provideGeneratedTOBuilderForBitsTypeDefinition(final String basePackageName,
             final TypeDefinition<?> typeDef, String typeDefName) {
 
-        if (typeDef == null) {
-            throw new IllegalArgumentException("typeDef cannot be NULL!");
-        }
-        if (basePackageName == null) {
-            throw new IllegalArgumentException("Base Package Name cannot be NULL!");
-        }
+        Preconditions.checkArgument(typeDef != null,"typeDef cannot be NULL!");
+        Preconditions.checkArgument(basePackageName != null,"Base Package Name cannot be NULL!");
 
         if (typeDef instanceof BitsTypeDefinition) {
             BitsTypeDefinition bitsTypeDefinition = (BitsTypeDefinition) typeDef;
@@ -1037,9 +989,7 @@ public final class TypeProviderImpl implements TypeProvider {
      */
     private List<String> resolveRegExpressionsFromTypedef(ExtendedType typedef) {
         final List<String> regExps = new ArrayList<String>();
-        if (typedef == null) {
-            throw new IllegalArgumentException("typedef can't be null");
-        }
+        Preconditions.checkArgument(typedef != null,"typedef can't be null");
         final TypeDefinition<?> strTypeDef = baseTypeDefForExtendedType(typedef);
         if (strTypeDef instanceof StringType) {
             final List<PatternConstraint> patternConstraints = typedef.getPatterns();
@@ -1112,15 +1062,9 @@ public final class TypeProviderImpl implements TypeProvider {
     private GeneratedTransferObject provideGeneratedTOFromExtendedType(final ExtendedType innerExtendedType,
             final String basePackageName, final String typedefName) {
 
-        if (innerExtendedType == null) {
-            throw new IllegalArgumentException("Extended type cannot be NULL!");
-        }
-        if (basePackageName == null) {
-            throw new IllegalArgumentException("String with base package name cannot be NULL!");
-        }
-        if (typedefName == null) {
-            throw new IllegalArgumentException("String with type definition name cannot be NULL!");
-        }
+        Preconditions.checkArgument(innerExtendedType != null,"Extended type cannot be NULL!");
+        Preconditions.checkArgument(basePackageName != null,"String with base package name cannot be NULL!");
+        Preconditions.checkArgument(typedefName != null,"String with type definition name cannot be NULL!");
 
         final String classTypedefName = parseToClassName(typedefName);
         final String innerTypeDef = innerExtendedType.getQName().getLocalName();
@@ -1190,9 +1134,7 @@ public final class TypeProviderImpl implements TypeProvider {
      *         definition to the base type
      */
     private int getTypeDefinitionDepth(final TypeDefinition<?> typeDefinition) {
-        if (typeDefinition == null) {
-            throw new IllegalArgumentException("Type definition can't be null");
-        }
+        Preconditions.checkArgument(typeDefinition != null,"Type definition can't be null");
         int depth = 1;
         TypeDefinition<?> baseType = typeDefinition.getBaseType();
 
diff --git a/pom.xml b/pom.xml
index bc25c94539949bb5a8721a3370597e06a877cf83..2d4d5fd37b5f4960e029516546b05a361578bd98 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                 <artifactId>slf4j-api</artifactId>\r
                 <version>1.7.2</version>\r
             </dependency>\r
+            <dependency>\r
+                <groupId>com.google.guava</groupId>\r
+                <artifactId>guava</artifactId>\r
+                <version>14.0.1</version>\r
+            </dependency>\r
         </dependencies>\r
     </dependencyManagement>\r
 \r