Fix eclipse warnings
[yangtools.git] / yang / yang-repo-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / YangTextSchemaSource.java
index d21fdcb021aecd36399355f7fda36ec470e7b07d..40a2ae5ccd3cbb640e8d4426cd50ec506cbde823 100644 (file)
@@ -20,7 +20,8 @@ import com.google.common.io.Resources;
 import java.io.File;
 import java.io.InputStream;
 import java.net.URL;
-import java.util.Map.Entry;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.common.Revision;
 
@@ -36,11 +37,11 @@ public abstract class YangTextSchemaSource extends ByteSource implements YangSch
     }
 
     public static @NonNull SourceIdentifier identifierFromFilename(final String name) {
-        checkArgument(name.endsWith(RFC6020_YANG_FILE_EXTENSION), "Filename %s does not end with '%s'",
-            RFC6020_YANG_FILE_EXTENSION, name);
+        checkArgument(name.endsWith(RFC6020_YANG_FILE_EXTENSION), "Filename '%s' does not end with '%s'", name,
+            RFC6020_YANG_FILE_EXTENSION);
 
         final String baseName = name.substring(0, name.length() - RFC6020_YANG_FILE_EXTENSION.length());
-        final Entry<String, String> parsed = parseFilename(baseName);
+        final var parsed = parseFilename(baseName);
         return RevisionSourceIdentifier.create(parsed.getKey(), Revision.ofNullable(parsed.getValue()));
     }
 
@@ -75,27 +76,27 @@ public abstract class YangTextSchemaSource extends ByteSource implements YangSch
      * Create a new YangTextSchemaSource backed by a {@link File} with {@link SourceIdentifier} derived from the file
      * name.
      *
-     * @param file Backing File
+     * @param path Backing path
      * @return A new YangTextSchemaSource
      * @throws IllegalArgumentException if the file name has invalid format or if the supplied File is not a file
      * @throws NullPointerException if file is {@code null}
      */
-    public static @NonNull YangTextSchemaSource forFile(final File file) {
-        return forFile(file, identifierFromFilename(file.getName()));
+    public static @NonNull YangTextSchemaSource forPath(final Path path) {
+        return forPath(path, identifierFromFilename(path.toFile().getName()));
     }
 
     /**
      * Create a new YangTextSchemaSource backed by a {@link File} and specified {@link SourceIdentifier}.
      *
-     * @param file Backing File
+     * @param path Backing path
      * @param identifier source identifier
      * @return A new YangTextSchemaSource
-     * @throws IllegalArgumentException if the file name has invalid format or if the supplied File is not a file
      * @throws NullPointerException if any argument is {@code null}
+     * @throws IllegalArgumentException if the supplied path is not a regular file
      */
-    public static @NonNull YangTextSchemaSource forFile(final File file, final SourceIdentifier identifier) {
-        checkArgument(file.isFile(), "Supplied file %s is not a file", file);
-        return new YangTextFileSchemaSource(identifier, file);
+    public static @NonNull YangTextSchemaSource forPath(final Path path, final SourceIdentifier identifier) {
+        checkArgument(Files.isRegularFile(path), "Supplied path %s is not a regular file", path);
+        return new YangTextFileSchemaSource(identifier, path);
     }
 
     /**
@@ -126,6 +127,18 @@ public abstract class YangTextSchemaSource extends ByteSource implements YangSch
         return new ResourceYangTextSchemaSource(identifier, url);
     }
 
+    /**
+     * Create a new {@link YangTextSchemaSource} backed by a URL.
+     *
+     * @param url Backing URL
+     * @param identifier Source identifier
+     * @return A new instance.
+     * @throws NullPointerException if any argument is {@code null}
+     */
+    public static @NonNull YangTextSchemaSource forURL(final URL url, final SourceIdentifier identifier) {
+        return new ResourceYangTextSchemaSource(identifier, url);
+    }
+
     @Override
     public final SourceIdentifier getIdentifier() {
         return identifier;