+ def String toQuote(Object obj) {
+ return "\"" + obj.toString + "\"";
+ }
+
+ /**
+ * Template method which generates method parameters with their types from <code>parameters</code>.
+ *
+ * @param parameters
+ * list of parameter instances which are transformed to the method parameters
+ * @return string with the list of the method parameters with their types in JAVA format
+ */
+ def protected generateParameters(List<MethodSignature.Parameter> parameters) '''«
+ IF !parameters.empty»«
+ FOR parameter : parameters SEPARATOR ", "»«
+ parameter.type.importedName» «parameter.name»«
+ ENDFOR»«
+ ENDIF
+ »'''
+
+ def protected generateLengthMethod(String methodName, Type type, String className, String varName) '''
+ «val Restrictions restrictions = type.restrictions»
+ «IF restrictions != null && !(restrictions.lengthConstraints.empty)»
+ «val numberClass = restrictions.lengthConstraints.iterator.next.min.class»
+ public static «List.importedName»<«Range.importedName»<«numberClass.importedNumber»>> «methodName»() {
+ «IF numberClass.equals(typeof(BigDecimal))»
+ «lengthBody(restrictions, numberClass, className, varName)»
+ «ELSE»
+ «lengthBody(restrictions, typeof(BigInteger), className, varName)»
+ «ENDIF»
+ }
+ «ENDIF»
+ '''
+
+ def private lengthBody(Restrictions restrictions, Class<? extends Number> numberClass, String className, String varName) '''
+ if («varName» == null) {
+ synchronized («className».class) {
+ if («varName» == null) {
+ «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();
+ }
+ }
+ }
+ return «varName»;
+ '''
+
+ def protected generateRangeMethod(String methodName, Restrictions restrictions, Type returnType, String className, String varName) '''
+ «IF restrictions != null && !(restrictions.rangeConstraints.empty)»
+ «val number = returnType.importedNumber»
+ public static «List.importedName»<«Range.importedName»<«number»>> «methodName»() {
+ «IF returnType.fullyQualifiedName.equals(BigDecimal.canonicalName)»
+ «rangeBody(restrictions, BigDecimal, className, varName)»
+ «ELSE»
+ «rangeBody(restrictions, BigInteger, className, varName)»
+ «ENDIF»
+ }
+ «ENDIF»
+ '''
+
+ def protected generateRangeMethod(String methodName, Restrictions restrictions, String className, String varName, Iterable<GeneratedProperty> properties) '''
+ «IF restrictions != null && !(restrictions.rangeConstraints.empty)»
+ «val returnType = properties.iterator.next.returnType»
+ public static «List.importedName»<«Range.importedName»<«returnType.importedNumber»>> «methodName»() {
+ «IF returnType.fullyQualifiedName.equals(BigDecimal.canonicalName)»
+ «rangeBody(restrictions, BigDecimal, className, varName)»
+ «ELSE»
+ «rangeBody(restrictions, BigInteger, className, varName)»
+ «ENDIF»
+ }
+ «ENDIF»
+ '''
+
+ def private rangeBody(Restrictions restrictions, Class<? extends Number> numberClass, String className, String varName) '''
+ if («varName» == null) {
+ synchronized («className».class) {
+ if («varName» == null) {
+ «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();
+ }
+ }
+ }
+ return «varName»;
+ '''
+
+ def protected String importedNumber(Class<? extends Number> clazz) {
+ if (clazz.equals(typeof(BigDecimal))) {
+ return BigDecimal.importedName
+ }
+ return BigInteger.importedName
+ }
+
+ def protected String importedNumber(Type clazz) {
+ if (clazz.fullyQualifiedName.equals(BigDecimal.canonicalName)) {
+ return BigDecimal.importedName