Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.10] Support Smithy IDL Serialization #284

Merged
merged 16 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Compare ShapeId's case-insensitively
This updates the `compareTo` on shapeIds to be case-insensitve by
default, with a case-sensitive tie-breaker. Though technically that
means we could be comparing a given shape twice, practically the
likelihood is low since ShapeId's in a model must be
case-insensitively unique.
  • Loading branch information
JordonPhillips committed Feb 27, 2020
commit 1811d0a36f7add497a15d0be73836a7436057a33
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,12 @@ public ShapeId toShapeId() {

@Override
public int compareTo(ShapeId other) {
return toString().compareTo(other.toString());
int outcome = toString().compareToIgnoreCase(other.toString());
if (outcome == 0) {
// If they're case-insensitively equal, use a case-sensitive comparison as a tie-breaker.
return toString().compareTo(other.toString());
}
return outcome;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -238,6 +239,34 @@ public static Collection<Object[]> toStringData() {
});
}

@Test
public void compareToTest() {
List<ShapeId> given = Arrays.asList(
ShapeId.fromParts("ns.foo", "foo"),
ShapeId.fromParts("ns.foo", "Foo"),
ShapeId.fromParts("ns.foo", "bar"),
ShapeId.fromParts("ns.foo", "bar", "member"),
ShapeId.fromParts("ns.foo", "bar", "Member"),
ShapeId.fromParts("ns.foo", "bar", "AMember"),
ShapeId.fromParts("ns.Foo", "foo"),
ShapeId.fromParts("ns.baz", "foo")
);
given.sort(ShapeId::compareTo);

List<ShapeId> expected = Arrays.asList(
ShapeId.fromParts("ns.baz", "foo"),
ShapeId.fromParts("ns.foo", "bar"),
ShapeId.fromParts("ns.foo", "bar", "AMember"),
ShapeId.fromParts("ns.foo", "bar", "Member"),
ShapeId.fromParts("ns.foo", "bar", "member"),
ShapeId.fromParts("ns.Foo", "foo"),
ShapeId.fromParts("ns.foo", "Foo"),
ShapeId.fromParts("ns.foo", "foo")
);

assertEquals(expected, given);
}

@ParameterizedTest
@MethodSource("equalsData")
public void equalsTest(final ShapeId lhs, final Object rhs, final boolean expected) {
Expand Down