-
-
Save V-ed/ffa57aec6bf646d2749a03a01c21d265 to your computer and use it in GitHub Desktop.
Test code for langAmount handling
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
public static class LangAmount{ | |
public int countMin; | |
public int countMax; | |
public String message; | |
public LangAmount(String messySubLine){ | |
this(messySubLine, -1); | |
} | |
public LangAmount(String messySubLine, int prevMax){ | |
String countString = messySubLine.replaceFirst("^\\[(.+)\\].+$", "$1"); | |
String messageString = messySubLine.replaceFirst("^\\[.+\\]\\s*(.+)$", "$1"); | |
String[] counts = countString.split(","); | |
if(counts.length == 1){ | |
this.countMin = Integer.parseInt(counts[0]); | |
this.countMax = this.countMin; | |
} | |
else{ | |
this.countMin = counts[0].equals("*") ? 0 : Integer.parseInt(counts[0]); | |
this.countMax = counts[1].equals("*") ? Integer.MAX_VALUE : Integer.parseInt(counts[1]); | |
} | |
this.message = messageString; | |
System.out.println(prevMax); | |
} | |
public LangAmount(int countMin, int countMax, String message){ | |
this.countMin = countMin; | |
this.countMax = countMax; | |
this.message = message; | |
} | |
public LangAmount(int countMin, char countMax, String message){ | |
this(countMin, countMax == '*' ? Integer.MAX_VALUE : Character.getNumericValue(countMax), message); | |
} | |
@Override | |
public String toString(){ | |
return "[min: " + countMin + ", max: " + countMax + ", message: \"" + message + "\"]"; | |
} | |
} | |
public static void main(String []args){ | |
String testString = "[0] string1 | [1,10] string2 | [11,*] string3"; | |
testLangAmountString(testString); | |
} | |
public static void testLangAmountString(String testString){ | |
String[] array = testString.split("\\s*[^\\\\]\\|\\s*"); | |
String countMatcher = "^\\[[0-9]+(,([0-9]+|*))?\\]\\s?.+$"; | |
ArrayList<LangAmount> langList = new ArrayList<>(); | |
if(array.length == 2){ | |
if(!array[0].matches(countMatcher) && !array[1].matches(countMatcher)){ | |
langList.add(new LangAmount(1, 1, array[0])); | |
langList.add(new LangAmount(2, '*', array[0])); | |
} | |
} | |
if(langList.isEmpty()){ | |
for(String val : array){ | |
if(langList.isEmpty()){ | |
langList.add(new LangAmount(val)); | |
} | |
else{ | |
langList.add(new LangAmount(val, langList.get(langList.size() - 1).countMax)); | |
} | |
} | |
} | |
for(LangAmount langs : langList){ | |
System.out.println(langs); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment