@Override public List<String> read(String string) throws InvalidConfigException { return Arrays.asList(StringHelper.readCommaSeperatedString(string)); }
@Override public double[] read(String string) throws InvalidConfigException { if (string.isEmpty()) { return new double[0]; } String[] split = StringHelper.readCommaSeperatedString(string); double[] values = new double[split.length]; for (int i = 0; i < split.length; i++) { // Trimming the values allows "Value1, Value2" values[i] = StringHelper.readDouble(split[i], -Double.MAX_VALUE, Double.MAX_VALUE); } return values; }
@Override public MaterialSet read(String string) throws InvalidConfigException { MaterialSet blocks = new MaterialSet(); for (String blockName : StringHelper.readCommaSeperatedString(string)) { blocks.parseAndAdd(blockName); } return blocks; }
public static List<WeightedMobSpawnGroup> fromJson(String originalJson) throws InvalidConfigException { // Example: [{"mob": "Sheep", "weight": 12, "min": 4, "max": 4}] List<WeightedMobSpawnGroup> mobGroups = new ArrayList<WeightedMobSpawnGroup>(); String json = originalJson.trim(); if (json.length() <= 2) { // Empty Json return mobGroups; } // Remove the [..] json = removeFirstAndLastChar(json); // Every group is separated by a , but in the group the , is also // used. // So convert the ( to {, the ) to } and use an existing function to // get each group json = json.replace('{', '('); json = json.replace('}', ')'); String[] groups = StringHelper.readCommaSeperatedString(json); for (String group : groups) { mobGroups.add(readSingleGroup(group)); } return mobGroups; }
public ReplacedBlocksMatrix(String setting, int maxHeight) throws InvalidConfigException { this.maxHeight = maxHeight; // Parse if (setting.isEmpty() || setting.equalsIgnoreCase(NO_REPLACE)) { setInstructions(Collections.<ReplacedBlocksInstruction> emptyList()); return; } List<ReplacedBlocksInstruction> instructions = new ArrayList<ReplacedBlocksInstruction>(); String[] keys = StringHelper.readCommaSeperatedString(setting); for (String key : keys) { int start = key.indexOf('('); int end = key.lastIndexOf(')'); if (start != -1 && end != -1) { String keyWithoutBraces = key.substring(start + 1, end); instructions.add(new ReplacedBlocksInstruction(keyWithoutBraces, maxHeight)); } else { throw new InvalidConfigException("One of the parts is missing braces around it."); } } // Set setInstructions(instructions); }
@Override public SurfaceGenerator read(String string) throws InvalidConfigException { if (string.length() > 0) { SurfaceGenerator mesa = MesaSurfaceGenerator.getFor(string); if (mesa != null) { return mesa; } String[] parts = StringHelper.readCommaSeperatedString(string); return new MultipleLayersSurfaceGenerator(parts); } return new SimpleSurfaceGenerator(); }
String functionName = configFunctionString.substring(0, bracketIndex); String parameters = configFunctionString.substring(bracketIndex + 1, configFunctionString.length() - 1); List<String> args = Arrays.asList(StringHelper.readCommaSeperatedString(parameters)); ConfigFunction<T> function = manager.getConfigFunction(functionName, holder, args); if (function == null)
@Test public void testReadCommaSeperatedString() { // Test empty string assertArrayEquals(StringHelper.readCommaSeperatedString(""), new String[0]); // Test simple strings assertArrayEquals(StringHelper.readCommaSeperatedString("a"), new String[] {"a"}); assertArrayEquals(StringHelper.readCommaSeperatedString("a,b,cd"), new String[] {"a", "b", "cd"}); // Test if commas inside braces are ignored assertArrayEquals(StringHelper.readCommaSeperatedString("a,b(c,d),e"), new String[] {"a", "b(c,d)", "e"}); // Test handling of nested braces assertArrayEquals(StringHelper.readCommaSeperatedString("a,b(c,d(e,f),g),h"), new String[] {"a", "b(c,d(e,f),g)", "h"}); // Test if whitespace is stripped assertArrayEquals(StringHelper.readCommaSeperatedString(" "), new String[0]); assertArrayEquals(StringHelper.readCommaSeperatedString("a, b(c,d), e"), new String[] {"a", "b(c,d)", "e"}); assertArrayEquals(StringHelper.readCommaSeperatedString(" a, b(c,d), e "), new String[] {"a", "b(c,d)", "e"}); }
private static WeightedMobSpawnGroup readSingleGroup(String json) throws InvalidConfigException String[] groupParts = StringHelper.readCommaSeperatedString(group); String mobName = null; int weight = -1;