Skip to content

Commit

Permalink
(#1030) ComparableText is not equal to the same text (extends TestEnv…
Browse files Browse the repository at this point in the history
…elope)
  • Loading branch information
ilyakharlamov committed Jan 26, 2019
1 parent 342a224 commit 108c9c7
Showing 1 changed file with 4 additions and 30 deletions.
34 changes: 4 additions & 30 deletions src/main/java/org/cactoos/text/ComparableText.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
package org.cactoos.text;

import org.cactoos.Text;
import org.cactoos.scalar.Equals;
import org.cactoos.scalar.HashCode;
import org.cactoos.scalar.UncheckedScalar;

/**
Expand All @@ -44,45 +42,21 @@
*
* @since 0.27
*/
public final class ComparableText implements Text, Comparable<Text> {

/**
* The origin.
*/
private final Text text;
public final class ComparableText extends TextEnvelope
implements Comparable<Text> {

/**
* Ctor.
* @param text The text
*/
public ComparableText(final Text text) {
this.text = text;
super(text);
}

@Override
public int compareTo(final Text other) {
return new UncheckedScalar<>(
() -> this.text.asString().compareTo(other.asString())
).value();
}

@Override
public String asString() throws Exception {
return this.text.asString();
}

@Override
public boolean equals(final Object other) {
return new UncheckedScalar<>(
new Equals<>(
this.text::asString,
() -> ComparableText.class.cast(other).asString()
)
() -> this.asString().compareTo(other.asString())
).value();
}

@Override
public int hashCode() {
return new HashCode(this.text).value();
}
}

0 comments on commit 108c9c7

Please sign in to comment.