LinkFSPath.java
net.minecraft.server.packs.linkfs.LinkFSPath
信息
- 全限定名:net.minecraft.server.packs.linkfs.LinkFSPath
- 类型:package-private class
- 包:net.minecraft.server.packs.linkfs
- 源码路径:src/main/java/net/minecraft/server/packs/linkfs/LinkFSPath.java
- 起始行号:L28
- 实现:Path
- 职责:
TODO
字段/常量
-
PATH_COMPARATOR- 类型:
Comparator<LinkFSPath> - 修饰符:
private static final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
name- 类型:
String - 修饰符:
private final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
fileSystem- 类型:
LinkFileSystem - 修饰符:
private final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
parent- 类型:
LinkFSPath - 修饰符:
private final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
pathToRoot- 类型:
List<String> - 修饰符:
private - 源码定位:
L33 - 说明:
TODO
- 类型:
-
pathString- 类型:
String - 修饰符:
private - 源码定位:
L34 - 说明:
TODO
- 类型:
-
pathContents- 类型:
PathContents - 修饰符:
private final - 源码定位:
L35 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public LinkFSPath(LinkFileSystem fileSystem, String name, LinkFSPath parent, PathContents pathContents) @ L37
- 构造器名:LinkFSPath
- 源码定位:L37
- 修饰符:public
参数:
- fileSystem: LinkFileSystem
- name: String
- parent: LinkFSPath
- pathContents: PathContents
说明:
TODO
方法
下面的方法块按源码顺序生成。
private LinkFSPath createRelativePath(LinkFSPath parent, String name) @ L44
- 方法名:createRelativePath
- 源码定位:L44
- 返回类型:LinkFSPath
- 修饰符:private
参数:
- parent: LinkFSPath
- name: String
说明:
TODO
public LinkFileSystem getFileSystem() @ L48
- 方法名:getFileSystem
- 源码定位:L48
- 返回类型:LinkFileSystem
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean isAbsolute() @ L52
- 方法名:isAbsolute
- 源码定位:L52
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public File toFile() @ L57
- 方法名:toFile
- 源码定位:L57
- 返回类型:File
- 修饰符:public
参数:
- 无
说明:
TODO
public LinkFSPath getRoot() @ L66
- 方法名:getRoot
- 源码定位:L66
- 返回类型:LinkFSPath
- 修饰符:public
参数:
- 无
说明:
TODO
public LinkFSPath getFileName() @ L70
- 方法名:getFileName
- 源码定位:L70
- 返回类型:LinkFSPath
- 修饰符:public
参数:
- 无
说明:
TODO
public LinkFSPath getParent() @ L74
- 方法名:getParent
- 源码定位:L74
- 返回类型:LinkFSPath
- 修饰符:public
参数:
- 无
说明:
TODO
public int getNameCount() @ L78
- 方法名:getNameCount
- 源码定位:L78
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
private List<String> pathToRoot() @ L83
- 方法名:pathToRoot
- 源码定位:L83
- 返回类型:List
- 修饰符:private
参数:
- 无
说明:
TODO
public LinkFSPath getName(int index) @ L101
- 方法名:getName
- 源码定位:L101
- 返回类型:LinkFSPath
- 修饰符:public
参数:
- index: int
说明:
TODO
public LinkFSPath subpath(int beginIndex, int endIndex) @ L110
- 方法名:subpath
- 源码定位:L110
- 返回类型:LinkFSPath
- 修饰符:public
参数:
- beginIndex: int
- endIndex: int
说明:
TODO
public boolean startsWith(Path other) @ L125
- 方法名:startsWith
- 源码定位:L125
- 返回类型:boolean
- 修饰符:public
参数:
- other: Path
说明:
TODO
public boolean endsWith(Path other) @ L153
- 方法名:endsWith
- 源码定位:L153
- 返回类型:boolean
- 修饰符:public
参数:
- other: Path
说明:
TODO
public LinkFSPath normalize() @ L182
- 方法名:normalize
- 源码定位:L182
- 返回类型:LinkFSPath
- 修饰符:public
参数:
- 无
说明:
TODO
public LinkFSPath resolve(Path other) @ L186
- 方法名:resolve
- 源码定位:L186
- 返回类型:LinkFSPath
- 修饰符:public
参数:
- other: Path
说明:
TODO
private LinkFSPath resolve(List<String> names) @ L191
- 方法名:resolve
- 源码定位:L191
- 返回类型:LinkFSPath
- 修饰符:private
参数:
- names: List
说明:
TODO
LinkFSPath resolveName(String name) @ L201
- 方法名:resolveName
- 源码定位:L201
- 返回类型:LinkFSPath
- 修饰符:package-private
参数:
- name: String
说明:
TODO
private static boolean isRelativeOrMissing(PathContents contents) @ L214
- 方法名:isRelativeOrMissing
- 源码定位:L214
- 返回类型:boolean
- 修饰符:private static
参数:
- contents: PathContents
说明:
TODO
public LinkFSPath relativize(Path other) @ L218
- 方法名:relativize
- 源码定位:L218
- 返回类型:LinkFSPath
- 修饰符:public
参数:
- other: Path
说明:
TODO
public URI toUri() @ L239
- 方法名:toUri
- 源码定位:L239
- 返回类型:URI
- 修饰符:public
参数:
- 无
说明:
TODO
public LinkFSPath toAbsolutePath() @ L248
- 方法名:toAbsolutePath
- 源码定位:L248
- 返回类型:LinkFSPath
- 修饰符:public
参数:
- 无
说明:
TODO
public LinkFSPath toRealPath(LinkOption... options) @ L252
- 方法名:toRealPath
- 源码定位:L252
- 返回类型:LinkFSPath
- 修饰符:public
参数:
- options: LinkOption…
说明:
TODO
public WatchKey register(WatchService watcher, Kind<?>[] events, Modifier... modifiers) @ L256
- 方法名:register
- 源码定位:L256
- 返回类型:WatchKey
- 修饰符:public
参数:
- watcher: WatchService
- events: Kind<?>[]
- modifiers: Modifier…
说明:
TODO
public int compareTo(Path other) @ L261
- 方法名:compareTo
- 源码定位:L261
- 返回类型:int
- 修饰符:public
参数:
- other: Path
说明:
TODO
public boolean equals(Object other) @ L267
- 方法名:equals
- 源码定位:L267
- 返回类型:boolean
- 修饰符:public
参数:
- other: Object
说明:
TODO
private boolean hasRealContents() @ L289
- 方法名:hasRealContents
- 源码定位:L289
- 返回类型:boolean
- 修饰符:private
参数:
- 无
说明:
TODO
public int hashCode() @ L293
- 方法名:hashCode
- 源码定位:L293
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public String toString() @ L298
- 方法名:toString
- 源码定位:L298
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
private String pathToString() @ L303
- 方法名:pathToString
- 源码定位:L303
- 返回类型:String
- 修饰符:private
参数:
- 无
说明:
TODO
private LinkFSPath toLinkPath(Path path) @ L317
- 方法名:toLinkPath
- 源码定位:L317
- 返回类型:LinkFSPath
- 修饰符:private
参数:
- path: Path
说明:
TODO
public boolean exists() @ L327
- 方法名:exists
- 源码定位:L327
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public Path getTargetPath() @ L331
- 方法名:getTargetPath
- 源码定位:L331
- 返回类型:Path
- 修饰符:public
参数:
- 无
说明:
TODO
public PathContents.DirectoryContents getDirectoryContents() @ L335
- 方法名:getDirectoryContents
- 源码定位:L335
- 返回类型:PathContents.DirectoryContents
- 修饰符:public
参数:
- 无
说明:
TODO
public BasicFileAttributeView getBasicAttributeView() @ L339
- 方法名:getBasicAttributeView
- 源码定位:L339
- 返回类型:BasicFileAttributeView
- 修饰符:public
参数:
- 无
说明:
TODO
public BasicFileAttributes getBasicAttributes() @ L362
- 方法名:getBasicAttributes
- 源码定位:L362
- 返回类型:BasicFileAttributes
- 修饰符:public
参数:
- 无
说明:
TODO
代码
class LinkFSPath implements Path {
private static final Comparator<LinkFSPath> PATH_COMPARATOR = Comparator.comparing(LinkFSPath::pathToString);
private final String name;
private final LinkFileSystem fileSystem;
private final @Nullable LinkFSPath parent;
private @Nullable List<String> pathToRoot;
private @Nullable String pathString;
private final PathContents pathContents;
public LinkFSPath(LinkFileSystem fileSystem, String name, @Nullable LinkFSPath parent, PathContents pathContents) {
this.fileSystem = fileSystem;
this.name = name;
this.parent = parent;
this.pathContents = pathContents;
}
private LinkFSPath createRelativePath(@Nullable LinkFSPath parent, String name) {
return new LinkFSPath(this.fileSystem, name, parent, PathContents.RELATIVE);
}
public LinkFileSystem getFileSystem() {
return this.fileSystem;
}
@Override
public boolean isAbsolute() {
return this.pathContents != PathContents.RELATIVE;
}
@Override
public File toFile() {
if (this.pathContents instanceof PathContents.FileContents file) {
return file.contents().toFile();
} else {
throw new UnsupportedOperationException("Path " + this.pathToString() + " does not represent file");
}
}
public @Nullable LinkFSPath getRoot() {
return this.isAbsolute() ? this.fileSystem.rootPath() : null;
}
public LinkFSPath getFileName() {
return this.createRelativePath(null, this.name);
}
public @Nullable LinkFSPath getParent() {
return this.parent;
}
@Override
public int getNameCount() {
return this.pathToRoot().size();
}
private List<String> pathToRoot() {
if (this.name.isEmpty()) {
return List.of();
} else {
if (this.pathToRoot == null) {
Builder<String> result = ImmutableList.builder();
if (this.parent != null) {
result.addAll(this.parent.pathToRoot());
}
result.add(this.name);
this.pathToRoot = result.build();
}
return this.pathToRoot;
}
}
public LinkFSPath getName(int index) {
List<String> names = this.pathToRoot();
if (index >= 0 && index < names.size()) {
return this.createRelativePath(null, names.get(index));
} else {
throw new IllegalArgumentException("Invalid index: " + index);
}
}
public LinkFSPath subpath(int beginIndex, int endIndex) {
List<String> names = this.pathToRoot();
if (beginIndex >= 0 && endIndex <= names.size() && beginIndex < endIndex) {
LinkFSPath current = null;
for (int i = beginIndex; i < endIndex; i++) {
current = this.createRelativePath(current, names.get(i));
}
return current;
} else {
throw new IllegalArgumentException();
}
}
@Override
public boolean startsWith(Path other) {
if (other.isAbsolute() != this.isAbsolute()) {
return false;
} else if (other instanceof LinkFSPath otherLink) {
if (otherLink.fileSystem != this.fileSystem) {
return false;
} else {
List<String> thisNames = this.pathToRoot();
List<String> otherNames = otherLink.pathToRoot();
int otherSize = otherNames.size();
if (otherSize > thisNames.size()) {
return false;
} else {
for (int i = 0; i < otherSize; i++) {
if (!otherNames.get(i).equals(thisNames.get(i))) {
return false;
}
}
return true;
}
}
} else {
return false;
}
}
@Override
public boolean endsWith(Path other) {
if (other.isAbsolute() && !this.isAbsolute()) {
return false;
} else if (other instanceof LinkFSPath otherLink) {
if (otherLink.fileSystem != this.fileSystem) {
return false;
} else {
List<String> thisNames = this.pathToRoot();
List<String> otherNames = otherLink.pathToRoot();
int otherSize = otherNames.size();
int delta = thisNames.size() - otherSize;
if (delta < 0) {
return false;
} else {
for (int i = otherSize - 1; i >= 0; i--) {
if (!otherNames.get(i).equals(thisNames.get(delta + i))) {
return false;
}
}
return true;
}
}
} else {
return false;
}
}
public LinkFSPath normalize() {
return this;
}
public LinkFSPath resolve(Path other) {
LinkFSPath otherLink = this.toLinkPath(other);
return other.isAbsolute() ? otherLink : this.resolve(otherLink.pathToRoot());
}
private LinkFSPath resolve(List<String> names) {
LinkFSPath current = this;
for (String name : names) {
current = current.resolveName(name);
}
return current;
}
LinkFSPath resolveName(String name) {
if (isRelativeOrMissing(this.pathContents)) {
return new LinkFSPath(this.fileSystem, name, this, this.pathContents);
} else if (this.pathContents instanceof PathContents.DirectoryContents directory) {
LinkFSPath child = directory.children().get(name);
return child != null ? child : new LinkFSPath(this.fileSystem, name, this, PathContents.MISSING);
} else if (this.pathContents instanceof PathContents.FileContents) {
return new LinkFSPath(this.fileSystem, name, this, PathContents.MISSING);
} else {
throw new AssertionError("All content types should be already handled");
}
}
private static boolean isRelativeOrMissing(PathContents contents) {
return contents == PathContents.MISSING || contents == PathContents.RELATIVE;
}
public LinkFSPath relativize(Path other) {
LinkFSPath otherLink = this.toLinkPath(other);
if (this.isAbsolute() != otherLink.isAbsolute()) {
throw new IllegalArgumentException("absolute mismatch");
} else {
List<String> thisNames = this.pathToRoot();
List<String> otherNames = otherLink.pathToRoot();
if (thisNames.size() >= otherNames.size()) {
throw new IllegalArgumentException();
} else {
for (int i = 0; i < thisNames.size(); i++) {
if (!thisNames.get(i).equals(otherNames.get(i))) {
throw new IllegalArgumentException();
}
}
return otherLink.subpath(thisNames.size(), otherNames.size());
}
}
}
@Override
public URI toUri() {
try {
return new URI("x-mc-link", this.fileSystem.store().name(), this.pathToString(), null);
} catch (URISyntaxException var2) {
throw new AssertionError("Failed to create URI", var2);
}
}
public LinkFSPath toAbsolutePath() {
return this.isAbsolute() ? this : this.fileSystem.rootPath().resolve(this);
}
public LinkFSPath toRealPath(LinkOption... options) {
return this.toAbsolutePath();
}
@Override
public WatchKey register(WatchService watcher, Kind<?>[] events, Modifier... modifiers) {
throw new UnsupportedOperationException();
}
@Override
public int compareTo(Path other) {
LinkFSPath otherPath = this.toLinkPath(other);
return PATH_COMPARATOR.compare(this, otherPath);
}
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
} else if (other instanceof LinkFSPath that) {
if (this.fileSystem != that.fileSystem) {
return false;
} else {
boolean hasRealContents = this.hasRealContents();
if (hasRealContents != that.hasRealContents()) {
return false;
} else {
return hasRealContents
? this.pathContents == that.pathContents
: Objects.equals(this.parent, that.parent) && Objects.equals(this.name, that.name);
}
}
} else {
return false;
}
}
private boolean hasRealContents() {
return !isRelativeOrMissing(this.pathContents);
}
@Override
public int hashCode() {
return this.hasRealContents() ? this.pathContents.hashCode() : this.name.hashCode();
}
@Override
public String toString() {
return this.pathToString();
}
private String pathToString() {
if (this.pathString == null) {
StringBuilder builder = new StringBuilder();
if (this.isAbsolute()) {
builder.append("/");
}
Joiner.on("/").appendTo(builder, this.pathToRoot());
this.pathString = builder.toString();
}
return this.pathString;
}
private LinkFSPath toLinkPath(@Nullable Path path) {
if (path == null) {
throw new NullPointerException();
} else if (path instanceof LinkFSPath p && p.fileSystem == this.fileSystem) {
return p;
} else {
throw new ProviderMismatchException();
}
}
public boolean exists() {
return this.hasRealContents();
}
public @Nullable Path getTargetPath() {
return this.pathContents instanceof PathContents.FileContents file ? file.contents() : null;
}
public PathContents.@Nullable DirectoryContents getDirectoryContents() {
return this.pathContents instanceof PathContents.DirectoryContents dir ? dir : null;
}
public BasicFileAttributeView getBasicAttributeView() {
return new BasicFileAttributeView() {
{
Objects.requireNonNull(LinkFSPath.this);
}
@Override
public String name() {
return "basic";
}
@Override
public BasicFileAttributes readAttributes() throws IOException {
return LinkFSPath.this.getBasicAttributes();
}
@Override
public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) {
throw new ReadOnlyFileSystemException();
}
};
}
public BasicFileAttributes getBasicAttributes() throws IOException {
if (this.pathContents instanceof PathContents.DirectoryContents) {
return DummyFileAttributes.DIRECTORY;
} else if (this.pathContents instanceof PathContents.FileContents) {
return DummyFileAttributes.FILE;
} else {
throw new NoSuchFileException(this.pathToString());
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
返回值
- 引用位置: