Skip to content

Commit

Permalink
#21: Add org.cactoos.Text to Path entities
Browse files Browse the repository at this point in the history
  • Loading branch information
dgroup committed Oct 29, 2018
1 parent c56cfb1 commit 949d338
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
16 changes: 12 additions & 4 deletions src/main/java/com/github/dgroup/velocity/path/PathOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
*/
package com.github.dgroup.velocity.path;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.MessageFormat;
import org.cactoos.Scalar;
import org.cactoos.Text;
import org.cactoos.scalar.UncheckedScalar;

/**
Expand All @@ -45,10 +45,10 @@ public final class PathOf implements Scalar<Path> {
/**
* Ctor.
* @param pattern The path pattern for {@link MessageFormat#format}.
* The default delimiter is OS depended path separator.
* The default delimiter is `/` path separator.
*/
public PathOf(final String pattern) {
this(pattern, File.separator);
this(pattern, '/');
}

/**
Expand All @@ -57,7 +57,15 @@ public PathOf(final String pattern) {
* @param args The arguments for {@link MessageFormat#format}.
*/
public PathOf(final String pattern, final Object args) {
this(() -> Paths.get(MessageFormat.format(pattern, args)));
this(() -> MessageFormat.format(pattern, args));
}

/**
* Ctor.
* @param path The path to resource.
*/
public PathOf(final Text path) {
this(() -> Paths.get(path.asString()));
}

/**
Expand Down
16 changes: 12 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 @@ -23,11 +23,11 @@
*/
package com.github.dgroup.velocity.path;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.MessageFormat;
import org.cactoos.Scalar;
import org.cactoos.Text;
import org.cactoos.scalar.UncheckedScalar;

/**
Expand All @@ -47,10 +47,10 @@ public final class RelativePath implements Scalar<String> {
/**
* Ctor.
* @param pattern The path pattern for {@link MessageFormat#format}.
* The default delimiter is OS depended path separator.
* The default delimiter is '/' path separator.
*/
public RelativePath(final String pattern) {
this(pattern, File.separator);
this(pattern, '/');
}

/**
Expand All @@ -59,7 +59,15 @@ public RelativePath(final String pattern) {
* @param args The arguments for {@link MessageFormat#format}.
*/
public RelativePath(final String pattern, final Object... args) {
this(() -> MessageFormat.format(pattern, args));
this((Scalar<String>) () -> MessageFormat.format(pattern, args));
}

/**
* Ctor.
* @param path The path to resource.
*/
public RelativePath(final Text path) {
this((Scalar<String>) path::asString);
}

/**
Expand Down

0 comments on commit 949d338

Please sign in to comment.