diff --git a/model/src/main/java/one/nem/lacerta/model/PublicPath.java b/model/src/main/java/one/nem/lacerta/model/PublicPath.java index 8ca9e9ff..3181d00e 100644 --- a/model/src/main/java/one/nem/lacerta/model/PublicPath.java +++ b/model/src/main/java/one/nem/lacerta/model/PublicPath.java @@ -1,23 +1,47 @@ package one.nem.lacerta.model; +import java.util.ArrayList; +import java.util.List; + public class PublicPath { /* * ユーザーが扱うパス(内部パスの代替) */ - String[] path; + List path = new ArrayList(); public PublicPath() { - this.path = new String[0]; } - public PublicPath load(String[] path) { + public PublicPath(List path) { this.path = path; + } + + private void add(String path) { + this.path.add(path); + } + + public PublicPath resolve(String path) { + if (path.equals("..")) { + this.path.remove(this.path.size() - 1); + } else { + add(path); + } return this; } - public PublicPath load(String path) { - this.path = path.split("/"); + public PublicPath resolve(List path) { + for (String p : path) { + resolve(p); + } return this; } + + public List getPath() { + return path; + } + + public String getStringPath() { + return String.join("/", path); + } }