forked from devonfw/IDEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'devonfw#420-create-win-installer' of https://github.com…
…/alfeilex/IDEasy into devonfw#420-create-win-installer
- Loading branch information
Showing
17 changed files
with
320 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
cli/src/main/java/com/devonfw/tools/ide/common/SimpleSystemPath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.devonfw.tools.ide.common; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Represents the PATH variable in a structured way. Similar to {@link SystemPath} but much simper: It just tokenizes the PATH into a {@link java.util.List} of | ||
* {@link String}s. | ||
*/ | ||
public class SimpleSystemPath { | ||
|
||
private final char separator; | ||
|
||
private final List<String> entries; | ||
|
||
private SimpleSystemPath(char separator, List<String> entries) { | ||
|
||
super(); | ||
this.separator = separator; | ||
this.entries = entries; | ||
} | ||
|
||
/** | ||
* @return the entries of this PATH as a mutable {@link List}. | ||
*/ | ||
public List<String> getEntries() { | ||
|
||
return this.entries; | ||
} | ||
|
||
/** | ||
* Remove all entries from this PATH that match the given {@link Predicate}. | ||
* | ||
* @param filter the {@link Predicate} {@link Predicate#test(Object) deciding} what to filter and remove. | ||
*/ | ||
public void removeEntries(Predicate<String> filter) { | ||
|
||
Iterator<String> iterator = this.entries.iterator(); | ||
while (iterator.hasNext()) { | ||
String entry = iterator.next(); | ||
if (filter.test(entry)) { | ||
iterator.remove(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
boolean first = true; | ||
for (String entry : this.entries) { | ||
if (first) { | ||
first = false; | ||
} else { | ||
sb.append(this.separator); | ||
} | ||
sb.append(entry); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
/** | ||
* @param path the entire PATH as {@link String}, | ||
* @param separator the separator character. | ||
* @return the {@link SimpleSystemPath}. | ||
*/ | ||
public static SimpleSystemPath of(String path, char separator) { | ||
|
||
List<String> entries = new ArrayList<>(); | ||
int start = 0; | ||
int len = path.length(); | ||
while (start < len) { | ||
int end = path.indexOf(separator, start); | ||
if (end < 0) { | ||
end = len; | ||
} | ||
entries.add(path.substring(start, end)); | ||
start = end + 1; | ||
} | ||
return new SimpleSystemPath(separator, entries); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.