mirror of
https://github.com/RayzsYT/ProAntiTab.git
synced 2026-11-30 20:39:53 -05:00
Add Methods
This commit is contained in:
1 parent
f385708cb0
commit
3ae668af80
1 file changed
+54
-2
@@ -1,5 +1,13 @@
|
||||
package de.rayzs.pat.utils;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
public static String replaceFirst(String input, String trigger, String replacement) {
|
||||
@@ -14,10 +22,10 @@ public class StringUtils {
|
||||
return input;
|
||||
}
|
||||
|
||||
public static String replace(String input, String... triggers) {
|
||||
public static String replace(String input, String replacement, String... triggers) {
|
||||
for (String trigger : triggers) {
|
||||
if(!input.contains(trigger)) continue;
|
||||
input = input.replace(trigger, "");
|
||||
input = input.replace(trigger, replacement);
|
||||
}
|
||||
|
||||
return input;
|
||||
@@ -31,4 +39,48 @@ public class StringUtils {
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
public static String replace(String input, String... replacements) {
|
||||
final HashMap<String, String> REPLACEMENTS = new HashMap<>();
|
||||
|
||||
if(replacements != null) {
|
||||
String firstReplacementInput = null, secondReplacementInput = null;
|
||||
for (String replacement : replacements) {
|
||||
if (firstReplacementInput == null) firstReplacementInput = replacement;
|
||||
else secondReplacementInput = replacement;
|
||||
|
||||
if (firstReplacementInput != null && secondReplacementInput != null) {
|
||||
REPLACEMENTS.put(firstReplacementInput, secondReplacementInput);
|
||||
firstReplacementInput = null;
|
||||
secondReplacementInput = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String text = input;
|
||||
if(replacements != null)
|
||||
for (Map.Entry<String, String> entry : REPLACEMENTS.entrySet())
|
||||
text = text.replace(entry.getKey(), entry.getValue());
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
public static String buildSortedStringList(List<String> list, String splitter, String format, String placeholder, boolean reversed) {
|
||||
Collections.sort(list);
|
||||
if(reversed) Collections.reverse(list);
|
||||
return buildStringList(list, splitter, format, placeholder);
|
||||
}
|
||||
|
||||
public static String buildStringList(List<String> list, String splitter, String format, String placeholder) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
boolean end;
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
end = i >= list.size() - 1;
|
||||
builder.append(format.replace(placeholder, list.get(i)));
|
||||
if (!end && splitter != null) builder.append(splitter);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user