Files2 { @Nullable public static File getAbsoluteFile(@NonNull File[] paths, @NonNull File file) { if (file.isAbsolute()) { return file; } for (File parent : paths) { File result = new File(parent, file.getPath()); if (result.exists()) { return result; } } return null; } private  Files2(); static File fromPath(String parent, String... path); @Deprecated static boolean isValidPath(File file); @Nullable static File getAbsoluteFile(@NonNull File[] paths, @NonNull File file); @Nullable static File getRelativeFile(@NonNull File[] paths, @NonNull File file); static boolean acceptByLowerCaseExtension(File pathname, String... lowerCaseExtensions); @Nullable static File extractFile(@NonNull String path);  }
@Test public void testGetAbsoluteFile() { assertEquals(ABSOLUTE_INSIDE, Files2.getAbsoluteFile(PATHS, RELATIVE_INSIDE)); assertNotSame(ABSOLUTE_INSIDE, Files2.getAbsoluteFile(PATHS, RELATIVE_INSIDE)); assertTrue(Files2.getAbsoluteFile(PATHS, RELATIVE_INSIDE).isAbsolute()); assertEquals(ABSOLUTE_DIR_INSIDE, Files2.getAbsoluteFile(PATHS, RELATIVE_DIR_INSIDE)); assertNotSame(ABSOLUTE_DIR_INSIDE, Files2.getAbsoluteFile(PATHS, RELATIVE_DIR_INSIDE)); assertTrue(Files2.getAbsoluteFile(PATHS, RELATIVE_DIR_INSIDE).isAbsolute()); assertEquals(ABSOLUTE_INSIDE, Files2.getAbsoluteFile(PATHS, ABSOLUTE_INSIDE)); assertSame(ABSOLUTE_INSIDE, Files2.getAbsoluteFile(PATHS, ABSOLUTE_INSIDE)); assertTrue(Files2.getAbsoluteFile(PATHS, ABSOLUTE_INSIDE).isAbsolute()); assertEquals(ABSOLUTE_DIR_INSIDE, Files2.getAbsoluteFile(PATHS, ABSOLUTE_DIR_INSIDE)); assertSame(ABSOLUTE_DIR_INSIDE, Files2.getAbsoluteFile(PATHS, ABSOLUTE_DIR_INSIDE)); assertTrue(Files2.getAbsoluteFile(PATHS, ABSOLUTE_DIR_INSIDE).isAbsolute()); assertNotEquals(ABSOLUTE_OUTSIDE, Files2.getAbsoluteFile(PATHS, RELATIVE_OUTSIDE)); assertNotSame(ABSOLUTE_OUTSIDE, Files2.getAbsoluteFile(PATHS, RELATIVE_OUTSIDE)); assertNull(Files2.getAbsoluteFile(PATHS, RELATIVE_OUTSIDE)); assertEquals(ABSOLUTE_OUTSIDE, Files2.getAbsoluteFile(PATHS, ABSOLUTE_OUTSIDE)); assertSame(ABSOLUTE_OUTSIDE, Files2.getAbsoluteFile(PATHS, ABSOLUTE_OUTSIDE)); assertTrue(Files2.getAbsoluteFile(PATHS, ABSOLUTE_OUTSIDE).isAbsolute()); }