@Test public void testSplitPath() { String[][] samples = { {"path/to/file", "path", "to", "file"}, {"/path/to/file", "", "path", "to", "file"}, {"path/to/file/", "path", "to", "file"}, {"/path/to/file/", "", "path", "to", "file"}, {"/", ""}, {" {"", ""}, }; for (String[] sample : samples) { List<String> expected = new ArrayList<String> (); for (int i = 1; i < sample.length; i++) expected.add(sample[i]); List<String> actual = Util.splitPath(sample[0]); if (expected.size() != 0 && actual.size() != 0) assertEquals(expected, actual); } }
@MutableCopy @NotNull public static List<String> splitPath(@NotNull String path) { List<String> parts = new ArrayList<String>(); int lastStart = 0; for (int i = 0; i < path.length(); i++) { char c = path.charAt(i); if (c == '/' || c == '\\') { parts.add(path.substring(lastStart, i)); lastStart = i + 1; } } if (lastStart < path.length()) parts.add(path.substring(lastStart)); return parts; }
Util { @MutableCopy @NotNull public static List<String> splitPath(@NotNull String path) { List<String> parts = new ArrayList<String>(); int lastStart = 0; for (int i = 0; i < path.length(); i++) { char c = path.charAt(i); if (c == '/' || c == '\\') { parts.add(path.substring(lastStart, i)); lastStart = i + 1; } } if (lastStart < path.length()) parts.add(path.substring(lastStart)); return parts; } }
Util { @MutableCopy @NotNull public static List<String> splitPath(@NotNull String path) { List<String> parts = new ArrayList<String>(); int lastStart = 0; for (int i = 0; i < path.length(); i++) { char c = path.charAt(i); if (c == '/' || c == '\\') { parts.add(path.substring(lastStart, i)); lastStart = i + 1; } } if (lastStart < path.length()) parts.add(path.substring(lastStart)); return parts; } private  Util(); }
Util { @MutableCopy @NotNull public static List<String> splitPath(@NotNull String path) { List<String> parts = new ArrayList<String>(); int lastStart = 0; for (int i = 0; i < path.length(); i++) { char c = path.charAt(i); if (c == '/' || c == '\\') { parts.add(path.substring(lastStart, i)); lastStart = i + 1; } } if (lastStart < path.length()) parts.add(path.substring(lastStart)); return parts; } private  Util(); static int[] toIntArray(String str, int[] defaultValues); static int toInt(String value, int defaultValue); @NotNull static String encodeStrings(	@NotNull String sep,
										@NotNull Collection<String> parts); @MutableCopy @NotNull static List<String> decodeStrings(char sep, @NotNull String str); @NotNull static String truncate(@NotNull String str); @NotNull static String trimLeft(@NotNull String input); @NotNull static String trimRight(@NotNull String input); static boolean equals(@NotNull Collection<T> col, @NotNull T[] a); static String ensureLinuxLineSep(@NotNull String input); static String ensureWindowsLineSep(@NotNull String input); static void setCenteredBounds(	@NotNull Shell shell,
											int width,
											int height); static void setCenteredBounds(@NotNull Shell shell); static void setCenteredBounds(	@NotNull Shell shell,
											@NotNull Control control); static void setCenteredMinBounds(@NotNull Shell shell,
											int minWidth,
											int minHeight); @NotNull static Button[] maybeSwapButtons(@NotNull Button b1,
											@NotNull Button b2); static boolean contains(int bit1, int bit2); static FillLayout createFillLayout(int margin); static GridLayout createGridLayout(int numColumns, boolean makeColumsEqualWidth, int margin, int spacing); static FormLayout createFormLayout(int margin); @NotNull static Text createLabeledGridText(	@NotNull Composite parent,
												@NotNull String labelText); @NotNull static Text createUnlabeledGridText(	@NotNull Composite parent); @NotNull static StyledText createLabeledGridStyledText(	@NotNull Composite parent,
															@NotNull String labelText); @NotNull static Button createCheckButton(	@NotNull Composite parent,
											@NotNull String label); @NotNull static Button createPushButton(	@NotNull Composite parent,
											@NotNull String label,
											@NotNull SelectionListener listener); @NotNull static Button createPushButton(	@NotNull Composite parent,
											@Nullable Image image,
											@Nullable String toolTip,
											@NotNull SelectionListener listener); @NotNull static Color getTextForeground(@NotNull Color background); @MutableCopy @NotNull static List<String> splitPath(@NotNull String path); @NotNull static String joinPath(	@NotNull String first,
									@NotNull String second,
									@NotNull String... more); @NotNull static String joinPath(@NotNull Iterable<?> parts); @NotNull static String join(@NotNull String separator, @NotNull Object... parts); @NotNull static String join(@NotNull String separator, @NotNull Iterable<?> parts); @NotNull static String getAbsPath(@NotNull File file); static boolean isUncPath(@NotNull File file); @NotNull static String getAbsPath(@NotNull String path); @NotNull static File getAbsFile(@NotNull File file); @NotNull static String getSystemAbsPath(@NotNull File file); @NotNull static String getSystemAbsPath(@NotNull String path); @NotNull static File getCanonicalFile(@NotNull String path); @NotNull static File getCanonicalFile(@NotNull File file); @NotNull static String getCanonicalPath(@NotNull File file); static boolean isCanonicallyEqual(	@Nullable File file1,
												@Nullable File file2); @NotNull static File[] listFiles(@NotNull File dir); @NotNull static File[] listFiles(	@NotNull File dir,
									@Nullable FilenameFilter filter); @NotNull static File[] listFiles(	@NotNull File dir,
									@Nullable FileFilter filter); static boolean isSymLink(@NotNull File file); static boolean isJunctionOrSymlink(@NotNull File file); @NotNull static File getParentFile(@NotNull File file); @NotNull static String toForwardSlashes(@NotNull String path); @NotNull static File getParentFile(@NotNull String path); static boolean containsEquality(	@Nullable Object[] objects,
											@Nullable Object object); static String[] splitFilename(@NotNull File file); @NotNull static String[] splitFilename(@NotNull String filename); @NotNull static String getExtension(@NotNull String filename); @NotNull static String getExtension(@NotNull File file); static boolean hasExtension(	@NotNull String filename,
										@NotNull String... extensions); static boolean hasExtension(@NotNull String filename,
	                                   @NotNull Collection<String> extensions); static void deleteContents(@NotNull File directory); static void deleteRecursively(@NotNull File file); @NotNull static String getNameOrLetter(	@NotNull File file,
											@NotNull String letterSuffix); @Nullable static String getDriveLetter(@NotNull String path); static boolean isWindowsDevice(@NotNull String path); static void assertSwtThread(); static void checkThat(boolean condition); static void checkThat(boolean condition, @NotNull String message); static T checkNotNull(T a); static void checkNotNull(Object a, Object b); static void checkNotNull(Object a, Object b, Object c); static void checkNotNull(Object a, Object b, Object c, Object d); static void checkNotNull(Object a, Object b, Object c, Object d, Object e); @NotNull static String notNull(@Nullable String string); @ThreadSafe static synchronized long getTimestamp(); static boolean contains(	@NotNull File dir,
									@NotNull File fileOrDir); static boolean contains(	@NotNull String dirPath,
									@NotNull String fileOrDirPath); @Nullable static T getLast(@Nullable List<T> list); @MutableCopy @NotNull static List<T> createList(	int extraCapacity,
											@NotNull T... elements); @MutableCopy @NotNull static List<T> createList(	@NotNull Collection<? extends T> col,
											@NotNull T... elements); @MutableCopy @NotNull static List<T> createListReversed(	@NotNull Collection<? extends T> col,
													@NotNull T... elements); @NotNull static List<T> createEmptyList(@NotNull Collection<?>... cols); static boolean runSwtSafe(	@Nullable final Widget widget,
										@NotNull final Runnable runnable); static boolean runSwtSafe(	@Nullable final Display display,
										@NotNull final Runnable runnable); static boolean runSyncExec(	@Nullable final Widget widget,
										@NotNull final Runnable runnable); static boolean runSyncExec(	@Nullable final Display display,
										@NotNull final Runnable runnable); static void runAsyncExec(@Nullable final Widget widget,
									@NotNull final Runnable runnable); static void runAsyncExec(@Nullable final Display display,
									@NotNull final Runnable runnable); static boolean launch(@NotNull String filename); static boolean launch(@NotNull File fileOrDir); @NotNull static File createTempDir(); static File createTempFile(	@NotNull String prefix,
										@Nullable String suffix); static File createTempFile(	@NotNull String prefix,
										@Nullable String suffix,
										@Nullable File directory); @NotNull static File createDerivedTempFile(	@NotNull String filename,
												@NotNull File tempDir); static void println(@NotNull Object... objects); static void printErr(@NotNull String message); static void printErr(@NotNull Throwable t); @NotNull static String getLowestMessage(@Nullable Throwable throwable); static void selectAllOnFocus(@NotNull final Control text); static void registerSelectAllKey(@NotNull final StyledText st); static void selectAll(@NotNull Combo combo); static int clamp(int value, int minimum, int maximum); static boolean isInterrupted(); @Nullable static List<File> getFilesFromClipboard(); static void setClipboard(@NotNull String text); static void setClipboard(@NotNull Collection<File> files); static void addMouseHighlighter(@NotNull final Control control); static boolean isEnterKey(int keyCode); static boolean isSpecialStateMask(int stateMask); static boolean isAlphaNumeric(int keyCode); static boolean isTypeAheadAccept(char character); static void disposeWith(	@NotNull Widget widget,
									@NotNull final Resource... resources); static boolean winOpenDir(String fileName); static String getDefaultIndexName(File rootFile); }
Util { @MutableCopy @NotNull public static List<String> splitPath(@NotNull String path) { List<String> parts = new ArrayList<String>(); int lastStart = 0; for (int i = 0; i < path.length(); i++) { char c = path.charAt(i); if (c == '/' || c == '\\') { parts.add(path.substring(lastStart, i)); lastStart = i + 1; } } if (lastStart < path.length()) parts.add(path.substring(lastStart)); return parts; } private  Util(); static int[] toIntArray(String str, int[] defaultValues); static int toInt(String value, int defaultValue); @NotNull static String encodeStrings(	@NotNull String sep,
										@NotNull Collection<String> parts); @MutableCopy @NotNull static List<String> decodeStrings(char sep, @NotNull String str); @NotNull static String truncate(@NotNull String str); @NotNull static String trimLeft(@NotNull String input); @NotNull static String trimRight(@NotNull String input); static boolean equals(@NotNull Collection<T> col, @NotNull T[] a); static String ensureLinuxLineSep(@NotNull String input); static String ensureWindowsLineSep(@NotNull String input); static void setCenteredBounds(	@NotNull Shell shell,
											int width,
											int height); static void setCenteredBounds(@NotNull Shell shell); static void setCenteredBounds(	@NotNull Shell shell,
											@NotNull Control control); static void setCenteredMinBounds(@NotNull Shell shell,
											int minWidth,
											int minHeight); @NotNull static Button[] maybeSwapButtons(@NotNull Button b1,
											@NotNull Button b2); static boolean contains(int bit1, int bit2); static FillLayout createFillLayout(int margin); static GridLayout createGridLayout(int numColumns, boolean makeColumsEqualWidth, int margin, int spacing); static FormLayout createFormLayout(int margin); @NotNull static Text createLabeledGridText(	@NotNull Composite parent,
												@NotNull String labelText); @NotNull static Text createUnlabeledGridText(	@NotNull Composite parent); @NotNull static StyledText createLabeledGridStyledText(	@NotNull Composite parent,
															@NotNull String labelText); @NotNull static Button createCheckButton(	@NotNull Composite parent,
											@NotNull String label); @NotNull static Button createPushButton(	@NotNull Composite parent,
											@NotNull String label,
											@NotNull SelectionListener listener); @NotNull static Button createPushButton(	@NotNull Composite parent,
											@Nullable Image image,
											@Nullable String toolTip,
											@NotNull SelectionListener listener); @NotNull static Color getTextForeground(@NotNull Color background); @MutableCopy @NotNull static List<String> splitPath(@NotNull String path); @NotNull static String joinPath(	@NotNull String first,
									@NotNull String second,
									@NotNull String... more); @NotNull static String joinPath(@NotNull Iterable<?> parts); @NotNull static String join(@NotNull String separator, @NotNull Object... parts); @NotNull static String join(@NotNull String separator, @NotNull Iterable<?> parts); @NotNull static String getAbsPath(@NotNull File file); static boolean isUncPath(@NotNull File file); @NotNull static String getAbsPath(@NotNull String path); @NotNull static File getAbsFile(@NotNull File file); @NotNull static String getSystemAbsPath(@NotNull File file); @NotNull static String getSystemAbsPath(@NotNull String path); @NotNull static File getCanonicalFile(@NotNull String path); @NotNull static File getCanonicalFile(@NotNull File file); @NotNull static String getCanonicalPath(@NotNull File file); static boolean isCanonicallyEqual(	@Nullable File file1,
												@Nullable File file2); @NotNull static File[] listFiles(@NotNull File dir); @NotNull static File[] listFiles(	@NotNull File dir,
									@Nullable FilenameFilter filter); @NotNull static File[] listFiles(	@NotNull File dir,
									@Nullable FileFilter filter); static boolean isSymLink(@NotNull File file); static boolean isJunctionOrSymlink(@NotNull File file); @NotNull static File getParentFile(@NotNull File file); @NotNull static String toForwardSlashes(@NotNull String path); @NotNull static File getParentFile(@NotNull String path); static boolean containsEquality(	@Nullable Object[] objects,
											@Nullable Object object); static String[] splitFilename(@NotNull File file); @NotNull static String[] splitFilename(@NotNull String filename); @NotNull static String getExtension(@NotNull String filename); @NotNull static String getExtension(@NotNull File file); static boolean hasExtension(	@NotNull String filename,
										@NotNull String... extensions); static boolean hasExtension(@NotNull String filename,
	                                   @NotNull Collection<String> extensions); static void deleteContents(@NotNull File directory); static void deleteRecursively(@NotNull File file); @NotNull static String getNameOrLetter(	@NotNull File file,
											@NotNull String letterSuffix); @Nullable static String getDriveLetter(@NotNull String path); static boolean isWindowsDevice(@NotNull String path); static void assertSwtThread(); static void checkThat(boolean condition); static void checkThat(boolean condition, @NotNull String message); static T checkNotNull(T a); static void checkNotNull(Object a, Object b); static void checkNotNull(Object a, Object b, Object c); static void checkNotNull(Object a, Object b, Object c, Object d); static void checkNotNull(Object a, Object b, Object c, Object d, Object e); @NotNull static String notNull(@Nullable String string); @ThreadSafe static synchronized long getTimestamp(); static boolean contains(	@NotNull File dir,
									@NotNull File fileOrDir); static boolean contains(	@NotNull String dirPath,
									@NotNull String fileOrDirPath); @Nullable static T getLast(@Nullable List<T> list); @MutableCopy @NotNull static List<T> createList(	int extraCapacity,
											@NotNull T... elements); @MutableCopy @NotNull static List<T> createList(	@NotNull Collection<? extends T> col,
											@NotNull T... elements); @MutableCopy @NotNull static List<T> createListReversed(	@NotNull Collection<? extends T> col,
													@NotNull T... elements); @NotNull static List<T> createEmptyList(@NotNull Collection<?>... cols); static boolean runSwtSafe(	@Nullable final Widget widget,
										@NotNull final Runnable runnable); static boolean runSwtSafe(	@Nullable final Display display,
										@NotNull final Runnable runnable); static boolean runSyncExec(	@Nullable final Widget widget,
										@NotNull final Runnable runnable); static boolean runSyncExec(	@Nullable final Display display,
										@NotNull final Runnable runnable); static void runAsyncExec(@Nullable final Widget widget,
									@NotNull final Runnable runnable); static void runAsyncExec(@Nullable final Display display,
									@NotNull final Runnable runnable); static boolean launch(@NotNull String filename); static boolean launch(@NotNull File fileOrDir); @NotNull static File createTempDir(); static File createTempFile(	@NotNull String prefix,
										@Nullable String suffix); static File createTempFile(	@NotNull String prefix,
										@Nullable String suffix,
										@Nullable File directory); @NotNull static File createDerivedTempFile(	@NotNull String filename,
												@NotNull File tempDir); static void println(@NotNull Object... objects); static void printErr(@NotNull String message); static void printErr(@NotNull Throwable t); @NotNull static String getLowestMessage(@Nullable Throwable throwable); static void selectAllOnFocus(@NotNull final Control text); static void registerSelectAllKey(@NotNull final StyledText st); static void selectAll(@NotNull Combo combo); static int clamp(int value, int minimum, int maximum); static boolean isInterrupted(); @Nullable static List<File> getFilesFromClipboard(); static void setClipboard(@NotNull String text); static void setClipboard(@NotNull Collection<File> files); static void addMouseHighlighter(@NotNull final Control control); static boolean isEnterKey(int keyCode); static boolean isSpecialStateMask(int stateMask); static boolean isAlphaNumeric(int keyCode); static boolean isTypeAheadAccept(char character); static void disposeWith(	@NotNull Widget widget,
									@NotNull final Resource... resources); static boolean winOpenDir(String fileName); static String getDefaultIndexName(File rootFile); static final boolean IS_WINDOWS; static final boolean IS_LINUX; static final boolean IS_LINUX_KDE; static final boolean IS_UBUNTU_UNITY; static final boolean IS_MAC_OS_X; static final boolean IS_64_BIT_JVM; static final File TEMP_DIR; static final String USER_DIR_PATH; static final File USER_DIR; static final String USER_HOME_PATH; static final String LS; static final String FS; static final int BTW; static final CharMatcher fileSepMatcher; }