From fad41841c91709ef3ccdec197ddc59f691602adc Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Tue, 9 May 2023 16:44:35 -0600 Subject: [PATCH] Address JavaFormat Violations in Odm Issue gh-743 --- .../ldap/odm/tools/AttributeSchema.java | 105 ++++++++++-------- .../ldap/odm/tools/ObjectSchema.java | 77 +++++++------ .../ldap/odm/tools/SchemaToJava.java | 16 +-- .../ldap/odm/tools/SchemaViewer.java | 16 +-- .../ldap/odm/tools/SyntaxToJavaClass.java | 46 ++++---- .../ldap/odm/tools/package-info.java | 2 +- 6 files changed, 142 insertions(+), 120 deletions(-) diff --git a/odm/src/main/java/org/springframework/ldap/odm/tools/AttributeSchema.java b/odm/src/main/java/org/springframework/ldap/odm/tools/AttributeSchema.java index 1a368fbb..8b0bead1 100755 --- a/odm/src/main/java/org/springframework/ldap/odm/tools/AttributeSchema.java +++ b/odm/src/main/java/org/springframework/ldap/odm/tools/AttributeSchema.java @@ -84,18 +84,55 @@ public final class AttributeSchema { return this.isMultiValued; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override - public String toString() { - - return String.format( - "{ name=%1$s, syntax=%2$s, isMultiValued=%3$s, isPrimitive=%4$s, isBinary=%5$s, isArray=%6$s, scalarType=%7$s }", - this.name, this.syntax, this.isMultiValued, this.isPrimitive, this.isBinary, this.isArray, - this.scalarType); + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + AttributeSchema other = (AttributeSchema) obj; + if (this.isArray != other.isArray) { + return false; + } + if (this.isBinary != other.isBinary) { + return false; + } + if (this.isMultiValued != other.isMultiValued) { + return false; + } + if (this.isPrimitive != other.isPrimitive) { + return false; + } + if (this.name == null) { + if (other.name != null) { + return false; + } + } + else if (!this.name.equals(other.name)) { + return false; + } + if (this.scalarType == null) { + if (other.scalarType != null) { + return false; + } + } + else if (!this.scalarType.equals(other.scalarType)) { + return false; + } + if (this.syntax == null) { + if (other.syntax != null) { + return false; + } + } + else if (!this.syntax.equals(other.syntax)) { + return false; + } + return true; } @Override @@ -112,42 +149,18 @@ public final class AttributeSchema { return result; } + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - AttributeSchema other = (AttributeSchema) obj; - if (this.isArray != other.isArray) - return false; - if (this.isBinary != other.isBinary) - return false; - if (this.isMultiValued != other.isMultiValued) - return false; - if (this.isPrimitive != other.isPrimitive) - return false; - if (this.name == null) { - if (other.name != null) - return false; - } - else if (!this.name.equals(other.name)) - return false; - if (this.scalarType == null) { - if (other.scalarType != null) - return false; - } - else if (!this.scalarType.equals(other.scalarType)) - return false; - if (this.syntax == null) { - if (other.syntax != null) - return false; - } - else if (!this.syntax.equals(other.syntax)) - return false; - return true; + public String toString() { + + return String.format( + "{ name=%1$s, syntax=%2$s, isMultiValued=%3$s, isPrimitive=%4$s, isBinary=%5$s, isArray=%6$s, scalarType=%7$s }", + this.name, this.syntax, this.isMultiValued, this.isPrimitive, this.isBinary, this.isArray, + this.scalarType); } } diff --git a/odm/src/main/java/org/springframework/ldap/odm/tools/ObjectSchema.java b/odm/src/main/java/org/springframework/ldap/odm/tools/ObjectSchema.java index d098daa4..9e12a50a 100755 --- a/odm/src/main/java/org/springframework/ldap/odm/tools/ObjectSchema.java +++ b/odm/src/main/java/org/springframework/ldap/odm/tools/ObjectSchema.java @@ -66,14 +66,43 @@ public final class ObjectSchema { return Collections.unmodifiableSet(this.objectClass); } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override - public String toString() { - return String.format("objectClass=%1$s | must=%2$s | may=%3$s", this.objectClass, this.must, this.may); + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ObjectSchema other = (ObjectSchema) obj; + if (this.may == null) { + if (other.may != null) { + return false; + } + } + else if (!this.may.equals(other.may)) { + return false; + } + if (this.must == null) { + if (other.must != null) { + return false; + } + } + else if (!this.must.equals(other.must)) { + return false; + } + if (this.objectClass == null) { + if (other.objectClass != null) { + return false; + } + } + else if (!this.objectClass.equals(other.objectClass)) { + return false; + } + return true; } @Override @@ -86,34 +115,14 @@ public final class ObjectSchema { return result; } + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ObjectSchema other = (ObjectSchema) obj; - if (this.may == null) { - if (other.may != null) - return false; - } - else if (!this.may.equals(other.may)) - return false; - if (this.must == null) { - if (other.must != null) - return false; - } - else if (!this.must.equals(other.must)) - return false; - if (this.objectClass == null) { - if (other.objectClass != null) - return false; - } - else if (!this.objectClass.equals(other.objectClass)) - return false; - return true; + public String toString() { + return String.format("objectClass=%1$s | must=%2$s | may=%3$s", this.objectClass, this.must, this.may); } } diff --git a/odm/src/main/java/org/springframework/ldap/odm/tools/SchemaToJava.java b/odm/src/main/java/org/springframework/ldap/odm/tools/SchemaToJava.java index 36edb2eb..f1a9f9ec 100755 --- a/odm/src/main/java/org/springframework/ldap/odm/tools/SchemaToJava.java +++ b/odm/src/main/java/org/springframework/ldap/odm/tools/SchemaToJava.java @@ -360,8 +360,8 @@ public final class SchemaToJava { try { cmd = parser.parse(DEFAULT_OPTIONS, argv); } - catch (ParseException e) { - error(e.toString()); + catch (ParseException ex) { + error(ex.toString()); } // If the help flag is specified ignore other flags, print a usage message and @@ -390,8 +390,8 @@ public final class SchemaToJava { try { outputFile = makeOutputFile(outputDir, packageName, className); } - catch (IOException e) { - error(e.toString()); + catch (IOException ex) { + error(ex.toString()); } // Get the flags we need to bind to the directory @@ -418,9 +418,9 @@ public final class SchemaToJava { try { syntaxToJavaClass = new SyntaxToJavaClass(readSyntaxMap(syntaxMapFile)); } - catch (IOException e) { + catch (IOException ex) { error(String.format("Error reading syntax map file %1$s - %2$s", syntaxMapFile.getAbsolutePath(), - e.toString())); + ex.toString())); } } else { @@ -441,8 +441,8 @@ public final class SchemaToJava { try { binarySet = readBinarySet(binarySetFile); } - catch (IOException e) { - error(String.format("Error reading binary set file %1$s - %2$s", binarySetFile.getAbsolutePath(), e)); + catch (IOException ex) { + error(String.format("Error reading binary set file %1$s - %2$s", binarySetFile.getAbsolutePath(), ex)); } // Read schema from the directory diff --git a/odm/src/main/java/org/springframework/ldap/odm/tools/SchemaViewer.java b/odm/src/main/java/org/springframework/ldap/odm/tools/SchemaViewer.java index 9a81c971..3b34126c 100755 --- a/odm/src/main/java/org/springframework/ldap/odm/tools/SchemaViewer.java +++ b/odm/src/main/java/org/springframework/ldap/odm/tools/SchemaViewer.java @@ -201,8 +201,8 @@ public final class SchemaViewer { try { cmd = parser.parse(DEFAULT_OPTIONS, argv); } - catch (ParseException e) { - System.out.println(e.getMessage()); + catch (ParseException ex) { + System.out.println(ex.getMessage()); System.exit(1); } @@ -253,17 +253,17 @@ public final class SchemaViewer { } } - catch (AuthenticationException e) { + catch (AuthenticationException ex) { System.err.println(String.format("Failed to bind to ldap server at %1$s", url)); } - catch (CommunicationException e) { + catch (CommunicationException ex) { System.err.println(String.format("Failed to contact ldap server at %1$s", url)); } - catch (NameNotFoundException e) { - System.err.println(String.format("Can't find object %1$s", e.getMessage())); + catch (NameNotFoundException ex) { + System.err.println(String.format("Can't find object %1$s", ex.getMessage())); } - catch (NamingException e) { - System.err.println(e.toString()); + catch (NamingException ex) { + System.err.println(ex.toString()); } } diff --git a/odm/src/main/java/org/springframework/ldap/odm/tools/SyntaxToJavaClass.java b/odm/src/main/java/org/springframework/ldap/odm/tools/SyntaxToJavaClass.java index 37933034..500bb30f 100755 --- a/odm/src/main/java/org/springframework/ldap/odm/tools/SyntaxToJavaClass.java +++ b/odm/src/main/java/org/springframework/ldap/odm/tools/SyntaxToJavaClass.java @@ -27,6 +27,29 @@ import java.util.Map.Entry; */ /* package */ final class SyntaxToJavaClass { + private final Map mapSyntaxToClassInfo = new HashMap(); + + public SyntaxToJavaClass(Map mapSyntaxToClass) { + for (Entry syntaxAndClass : mapSyntaxToClass.entrySet()) { + String fullClassName = syntaxAndClass.getValue().trim(); + String packageName = null; + String className = null; + int lastDotIndex = fullClassName.lastIndexOf('.'); + if (lastDotIndex != -1) { + className = fullClassName.substring(lastDotIndex + 1); + packageName = fullClassName.substring(0, lastDotIndex); + } + else { + className = fullClassName; + } + this.mapSyntaxToClassInfo.put(syntaxAndClass.getKey(), new ClassInfo(className, packageName)); + } + } + + public ClassInfo getClassInfo(String syntax) { + return this.mapSyntaxToClassInfo.get(syntax); + } + public static final class ClassInfo { private final String className; @@ -59,27 +82,4 @@ import java.util.Map.Entry; } - private final Map mapSyntaxToClassInfo = new HashMap(); - - public SyntaxToJavaClass(Map mapSyntaxToClass) { - for (Entry syntaxAndClass : mapSyntaxToClass.entrySet()) { - String fullClassName = syntaxAndClass.getValue().trim(); - String packageName = null; - String className = null; - int lastDotIndex = fullClassName.lastIndexOf('.'); - if (lastDotIndex != -1) { - className = fullClassName.substring(lastDotIndex + 1); - packageName = fullClassName.substring(0, lastDotIndex); - } - else { - className = fullClassName; - } - this.mapSyntaxToClassInfo.put(syntaxAndClass.getKey(), new ClassInfo(className, packageName)); - } - } - - public ClassInfo getClassInfo(String syntax) { - return this.mapSyntaxToClassInfo.get(syntax); - } - } diff --git a/odm/src/main/java/org/springframework/ldap/odm/tools/package-info.java b/odm/src/main/java/org/springframework/ldap/odm/tools/package-info.java index 3bf9e768..f31bae28 100755 --- a/odm/src/main/java/org/springframework/ldap/odm/tools/package-info.java +++ b/odm/src/main/java/org/springframework/ldap/odm/tools/package-info.java @@ -21,4 +21,4 @@ * @author Paul Harvey <paul.at.pauls-place.me.uk> */ -package org.springframework.ldap.odm.tools; \ No newline at end of file +package org.springframework.ldap.odm.tools;