Skip to content

Commit

Permalink
Merge branch '2.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Dec 17, 2018
2 parents c8a0c99 + 7dbe70d commit 317c4c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,20 @@ public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || !CharSequence.class.isInstance(obj)) {
if (!(obj instanceof CharSequence)) {
return false;
}
CharSequence other = (CharSequence) obj;
int n = length();
if (n == other.length()) {
int i = 0;
while (n-- != 0) {
if (charAt(i) != other.charAt(i)) {
return false;
}
i++;
if (n != other.length()) {
return false;
}
int i = 0;
while (n-- != 0) {
if (charAt(i) != other.charAt(i)) {
return false;
}
return true;
i++;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ public void equalsWhenSameContentShouldMatch() {
assertThat(a).isEqualTo(b).isNotEqualTo(c);
}

@Test
public void notEqualsWhenSequencesOfDifferentLength() {
StringSequence a = new StringSequence("abcd");
StringSequence b = new StringSequence("ef");
assertThat(a).isNotEqualTo(b);
}

@Test
public void startsWithWhenExactMatch() {
assertThat(new StringSequence("abc").startsWith("abc")).isTrue();
Expand Down

0 comments on commit 317c4c2

Please sign in to comment.