Skip to content

Commit

Permalink
#24: *.path.* classes should implement org.cactoos.Text`
Browse files Browse the repository at this point in the history
  • Loading branch information
dgroup committed Oct 30, 2018
1 parent 5086ed7 commit 3db601d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
14 changes: 8 additions & 6 deletions src/main/java/com/github/dgroup/velocity/path/PathOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
import java.text.MessageFormat;
import org.cactoos.Scalar;
import org.cactoos.Text;
import org.cactoos.scalar.UncheckedScalar;
import org.cactoos.text.UncheckedText;

/**
* The path to the resource.
*
* @since 0.1.0
*/
public final class PathOf implements Scalar<Path> {
public final class PathOf implements Scalar<Path>, Text {

/**
* The path.
Expand Down Expand Up @@ -83,9 +83,11 @@ public Path value() throws Exception {

@Override
public String toString() {
return new UncheckedScalar<>(this)
.value()
.toAbsolutePath()
.toString();
return new UncheckedText((Text) this).asString();
}

@Override
public String asString() throws Exception {
return this.value().toAbsolutePath().toString();
}
}
12 changes: 8 additions & 4 deletions src/main/java/com/github/dgroup/velocity/path/RelativePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.text.MessageFormat;
import org.cactoos.Scalar;
import org.cactoos.Text;
import org.cactoos.scalar.UncheckedScalar;
import org.cactoos.text.UncheckedText;

/**
* Relative path.
Expand All @@ -37,7 +37,7 @@
*
* @since 0.2
*/
public final class RelativePath implements Scalar<String> {
public final class RelativePath implements Scalar<String>, Text {

/**
* The relative path.
Expand Down Expand Up @@ -85,15 +85,19 @@ public String value() throws Exception {

@Override
public String toString() {
return new UncheckedScalar<>(this).value();
return new UncheckedText((Text)this).asString();
}

/**
* Convert relative path to {@link Path}.
* @return The path.
*/
public Scalar<Path> toPath() {
return () -> Paths.get(this.toString());
return () -> Paths.get(this.asString());
}

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

0 comments on commit 3db601d

Please sign in to comment.