private static SortedMap<String, Object> makeMap(String[] itemNames, Object[] itemValues) throws OpenDataException { if (itemNames == null || itemValues == null) throw new IllegalArgumentException("Null itemNames or itemValues"); if (itemNames.length == 0 || itemValues.length == 0) throw new IllegalArgumentException("Empty itemNames or itemValues"); if (itemNames.length != itemValues.length) { throw new IllegalArgumentException( "Different lengths: itemNames[" + itemNames.length + "], itemValues[" + itemValues.length + "]"); } SortedMap<String, Object> map = new TreeMap<String, Object>(); for (int i = 0; i < itemNames.length; i++) { String name = itemNames[i]; if (name == null || name.equals("")) throw new IllegalArgumentException("Null or empty item name"); if (map.containsKey(name)) throw new OpenDataException("Duplicate item name " + name); map.put(itemNames[i], itemValues[i]); } return map; }
private static SortedMap<String, Object> makeMap(Map<String, ?> items) { if (items == null || items.isEmpty()) throw new IllegalArgumentException("Null or empty items map"); SortedMap<String, Object> map = new TreeMap<String, Object>(); for (Object key : items.keySet()) { if (key == null || key.equals("")) throw new IllegalArgumentException("Null or empty item name"); if (!(key instanceof String)) { throw new ArrayStoreException("Item name is not string: " + key); // This can happen because of erasure. The particular // exception is a historical artifact - an implementation // detail that leaked into the API. } map.put((String) key, items.get(key)); } return map; }