«generateToString(genTO.toStringIdentifiers)»
- «generateGetLength»
+ «generateLengthMethod("length", genTO, genTO.importedName, "_length")»
- «generateGetRange»
+ «generateRangeMethod("range", genTO.restrictions, genTO.importedName, "_range", allProperties)»
}
'''
«parentConstructor»
«ENDIF»
'''
-
+
def protected allValuesConstructor() '''
«IF genTO.typedef && !allProperties.empty && allProperties.size == 1 && allProperties.get(0).name.equals("value")»
@«ConstructorProperties.importedName»("value")
* @return string with the class attributes in JAVA format
*/
def protected generateFields() '''
+ «IF restrictions != null»
+ «val prop = getPropByName("value")»
+ «IF prop != null»
+ «IF !(restrictions.lengthConstraints.empty)»
+ private static «List.importedName»<«Range.importedName»<«prop.returnType.importedNumber»>> _length;
+ «ENDIF»
+ «IF !(restrictions.rangeConstraints.empty)»
+ private static «List.importedName»<«Range.importedName»<«prop.returnType.importedNumber»>> _range;
+ «ENDIF»
+ «ENDIF»
+ «ENDIF»
«IF !properties.empty»
«FOR f : properties»
«IF f.readOnly»final«ENDIF» private «f.returnType.importedName» «f.fieldName»;
«ENDIF»
'''
-
/**
* Template method which generates the method <code>hashCode()</code>.
*
«ENDIF»
'''
- def private generateGetLength() '''
- «IF restrictions != null && !(restrictions.lengthConstraints.empty)»
- «val clazz = restrictions.lengthConstraints.iterator.next.min.class»
- public static «List.importedName»<«Range.importedName»<«clazz.importedName»>> length() {
- final «List.importedName»<«Range.importedName»<«clazz.importedName»>> result = new «ArrayList.importedName»<>();
- «FOR r : restrictions.lengthConstraints»
- result.add(«Range.importedName».closed(new «clazz.importedName»("«r.min»"), new «clazz.importedName»("«r.max»")));
- «ENDFOR»
- return result;
+ def GeneratedProperty getPropByName(String name) {
+ for (GeneratedProperty prop : allProperties) {
+ if (prop.name.equals(name)) {
+ return prop;
}
- «ENDIF»
- '''
-
- def private generateGetRange() '''
- «IF restrictions != null && !(restrictions.rangeConstraints.empty)»
- «val clazz = restrictions.rangeConstraints.iterator.next.min.class»
- public static «List.importedName»<«Range.importedName»<«clazz.importedName»>> range() {
- final «List.importedName»<«Range.importedName»<«clazz.importedName»>> result = new «ArrayList.importedName»<>();
- «FOR r : restrictions.rangeConstraints»
- result.add(«Range.importedName».closed(new «clazz.importedName»("«r.min»"), new «clazz.importedName»("«r.max»")));
- «ENDFOR»
- return result;
- }
- «ENDIF»
- '''
+ }
+ return null;
+ }
}