From: Robert Varga Date: Wed, 9 Nov 2022 23:40:15 +0000 (+0100) Subject: Use primitive comparison for bit properties X-Git-Tag: v14.0.0~430 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=ba8955d31b110d4b08cb13884b3e4fcce73dc0bf;p=yangtools.git Use primitive comparison for bit properties Rather than boxing to go through Objects.equals(), use plain '==' on booleans. JIRA: MDSAL-744 Change-Id: I005ba52d8c68fb9eaf7d93e40adcf13ca159436f Signed-off-by: Robert Varga --- diff --git a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/ClassTemplate.xtend b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/ClassTemplate.xtend index 8eee22e211..b9a2e53c4e 100644 --- a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/ClassTemplate.xtend +++ b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/ClassTemplate.xtend @@ -47,6 +47,7 @@ import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject import org.opendaylight.mdsal.binding.model.api.Restrictions import org.opendaylight.mdsal.binding.model.api.Type import org.opendaylight.mdsal.binding.model.ri.TypeConstants +import org.opendaylight.mdsal.binding.model.ri.Types import org.opendaylight.mdsal.binding.spec.naming.BindingMapping import org.opendaylight.yangtools.yang.common.Empty @@ -574,10 +575,15 @@ class ClassTemplate extends BaseTemplate { @«OVERRIDE.importedName» public final boolean equals(«OBJECT.importedName» obj) { return this == obj || obj instanceof «type.name» other - «FOR property : genTO.equalsIdentifiers» - «val fieldName = property.fieldName» - && «property.importedUtilClass».equals(«fieldName», other.«fieldName»)« - »«ENDFOR»; + «FOR property : genTO.equalsIdentifiers» + «val fieldName = property.fieldName» + «val type = property.returnType» + «IF type.equals(Types.primitiveBooleanType)» + && «fieldName» == other.«fieldName»« + »«ELSE» + && «type.importedUtilClass».equals(«fieldName», other.«fieldName»)« + »«ENDIF»« + »«ENDFOR»; } «ENDIF» ''' diff --git a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/JavaFileTemplate.java b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/JavaFileTemplate.java index 45728d2cd8..58cfafd6d5 100644 --- a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/JavaFileTemplate.java +++ b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/JavaFileTemplate.java @@ -272,7 +272,18 @@ class JavaFileTemplate { * @return Imported class name */ final String importedUtilClass(final GeneratedProperty property) { - return importedName(property.getReturnType().getName().indexOf('[') != -1 ? JU_ARRAYS : JU_OBJECTS); + return importedUtilClass(property.getReturnType()); + } + + /** + * Return imported name of java.util class, whose hashCode/equals methods we want to invoke for a type. Returns + * {@link Arrays} if the type is an array, {@link Objects} otherwise. + * + * @param returnType A property return Type + * @return Imported class name + */ + final String importedUtilClass(final Type returnType) { + return importedName(returnType.getName().indexOf('[') != -1 ? JU_ARRAYS : JU_OBJECTS); } final String generatedAnnotation() {