@Test public void testGetNNFilePaths_ignoringUpperCase() throws Exception { final String[] alternativeNetDirNamesWithUpperCase = new String[]{ "rtosa_aaNN", "rtosa_rw", "rw_iop", "iop_rw", "rw_kd", "iop_unCIop", "iop_uncsumiop_unckd", "rw_rwNORM", "rtosa_trans", "rtosa_rpath" }; for (int i = 0; i < 10; i++) { final Path nnDir = testDir.resolve(alternativeNetDirNamesWithUpperCase[i]); Files.createDirectories(nnDir); final Path nnfile = nnDir.resolve("nnFile_" + i + ".net"); Files.createFile(nnfile); } final String[] nnFilePaths = NNUtils.getNNFilePaths(testDir, NNUtils.ALTERNATIVE_NET_DIR_NAMES); assertNotNull(nnFilePaths); assertEquals(10, nnFilePaths.length); for (int i = 0; i < NNUtils.ALTERNATIVE_NET_DIR_NAMES.length; i++) { String nameWithUpperCase = alternativeNetDirNamesWithUpperCase[i]; assertTrue(nnFilePaths[i].contains(sep + nameWithUpperCase + sep)); } }
public static String[] getNNFilePaths(Path nnRootPath, String[] alternativeNetDirNames) throws IOException { final ArrayList<String> pathsList = new ArrayList<>(); final String prefix = "The path '" + nnRootPath.toString() + "' "; if (!Files.isDirectory(nnRootPath)) { throw new OperatorException(prefix + "for alternative neuronal nets is not a valid path"); } final HashSet<String> dirNames = new HashSet<>(); Files.newDirectoryStream(nnRootPath).forEach(path -> { if (Files.isDirectory(path)) { dirNames.add(path.getFileName().toString()); } }); for (String alternativeNetDirName : alternativeNetDirNames) { if (!containsIgnoreCase(dirNames, alternativeNetDirName)) { throw new OperatorException(prefix + "does not contain the expected sub directory '" + alternativeNetDirName + "'"); } String dirName = getIgnoreCase(dirNames, alternativeNetDirName); final int[] dotNetFilesCount = {0}; final Path nnDirPath = nnRootPath.resolve(dirName); Files.newDirectoryStream(nnDirPath).forEach(path -> { if (path.getFileName().toString().toLowerCase().endsWith(".net") && Files.isRegularFile(path)) { dotNetFilesCount[0]++; pathsList.add(path.toString()); } }); int count = dotNetFilesCount[0]; if (count != 1) { throw new OperatorException("The path '" + nnDirPath + " must contain exact 1 file with file ending '*.net', but contains " + count); } } return pathsList.toArray(new String[pathsList.size()]); }
NNUtils { public static String[] getNNFilePaths(Path nnRootPath, String[] alternativeNetDirNames) throws IOException { final ArrayList<String> pathsList = new ArrayList<>(); final String prefix = "The path '" + nnRootPath.toString() + "' "; if (!Files.isDirectory(nnRootPath)) { throw new OperatorException(prefix + "for alternative neuronal nets is not a valid path"); } final HashSet<String> dirNames = new HashSet<>(); Files.newDirectoryStream(nnRootPath).forEach(path -> { if (Files.isDirectory(path)) { dirNames.add(path.getFileName().toString()); } }); for (String alternativeNetDirName : alternativeNetDirNames) { if (!containsIgnoreCase(dirNames, alternativeNetDirName)) { throw new OperatorException(prefix + "does not contain the expected sub directory '" + alternativeNetDirName + "'"); } String dirName = getIgnoreCase(dirNames, alternativeNetDirName); final int[] dotNetFilesCount = {0}; final Path nnDirPath = nnRootPath.resolve(dirName); Files.newDirectoryStream(nnDirPath).forEach(path -> { if (path.getFileName().toString().toLowerCase().endsWith(".net") && Files.isRegularFile(path)) { dotNetFilesCount[0]++; pathsList.add(path.toString()); } }); int count = dotNetFilesCount[0]; if (count != 1) { throw new OperatorException("The path '" + nnDirPath + " must contain exact 1 file with file ending '*.net', but contains " + count); } } return pathsList.toArray(new String[pathsList.size()]); } }
NNUtils { public static String[] getNNFilePaths(Path nnRootPath, String[] alternativeNetDirNames) throws IOException { final ArrayList<String> pathsList = new ArrayList<>(); final String prefix = "The path '" + nnRootPath.toString() + "' "; if (!Files.isDirectory(nnRootPath)) { throw new OperatorException(prefix + "for alternative neuronal nets is not a valid path"); } final HashSet<String> dirNames = new HashSet<>(); Files.newDirectoryStream(nnRootPath).forEach(path -> { if (Files.isDirectory(path)) { dirNames.add(path.getFileName().toString()); } }); for (String alternativeNetDirName : alternativeNetDirNames) { if (!containsIgnoreCase(dirNames, alternativeNetDirName)) { throw new OperatorException(prefix + "does not contain the expected sub directory '" + alternativeNetDirName + "'"); } String dirName = getIgnoreCase(dirNames, alternativeNetDirName); final int[] dotNetFilesCount = {0}; final Path nnDirPath = nnRootPath.resolve(dirName); Files.newDirectoryStream(nnDirPath).forEach(path -> { if (path.getFileName().toString().toLowerCase().endsWith(".net") && Files.isRegularFile(path)) { dotNetFilesCount[0]++; pathsList.add(path.toString()); } }); int count = dotNetFilesCount[0]; if (count != 1) { throw new OperatorException("The path '" + nnDirPath + " must contain exact 1 file with file ending '*.net', but contains " + count); } } return pathsList.toArray(new String[pathsList.size()]); }  }
NNUtils { public static String[] getNNFilePaths(Path nnRootPath, String[] alternativeNetDirNames) throws IOException { final ArrayList<String> pathsList = new ArrayList<>(); final String prefix = "The path '" + nnRootPath.toString() + "' "; if (!Files.isDirectory(nnRootPath)) { throw new OperatorException(prefix + "for alternative neuronal nets is not a valid path"); } final HashSet<String> dirNames = new HashSet<>(); Files.newDirectoryStream(nnRootPath).forEach(path -> { if (Files.isDirectory(path)) { dirNames.add(path.getFileName().toString()); } }); for (String alternativeNetDirName : alternativeNetDirNames) { if (!containsIgnoreCase(dirNames, alternativeNetDirName)) { throw new OperatorException(prefix + "does not contain the expected sub directory '" + alternativeNetDirName + "'"); } String dirName = getIgnoreCase(dirNames, alternativeNetDirName); final int[] dotNetFilesCount = {0}; final Path nnDirPath = nnRootPath.resolve(dirName); Files.newDirectoryStream(nnDirPath).forEach(path -> { if (path.getFileName().toString().toLowerCase().endsWith(".net") && Files.isRegularFile(path)) { dotNetFilesCount[0]++; pathsList.add(path.toString()); } }); int count = dotNetFilesCount[0]; if (count != 1) { throw new OperatorException("The path '" + nnDirPath + " must contain exact 1 file with file ending '*.net', but contains " + count); } } return pathsList.toArray(new String[pathsList.size()]); }  static String[] getNNFilePaths(Path nnRootPath, String[] alternativeNetDirNames); }
NNUtils { public static String[] getNNFilePaths(Path nnRootPath, String[] alternativeNetDirNames) throws IOException { final ArrayList<String> pathsList = new ArrayList<>(); final String prefix = "The path '" + nnRootPath.toString() + "' "; if (!Files.isDirectory(nnRootPath)) { throw new OperatorException(prefix + "for alternative neuronal nets is not a valid path"); } final HashSet<String> dirNames = new HashSet<>(); Files.newDirectoryStream(nnRootPath).forEach(path -> { if (Files.isDirectory(path)) { dirNames.add(path.getFileName().toString()); } }); for (String alternativeNetDirName : alternativeNetDirNames) { if (!containsIgnoreCase(dirNames, alternativeNetDirName)) { throw new OperatorException(prefix + "does not contain the expected sub directory '" + alternativeNetDirName + "'"); } String dirName = getIgnoreCase(dirNames, alternativeNetDirName); final int[] dotNetFilesCount = {0}; final Path nnDirPath = nnRootPath.resolve(dirName); Files.newDirectoryStream(nnDirPath).forEach(path -> { if (path.getFileName().toString().toLowerCase().endsWith(".net") && Files.isRegularFile(path)) { dotNetFilesCount[0]++; pathsList.add(path.toString()); } }); int count = dotNetFilesCount[0]; if (count != 1) { throw new OperatorException("The path '" + nnDirPath + " must contain exact 1 file with file ending '*.net', but contains " + count); } } return pathsList.toArray(new String[pathsList.size()]); }  static String[] getNNFilePaths(Path nnRootPath, String[] alternativeNetDirNames); static final String[] ALTERNATIVE_NET_DIR_NAMES; }