@Override public Iterator<K> iterator() { final Iterator<K> it = map.getAllKeys().iterator(); return new Iterator<K>() { private K last = null; @Override public boolean hasNext() { return it.hasNext(); } @Override public K next() { last = it.next(); return last; } @Override public void remove() { if (last == null) { throw new IllegalStateException(); } if (map.get(last) == null) { throw new ConcurrentModificationException(); } map.remove(last); last = null; } }; }
/** * Use this method to convert a NSDictionary with NSString keys to a Map with String keys. * Keys of this NSDictionary must be of type NSString, otherwise an exception will be thrown. * @return * @throws UnsupportedOperationException when the dictionary keys are not of type NSString. */ public Map<String, V> asStringMap() { Map<String, V> map = new HashMap<>(); if (size() == 0) return map; if (!(getAllKeys().get(0) instanceof NSString)) throw new UnsupportedOperationException("keys must be of type NSString"); for (java.util.Map.Entry<K, V> e : entrySet()) { map.put(e.getKey().toString(), e.getValue()); } return map; }
@Override public Iterator<K> iterator() { final Iterator<K> it = map.getAllKeys().iterator(); return new Iterator<K>() { private K last = null; @Override public boolean hasNext() { return it.hasNext(); } @Override public K next() { last = it.next(); return last; } @Override public void remove() { if (last == null) { throw new IllegalStateException(); } if (map.get(last) == null) { throw new ConcurrentModificationException(); } map.remove(last); last = null; } }; }
@Override public Iterator<K> iterator() { final Iterator<K> it = map.getAllKeys().iterator(); return new Iterator<K>() { private K last = null; @Override public boolean hasNext() { return it.hasNext(); } @Override public K next() { last = it.next(); return last; } @Override public void remove() { if (last == null) { throw new IllegalStateException(); } if (map.get(last) == null) { throw new ConcurrentModificationException(); } map.remove(last); last = null; } }; }
/** * Use this method to convert a NSDictionary with NSString keys to a Map with String keys. * Keys of this NSDictionary must be of type NSString, otherwise an exception will be thrown. * @return * @throws UnsupportedOperationException when the dictionary keys are not of type NSString. */ public Map<String, V> asStringMap() { Map<String, V> map = new HashMap<>(); if (size() == 0) return map; if (!(getAllKeys().get(0) instanceof NSString)) throw new UnsupportedOperationException("keys must be of type NSString"); for (java.util.Map.Entry<K, V> e : entrySet()) { map.put(e.getKey().toString(), e.getValue()); } return map; }
/** * Use this method to convert a NSDictionary with NSString keys to a Map with String keys. * Keys of this NSDictionary must be of type NSString, otherwise an exception will be thrown. * @return * @throws UnsupportedOperationException when the dictionary keys are not of type NSString. */ public Map<String, V> asStringMap() { Map<String, V> map = new HashMap<>(); if (size() == 0) return map; if (!(getAllKeys().get(0) instanceof NSString)) throw new UnsupportedOperationException("keys must be of type NSString"); for (java.util.Map.Entry<K, V> e : entrySet()) { map.put(e.getKey().toString(), e.getValue()); } return map; }