+
+ def private generateConstraints() '''
+ static {
+ «IF !restrictions.rangeConstraints.nullOrEmpty»
+ «generateRangeConstraints»
+ «ENDIF»
+ «IF !restrictions.lengthConstraints.nullOrEmpty»
+ «generateLengthConstraints»
+ «ENDIF»
+ }
+ '''
+
+ private def generateRangeConstraints() '''
+ «IF !allProperties.nullOrEmpty»
+ «val returnType = allProperties.iterator.next.returnType»
+ «IF returnType.fullyQualifiedName.equals(BigDecimal.canonicalName)»
+ «rangeBody(restrictions, BigDecimal, genTO.importedName, "_range")»
+ «ELSE»
+ «rangeBody(restrictions, BigInteger, genTO.importedName, "_range")»
+ «ENDIF»
+ «ENDIF»
+ '''
+
+ private def rangeBody(Restrictions restrictions, Class<? extends Number> numberClass, String className, String varName) '''
+ «ImmutableList.importedName».Builder<«Range.importedName»<«numberClass.importedName»>> builder = «ImmutableList.importedName».builder();
+ «FOR r : restrictions.rangeConstraints»
+ builder.add(«Range.importedName».closed(«numericValue(numberClass, r.min)», «numericValue(numberClass, r.max)»));
+ «ENDFOR»
+ «varName» = builder.build();
+ '''
+
+ private def lengthBody(Restrictions restrictions, Class<? extends Number> numberClass, String className, String varName) '''
+ «ImmutableList.importedName».Builder<«Range.importedName»<«numberClass.importedName»>> builder = «ImmutableList.importedName».builder();
+ «FOR r : restrictions.lengthConstraints»
+ builder.add(«Range.importedName».closed(«numericValue(numberClass, r.min)», «numericValue(numberClass, r.max)»));
+ «ENDFOR»
+ «varName» = builder.build();
+ '''
+
+ private def generateLengthConstraints() '''
+ «IF restrictions != null && !(restrictions.lengthConstraints.empty)»
+ «val numberClass = restrictions.lengthConstraints.iterator.next.min.class»
+ «IF numberClass.equals(typeof(BigDecimal))»
+ «lengthBody(restrictions, numberClass, genTO.importedName, "_length")»
+ «ELSE»
+ «lengthBody(restrictions, typeof(BigInteger), genTO.importedName, "_length")»
+ «ENDIF»
+ «ENDIF»
+ '''
+