diff --git a/src/main/java/com/pixelgamelibrary/api/interfaces/AppI.java b/src/main/java/com/pixelgamelibrary/api/interfaces/AppI.java index 5702581..7c40c7f 100644 --- a/src/main/java/com/pixelgamelibrary/api/interfaces/AppI.java +++ b/src/main/java/com/pixelgamelibrary/api/interfaces/AppI.java @@ -38,7 +38,11 @@ public interface AppI { } void exit(); void log(String msg); + void warn(String msg); void error(String msg); void debug(String msg); + void setAppName(String appName); + String getAppName(); + boolean isAppNameSet(); } diff --git a/src/main/java/com/pixelgamelibrary/api/storage/Storage.java b/src/main/java/com/pixelgamelibrary/api/storage/Storage.java index f5f71b6..46abe63 100644 --- a/src/main/java/com/pixelgamelibrary/api/storage/Storage.java +++ b/src/main/java/com/pixelgamelibrary/api/storage/Storage.java @@ -31,6 +31,8 @@ import java.util.List; */ public interface Storage { + public String SLASH = "/"; + /** * Returns the platform associated with this storage. * @@ -118,7 +120,15 @@ public interface Storage { * @param path the path to calculate depth for. * @return the depth of the path. */ - public int depth(String path); + default int depth(String path) { + // Return the depth of the given path + String absolutePath = convertToAbsolutePathIfNeeded(path); + if (absolutePath.equals(SLASH)) { + return 0; + } + String[] array = absolutePath.split(SLASH); + return array.length - 1; + } /** * Returns the depth of the current working directory in the directory tree. @@ -266,6 +276,7 @@ public interface Storage { static final String USER = "user"; default FileHandle file(String path) { + path = convertToAbsolutePathIfNeeded(path); return new FileHandleImpl(this, path); } default FileHandle file() { @@ -275,4 +286,18 @@ public interface Storage { FileType type(String path); RegularFileType getRegularFileType(String path); + + + /** + * Converts a path to an absolute path if it is not already absolute. + * + * @param path the path to convert + * @return the absolute path + */ + default String convertToAbsolutePathIfNeeded(String path) { + if (path.startsWith(SLASH)) { + return path; + } + return printWorkingDirectory() + (printWorkingDirectory().equals("/") ? "" : SLASH) + path; + } } diff --git a/src/main/java/com/pixelgamelibrary/api/storage/map/MapStorage.java b/src/main/java/com/pixelgamelibrary/api/storage/map/MapStorage.java index d25350c..657a068 100644 --- a/src/main/java/com/pixelgamelibrary/api/storage/map/MapStorage.java +++ b/src/main/java/com/pixelgamelibrary/api/storage/map/MapStorage.java @@ -76,19 +76,6 @@ public class MapStorage implements Storage { return null; } - /** - * Converts a path to an absolute path if it is not already absolute. - * - * @param path the path to convert - * @return the absolute path - */ - private String convertToAbsolutePathIfNeeded(String path) { - if (path.startsWith(SLASH)) { - return path; - } - return workingDirectory + (workingDirectory.equals("/") ? "" : SLASH) + path; - } - private static final String TWO_DOTS = ".."; private static final String SLASH = "/"; private static final String EIGHT_COLONS = "::::::::"; @@ -179,17 +166,6 @@ public class MapStorage implements Storage { return workingDirectory; } - @Override - public int depth(String path) { - // Return the depth of the given path - String absolutePath = convertToAbsolutePathIfNeeded(path); - if (absolutePath.equals(SLASH)) { - return 0; - } - String[] array = absolutePath.split(SLASH); - return array.length - 1; - } - @Override public List list(String path) { // List all files and directories at the specified path diff --git a/src/test/java/com/pixelgamelibrary/api/storage/map/MapStorageTest.java b/src/test/java/com/pixelgamelibrary/api/storage/map/MapStorageTest.java index da33b2d..0173087 100644 --- a/src/test/java/com/pixelgamelibrary/api/storage/map/MapStorageTest.java +++ b/src/test/java/com/pixelgamelibrary/api/storage/map/MapStorageTest.java @@ -55,6 +55,26 @@ public class MapStorageTest { public void debug(String msg) { } + + @Override + public void warn(String msg) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public void setAppName(String appName) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public String getAppName() { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public boolean isAppNameSet() { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } }; }