-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #380 from gdgib/G2-1649-FileSystemAPI
G2-1649 Support flexible arity for parent & child paths
- Loading branch information
Showing
6 changed files
with
62 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
ax-path/src/main/java/com/g2forge/alexandria/path/file/system/ISelfFileSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.g2forge.alexandria.path.file.system; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.g2forge.alexandria.path.path.IPath; | ||
import com.g2forge.alexandria.path.path.Path; | ||
|
||
public interface ISelfFileSystem<T> extends IFileSystem<T> { | ||
public T getSelf(); | ||
|
||
@Override | ||
public default IPath<T> normalize(IPath<T> path) { | ||
if (path.isEmpty()) return path; | ||
|
||
final List<T> retVal = new ArrayList<>(path.getComponents().toCollection()); | ||
for (int i = 0; i < retVal.size(); i++) { | ||
final T current = retVal.get(i); | ||
if (getSelf().equals(current)) retVal.remove(i--); | ||
} | ||
return new Path<>(retVal); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
ax-path/src/main/java/com/g2forge/alexandria/path/file/system/ITreeFileSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.g2forge.alexandria.path.file.system; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.g2forge.alexandria.path.path.IPath; | ||
import com.g2forge.alexandria.path.path.Path; | ||
|
||
public interface ITreeFileSystem<T> extends IFileSystem<T> { | ||
public T getParent(); | ||
|
||
@Override | ||
public default boolean isRootEscape(IPath<T> path) { | ||
return normalize(path).startsWith(new Path<>(getParent())); | ||
} | ||
|
||
@Override | ||
public default IPath<T> normalize(IPath<T> path) { | ||
if (path.isEmpty()) return path; | ||
|
||
final List<T> retVal = new ArrayList<>(path.getComponents().toCollection()); | ||
for (int i = 0; i < retVal.size(); i++) { | ||
final T current = retVal.get(i); | ||
if (getParent().equals(current) && (i > 0) && !getParent().equals(retVal.get(i - 1))) { | ||
retVal.remove(i--); | ||
retVal.remove(i--); | ||
} | ||
} | ||
return new Path<>(retVal); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters