Skip to content

Commit

Permalink
Remove unnecessary Comparable implementation from Namespace + Parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoerdtalsma committed Feb 20, 2019
1 parent afacc5d commit bdad67d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 32 deletions.
11 changes: 2 additions & 9 deletions src/main/java/nl/talsmasoftware/umldoclet/uml/Namespace.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author Sjoerd Talsma
*/
public class Namespace extends UMLNode implements Comparable<Namespace> {
public class Namespace extends UMLNode {

public final String name;

Expand Down Expand Up @@ -66,15 +66,8 @@ public int hashCode() {
return name.hashCode();
}

@Override
public int compareTo(Namespace other) {
requireNonNull(other, "Cannot compare with namespace <null>.");
int diff = name.compareToIgnoreCase(other.name);
return diff == 0 ? name.compareTo(other.name) : diff;
}

@Override
public boolean equals(Object other) {
return this == other || (other instanceof Namespace && this.compareTo((Namespace) other) == 0);
return this == other || (other instanceof Namespace && name.equals(((Namespace) other).name));
}
}
14 changes: 1 addition & 13 deletions src/main/java/nl/talsmasoftware/umldoclet/uml/Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import nl.talsmasoftware.umldoclet.configuration.TypeDisplay;
import nl.talsmasoftware.umldoclet.rendering.indent.IndentingPrintWriter;

import java.util.Iterator;

/**
* @author Sjoerd Talsma
*/
public class Parameters extends UMLNode implements Comparable<Parameters> {
public class Parameters extends UMLNode {

private boolean varargs = false;

Expand Down Expand Up @@ -73,16 +71,6 @@ void replaceParameterizedType(TypeName from, TypeName to) {
}
}

@Override
public int compareTo(Parameters other) {
int delta = Integer.compare(this.getChildren().size(), other.getChildren().size());
for (Iterator<UMLNode> ours = this.getChildren().iterator(), theirs = other.getChildren().iterator();
delta == 0 && ours.hasNext() && theirs.hasNext(); ) {
delta = ((Parameter) ours.next()).type.compareTo(((Parameter) theirs.next()).type);
}
return delta;
}

private class Parameter extends UMLNode {
private final String name;
private TypeName type;
Expand Down
10 changes: 0 additions & 10 deletions src/test/java/nl/talsmasoftware/umldoclet/uml/NamespaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,4 @@ public void testEquals() {
assertThat(namespace, is(not(equalTo(new Namespace(packageUml, "A.B.C")))));
}

@Test
public void testCompareTo() {
PackageDiagram packageUml = new PackageDiagram(config, "a.b.c");
Namespace namespace = new Namespace(packageUml, "a.b.c");

assertThat(namespace.compareTo(namespace), is(0));
assertThat(namespace.compareTo(new Namespace(null, "a.b.c.d")), is(lessThan(0)));
assertThat(namespace.compareTo(new Namespace(null, "A.B.C")), is(not(0)));
}

}

0 comments on commit bdad67d

Please sign in to comment.