Skip to content

Commit

Permalink
(yegor256#1030) ComparableText is not equal to the same text (equals)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyakharlamov committed Jan 24, 2019
1 parent 35b98c3 commit bbc5e3e
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/main/java/org/cactoos/text/ComparableText.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
package org.cactoos.text;

import java.util.Objects;
import org.cactoos.Text;
import org.cactoos.scalar.Equals;
import org.cactoos.scalar.HashCode;
import org.cactoos.scalar.UncheckedScalar;

Expand Down Expand Up @@ -73,18 +73,12 @@ public String asString() throws Exception {

@Override
public boolean equals(final Object other) {
final boolean result;
if (this == other) {
result = true;
} else if (other == null || this.getClass() != other.getClass()) {
result = false;
} else {
result = Objects.equals(
this.text,
((ComparableText) other).text
);
}
return result;
return new UncheckedScalar<>(
new Equals<>(
this.text::asString,
() -> ComparableText.class.cast(other).asString()
)
).value();
}

@Override
Expand Down

0 comments on commit bbc5e3e

Please sign in to comment.