jtulach commented on code in PR #9820:
URL: https://github.com/apache/netbeans/pull/9820#discussion_r4659708482


##########
platform/openide.filesystems/src/org/openide/filesystems/NioPathForFileObject.java:
##########
@@ -0,0 +1,366 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.openide.filesystems;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.InvalidPathException;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.nio.file.WatchEvent;
+import java.nio.file.WatchKey;
+import java.nio.file.WatchService;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
+
+final class NioPathForFileObject implements Path {
+    private final FileObject fileObject;
+    private final NioFsForFileSystem fileSystem;
+    private final String name;
+    private final boolean absolute;
+
+    private NioPathForFileObject(FileObject fileObject, NioFsForFileSystem 
fileSystem, String name) {
+        this(fileObject, fileSystem, name, true);
+    }
+
+    private NioPathForFileObject(FileObject fileObject, NioFsForFileSystem 
fileSystem, String name, boolean absolute) {
+        this.fileObject = fileObject;
+        this.fileSystem = fileSystem;
+        this.name = normalize(name);
+        this.absolute = absolute;
+    }
+
+    static NioPathForFileObject create(FileObject fileObject, 
NioFsForFileSystem fileSystem) {
+        return new NioPathForFileObject(fileObject, fileSystem, 
fullName(fileObject));
+    }
+
+    static NioPathForFileObject create(FileObject fileObject, 
NioFsForFileSystem fileSystem, String name) {
+        return new NioPathForFileObject(fileObject, fileSystem, name);
+    }
+
+    static NioPathForFileObject relative(FileObject fileObject, 
NioFsForFileSystem fileSystem, String name) {
+        return new NioPathForFileObject(fileObject, fileSystem, name, false);
+    }
+
+    FileObject getFileObject() {
+        return fileObject;
+    }
+
+    @Override
+    public java.nio.file.FileSystem getFileSystem() {
+        return fileSystem;
+    }
+
+    @Override
+    public boolean isAbsolute() {
+        return absolute;
+    }
+
+    @Override
+    public Path getRoot() {
+        return create(fileSystem.getFileSystem().getRoot(), fileSystem);
+    }
+
+    @Override
+    public Path getFileName() {
+        if (name.isEmpty()) {
+            return null;
+        }
+        int separator = name.lastIndexOf('/');
+        String fileName = separator == -1 ? name : name.substring(separator + 
1);
+        return fileName.isEmpty() ? null : relative(fileObject, fileSystem, 
fileName);
+    }
+
+    @Override
+    public Path getParent() {
+        if (name.isEmpty()) {
+            return null;
+        }
+        int separator = name.lastIndexOf('/');
+        if (separator == -1) {
+            return getRoot();
+        }
+        String parentName = name.substring(0, separator);
+        FileObject parent = 
fileSystem.getFileSystem().findResource(parentName);
+        if (parent == null && fileObject != null) {
+            parent = fileObject.getParent();
+        }
+        return create(parent, fileSystem, parentName);
+    }
+
+    @Override
+    public int getNameCount() {
+        if (name.isEmpty()) {
+            return 1;
+        }
+        int count = 0;
+        for (String part : name.split("/")) {
+            if (!part.isEmpty()) {
+                count++;
+            }
+        }
+        return count;
+    }
+
+    @Override
+    public Path getName(int index) {
+        if (index < 0 || index >= getNameCount()) {
+            throw new IllegalArgumentException("Illegal name index: " + index);
+        }
+        List<String> names = names();
+        return relative(null, fileSystem, names.get(index));
+    }
+
+    @Override
+    public Path subpath(int beginIndex, int endIndex) {
+        if (beginIndex < 0 || endIndex > getNameCount() || beginIndex >= 
endIndex) {
+            throw new IllegalArgumentException();
+        }
+        List<String> names = names();
+        return relative(null, fileSystem, String.join("/", 
names.subList(beginIndex, endIndex)));
+    }
+
+    @Override
+    public boolean startsWith(Path other) {
+        if (!(other instanceof NioPathForFileObject nio) || nio.fileSystem != 
fileSystem) {
+            return false;
+        }
+        if (nio.name.isEmpty()) {
+            return absolute;
+        }
+        return name.equals(nio.name) || name.startsWith(nio.name + "/");
+    }
+
+    @Override
+    public boolean startsWith(String other) {
+        return startsWith(fileSystem.getPath(other));
+    }
+
+    @Override
+    public boolean endsWith(Path other) {
+        if (!(other instanceof NioPathForFileObject nio) || nio.fileSystem != 
fileSystem) {
+            return false;
+        }
+        return name.equals(nio.name) || name.endsWith("/" + nio.name) || 
name.endsWith(nio.name);

Review Comment:
   This one shall be fixed by 79653362e4



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to