package org.opendaylight.mdsal.binding.java.api.generator
import static java.util.Objects.requireNonNull
+import static org.opendaylight.mdsal.binding.model.util.Types.BOOLEAN;
+import static org.opendaylight.mdsal.binding.model.util.Types.BYTE_ARRAY;
+import static org.opendaylight.mdsal.binding.model.util.Types.STRING;
import static extension org.apache.commons.text.StringEscapeUtils.escapeJava
+import com.google.common.base.Preconditions
import com.google.common.collect.ImmutableList
import com.google.common.collect.Lists
import java.beans.ConstructorProperties
import java.util.Collections
import java.util.List
import java.util.Map
-import java.util.Objects
import java.util.regex.Pattern
+import org.gaul.modernizer_maven_annotations.SuppressModernizer
import org.opendaylight.mdsal.binding.model.api.ConcreteType
import org.opendaylight.mdsal.binding.model.api.Constant
import org.opendaylight.mdsal.binding.model.api.Enumeration
import org.opendaylight.mdsal.binding.model.api.Type
import org.opendaylight.mdsal.binding.model.util.TypeConstants
import org.opendaylight.yangtools.yang.binding.CodeHelpers
+import org.opendaylight.yangtools.yang.common.Empty
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition
/**
* Template for generating JAVA class.
*/
+@SuppressModernizer
class ClassTemplate extends BaseTemplate {
protected val List<GeneratedProperty> properties
* consequence of how this code is structured.
*/
IF genTO.typedef && !allProperties.empty && allProperties.size == 1 && allProperties.get(0).name.equals("value")»
- «Objects.importedName».requireNonNull(_value, "Supplied value may not be null");
+ «CodeHelpers.importedName».requireValue(_value);
«genPatternEnforcer("_value")»
«ENDIF»
«val prop = allProperties.get(0)»
«IF !("org.opendaylight.yangtools.yang.binding.InstanceIdentifier".equals(prop.returnType.fullyQualifiedName))»
public static «genTO.name» getDefaultInstance(String defaultValue) {
- «IF "byte[]".equals(prop.returnType.name)»
+ «IF BYTE_ARRAY.equals(prop.returnType)»
return new «genTO.name»(«Base64.importedName».getDecoder().decode(defaultValue));
- «ELSEIF "java.lang.String".equals(prop.returnType.fullyQualifiedName)»
+ «ELSEIF STRING.equals(prop.returnType)»
return new «genTO.name»(defaultValue);
+ «ELSEIF Constants.EMPTY.equals(prop.returnType)»
+ «Preconditions.importedName».checkArgument(defaultValue.isEmpty(), "Invalid value %s", defaultValue);
+ return new «genTO.name»(«Empty.importedName».getInstance());
«ELSEIF allProperties.size > 1»
«bitsArgs»
- «ELSEIF "java.lang.Boolean".equals(prop.returnType.fullyQualifiedName)»
+ «ELSEIF BOOLEAN.equals(prop.returnType)»
return new «genTO.name»(«Boolean.importedName».valueOf(defaultValue));
«ELSEIF "java.lang.Byte".equals(prop.returnType.fullyQualifiedName)»
return new «genTO.name»(«Byte.importedName».valueOf(defaultValue));
*
* @return string with the <code>equals()</code> method definition in JAVA format
*/
- def protected generateEquals() '''
+ def private generateEquals() '''
«IF !genTO.equalsIdentifiers.empty»
@«Override.importedName»
- public boolean equals(java.lang.Object obj) {
+ public final boolean equals(java.lang.Object obj) {
if (this == obj) {
return true;
}
- if (obj == null) {
+ if (!(obj instanceof «type.name»)) {
return false;
}
- if (getClass() != obj.getClass()) {
- return false;
- }
- «type.name» other = («type.name») obj;
+ final «type.name» other = («type.name») obj;
«FOR property : genTO.equalsIdentifiers»
«val fieldName = property.fieldName»
if (!«property.importedUtilClass».equals(«fieldName», other.«fieldName»)) {