private void updateMax() { while (map.containsKey(Integer.toString(max++))) { ; } }
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public Collection<IntTo<X>> toCollection(Collection<IntTo<X>> into) { if (into == null) { into = newList(); } if (map instanceof StringToAbstract) { into.addAll(((StringToAbstract) map).valueSet()); } else { final String[] keys = map.keyArray(); Arrays.sort(keys); for (final String key : keys) { into.add(map.get(key)); } } return into; }
@Override @SuppressWarnings("unchecked") public boolean addAll(final IntTo<X>... items) { updateMax(); for (final IntTo<X> item : items) { map.put(Integer.toString(max++), item); } return true; }
@Override public boolean findRemove(final IntTo<X> value, final boolean all) { if (value == null) { return false; } boolean success = false; final String[] keys = map.keyArray(); main: for (int i = keys.length; i-->0;) { final String key = keys[i]; final IntTo<X> item = map.get(key); if (item.size() == value.size()) { for (int j = item.size(); j-->0;) { if (!equals(item.get(j), value.get(j))) { continue main; } } if (!all) { return true; } success = true; } } return success; }
@Override public int indexOf(final IntTo<X> value) { if (value == null) { return -1; } final String[] keys = map.keyArray(); main: for (int i = keys.length; i-->0;) { final String key = keys[i]; final IntTo<X> item = map.get(key); if (item.size() == value.size()) { for (int j = item.size(); j-->0;) { if (!equals(item.get(j), value.get(j))) { continue main; } } return Integer.parseInt(key); } } return -1; }
@Override public boolean contains(final IntTo<X> value) { if (value == null) { return false; } main: for (final IntTo<X> item : map.values()) { if (item.size() == value.size()) { for (int i = item.size(); i-->0;) { if (!equals(item.get(i), value.get(i))) { continue main; } } return true; } } return false; }
@Override public void add(final int key, final X item) { map.get(Integer.toString(key)).add(item); }
@Override public boolean isEmpty() { return map.isEmpty(); }
@Override public int size() { return map.size(); }
@Override public IntTo<X> at(final int index) { return map.get(Integer.toString(index)); }
@Override public Iterable<IntTo<X>> forEach() { return map.values(); }
@Override @SuppressWarnings("unchecked") public Set<IntTo<X>> asSet() { final Set<IntTo<X>> set = newSet(); if (map instanceof StringToAbstract) { set.addAll(((StringToAbstract<IntTo<X>>)map).valueSet()); } else { for (final IntTo<X> value : map.values()) { set.add(value); } } return set; }
@Override public IntTo<X> get(final Object key) { assertValid(key); return map.get(String.valueOf(key)); }
@Override public IntTo<X> setValue(final IntTo<X> value) { return map.put(asString, value); } };
@Override @SuppressWarnings("unchecked") public void setValue(final Object key, final Object value) { assertValid(key); if ((Integer)key > max) { max = (Integer)key; } map.put(String.valueOf(key), (IntTo<X>)value); }
@Override public boolean add(final IntTo<X> item) { updateMax(); map.put(Integer.toString(max++), item); return true; }
@Override public boolean remove(final int index) { return map.remove(Integer.toString(index)) != null; }
@Override public IntTo<X> getValue() { return map.get(asString); }
@Override public IntTo<X> put(final Entry<Integer, IntTo<X>> item) { return map.put(Integer.toString(item.getKey()), item.getValue()); }