public static String[] toArray(String list, String delimiter) { return toArrayFromNormalized(normalizeString(list, delimiter), normalizeDelimiter(delimiter)); }
private static String normalizeDelimiter(String delim) { delim = normalizeString(delim, delim); delim = regularExpressionReplace(delim, '\\'); delim = regularExpressionReplace(delim, '|'); delim = regularExpressionReplace(delim, '('); delim = regularExpressionReplace(delim, ')'); delim = regularExpressionReplace(delim, '*'); delim = regularExpressionReplace(delim, '+'); delim = regularExpressionReplace(delim, '.'); delim = regularExpressionReplace(delim, '?'); delim = regularExpressionReplace(delim, '['); delim = regularExpressionReplace(delim, ']'); delim = regularExpressionReplace(delim, '^'); delim = regularExpressionReplace(delim, '{'); delim = regularExpressionReplace(delim, '}'); delim = regularExpressionReplace(delim, '$'); return delim; }
private String sort(String list, boolean reverse, String delimiter) { try { int[] unsorted = ListProcessor.toIntArray(list, delimiter); if (reverse) { return ListProcessor.toString(ListProcessor.reverse(ListProcessor.sort(unsorted)), delimiter); } else { return ListProcessor.toString(ListProcessor.sort(unsorted), delimiter); } } catch (NumberFormatException e) { try { double[] unsorted = ListProcessor.toDoubleArray(list, delimiter); if (reverse) { return ListProcessor.toString(ListProcessor.reverse(ListProcessor.sort(unsorted)), delimiter); } else { return ListProcessor.toString(ListProcessor.sort(unsorted), delimiter); } } catch (NumberFormatException f) { String[] unsorted = ListProcessor.toArray(list, delimiter); if (reverse) { return ListProcessor.toString(ListProcessor.reverse(ListProcessor.sort(unsorted)), delimiter); } else { return ListProcessor.toString(ListProcessor.sort(unsorted), delimiter); } } } } }
public String trimIntList(String str_list, String delimiter, int percent) throws Exception { int[] list = ListProcessor.toIntArray(str_list, delimiter); list = ListProcessor.trimPercent(ListProcessor.sort(list), percent); return ListProcessor.toString(list, delimiter); }
public String trimStringList(String str_list, String delimiter, int percent) throws Exception { String[] list = ListProcessor.toArray(str_list, delimiter); list = ListProcessor.trimPercent(ListProcessor.sort(list), percent); return ListProcessor.toString(list, delimiter); } }
public String trimDoubleList(String str_list, String delimiter, int percent) throws Exception { double[] list = ListProcessor.toDoubleArray(str_list, delimiter); list = ListProcessor.trimPercent(ListProcessor.sort(list), percent); return ListProcessor.toString(list, delimiter); }
Map<String, String> result = new HashMap<>(); try { String[] table = ListProcessor.toArray(list, delimiter); int resolvedIndex; try { resolvedIndex = ListProcessor.getIndex(index, table.length); } catch (NumberFormatException e) { throw new NumberFormatException(e.getMessage() + WHILE_PARSING_INDEX);
String[] subArray = sublist.split(delimiter); String[] containerArray = container.split(delimiter); String[] uncontainedArray = ListProcessor.getUncontainedArray(subArray, containerArray, InputsUtils.toBoolean(ignoreCase, true, IGNORE_CASE)); if (ListProcessor.arrayElementsAreNull(uncontainedArray)) { result.put(RESPONSE_TEXT, TRUE); result.put(RETURN_RESULT, EMPTY_STRING);
private static double[] roundTo(double[] values, int decimals) { double[] rounded = new double[values.length]; for (int count = 0; count < values.length; count++) { rounded[count] = roundTo(values[count], decimals); } return rounded; }
private static String regularExpressionReplace(String delim, char character) { int index; if ((index = delim.indexOf(character)) > -1) { String start = delim.substring(0, index); String end = ""; if (index + 1 < delim.length()) { end = delim.substring(index + 1, delim.length()); } delim = start + "\\" + character + regularExpressionReplace(end, character); } return delim; }
public static String[] getUncontainedArray(String[] subArray, String[] containerArray, boolean ignoreCase) { String[] uncontainedArray = new String[subArray.length]; int index = 0; boolean found = false; for (String subStr : subArray) { for (String contStr : containerArray) { found = elementsAreEqual(subStr, contStr, ignoreCase); if (found) { break; } } if (!found) { uncontainedArray[index] = subStr; index++; } } String[] newUncontainedArray = new String[index]; System.arraycopy(uncontainedArray, 0, newUncontainedArray, 0, index); return newUncontainedArray; }
public static String toString(double[] list, String delimiter) { if (list.length == 0) { return ""; } list = roundTo(list, 3); StringBuilder out = new StringBuilder("" + list[0]); for (int count = 1; count < list.length; count++) { out.append(delimiter).append(list[count]); } return out.toString(); }