@Test public void toMap() throws Exception { assertEquals(CollectionUtilities.toMap("a:b,c:d,E:F", ",", ":").get("c"), "d"); assertEquals(CollectionUtilities.toMap("a::b,c::d,E::F", ",", "::").get("a"), "b"); assertEquals(CollectionUtilities.toMap("a=b;c=d;E=F", ";", "=").get("E"), "F"); testInvalidMap("a:b:c,b:c", ",", ":"); }
@NotNull public static Map<String, String> toMap(@Nullable final String stringMap, @NotNull final String pairDelimiter, @NotNull final String keyValueDelimiter) { Map<String, String> theMap = new HashMap<>(); for (final String pairStr : toArray(stringMap, pairDelimiter)) { final String[] arrayPair = toArray(pairStr, keyValueDelimiter); if (arrayPair.length != 2 && arrayPair.length != 0) { throw new IllegalArgumentException(pairStr + ExceptionValues.EXCEPTION_DELIMITER + ExceptionValues.INVALID_KEY_VALUE_PAIR); } else if (arrayPair.length == 2) { theMap.put(arrayPair[0], arrayPair[1]); } } return theMap; }
CollectionUtilities { @NotNull public static Map<String, String> toMap(@Nullable final String stringMap, @NotNull final String pairDelimiter, @NotNull final String keyValueDelimiter) { Map<String, String> theMap = new HashMap<>(); for (final String pairStr : toArray(stringMap, pairDelimiter)) { final String[] arrayPair = toArray(pairStr, keyValueDelimiter); if (arrayPair.length != 2 && arrayPair.length != 0) { throw new IllegalArgumentException(pairStr + ExceptionValues.EXCEPTION_DELIMITER + ExceptionValues.INVALID_KEY_VALUE_PAIR); } else if (arrayPair.length == 2) { theMap.put(arrayPair[0], arrayPair[1]); } } return theMap; } }
CollectionUtilities { @NotNull public static Map<String, String> toMap(@Nullable final String stringMap, @NotNull final String pairDelimiter, @NotNull final String keyValueDelimiter) { Map<String, String> theMap = new HashMap<>(); for (final String pairStr : toArray(stringMap, pairDelimiter)) { final String[] arrayPair = toArray(pairStr, keyValueDelimiter); if (arrayPair.length != 2 && arrayPair.length != 0) { throw new IllegalArgumentException(pairStr + ExceptionValues.EXCEPTION_DELIMITER + ExceptionValues.INVALID_KEY_VALUE_PAIR); } else if (arrayPair.length == 2) { theMap.put(arrayPair[0], arrayPair[1]); } } return theMap; } private  CollectionUtilities(); }
CollectionUtilities { @NotNull public static Map<String, String> toMap(@Nullable final String stringMap, @NotNull final String pairDelimiter, @NotNull final String keyValueDelimiter) { Map<String, String> theMap = new HashMap<>(); for (final String pairStr : toArray(stringMap, pairDelimiter)) { final String[] arrayPair = toArray(pairStr, keyValueDelimiter); if (arrayPair.length != 2 && arrayPair.length != 0) { throw new IllegalArgumentException(pairStr + ExceptionValues.EXCEPTION_DELIMITER + ExceptionValues.INVALID_KEY_VALUE_PAIR); } else if (arrayPair.length == 2) { theMap.put(arrayPair[0], arrayPair[1]); } } return theMap; } private  CollectionUtilities(); @NotNull static String[] toArrayWithEscaped(@Nullable final String stringArray, @NotNull final String delimiter); @NotNull static String[] toArray(@Nullable final String stringArray, @NotNull final String delimiter); @NotNull static List<String> toListWithEscaped(@Nullable final String stringList, @NotNull final String delimiter); @NotNull static List<String> toList(@Nullable final String stringList, @NotNull final String delimiter); @NotNull static Map<String, String> toMap(@Nullable final String stringMap, @NotNull final String pairDelimiter, @NotNull final String keyValueDelimiter); }
CollectionUtilities { @NotNull public static Map<String, String> toMap(@Nullable final String stringMap, @NotNull final String pairDelimiter, @NotNull final String keyValueDelimiter) { Map<String, String> theMap = new HashMap<>(); for (final String pairStr : toArray(stringMap, pairDelimiter)) { final String[] arrayPair = toArray(pairStr, keyValueDelimiter); if (arrayPair.length != 2 && arrayPair.length != 0) { throw new IllegalArgumentException(pairStr + ExceptionValues.EXCEPTION_DELIMITER + ExceptionValues.INVALID_KEY_VALUE_PAIR); } else if (arrayPair.length == 2) { theMap.put(arrayPair[0], arrayPair[1]); } } return theMap; } private  CollectionUtilities(); @NotNull static String[] toArrayWithEscaped(@Nullable final String stringArray, @NotNull final String delimiter); @NotNull static String[] toArray(@Nullable final String stringArray, @NotNull final String delimiter); @NotNull static List<String> toListWithEscaped(@Nullable final String stringList, @NotNull final String delimiter); @NotNull static List<String> toList(@Nullable final String stringList, @NotNull final String delimiter); @NotNull static Map<String, String> toMap(@Nullable final String stringMap, @NotNull final String pairDelimiter, @NotNull final String keyValueDelimiter);  }