Simplify guessJsonFromFileName() 33/83933/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 23 Aug 2019 13:25:21 +0000 (15:25 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 23 Aug 2019 13:28:57 +0000 (15:28 +0200)
46 here means '.', so the logic is:
- if there is no '.', return false
- if there is, return true IFF the string after the last '.' equals
  to ".json" in whatever case combination

Change-Id: Idbd7716a7c37ba8e428a2ecaf60031d32a3adbab
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/LibraryModulesSchemas.java

index 60592d7d7cc0b096f930fa21fe4449da8c93c4ea..b195d8e1f450f4da339d9566ea70c4ee1b6f0f87 100644 (file)
@@ -32,7 +32,6 @@ import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.util.AbstractMap;
 import java.util.HashMap;
-import java.util.Locale;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
@@ -289,13 +288,8 @@ public final class LibraryModulesSchemas implements NetconfDeviceSchemas {
     }
 
     private static boolean guessJsonFromFileName(final String fileName) {
-        String extension = "";
-        final int i = fileName.lastIndexOf(46);
-        if (i != -1) {
-            extension = fileName.substring(i).toLowerCase(Locale.ROOT);
-        }
-
-        return extension.equals(".json");
+        final int i = fileName.lastIndexOf('.');
+        return i != 1 && ".json".equalsIgnoreCase(fileName.substring(i));
     }
 
     private static Optional<NormalizedNode<?, ?>> readJson(final InputStream in) {