Some API changes
This commit is contained in:
parent
50eba8238b
commit
a3204d9a84
@ -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();
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<String> list(String path) {
|
||||
// List all files and directories at the specified path
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user