public ValuesIterator(Object key) { this.key = key; this.values = getCollection(key); this.iterator = values.iterator(); }
/** * Gets the size of the collection mapped to the specified key. * * @param key the key to get size for * @return the size of the collection at the key, zero if key not in map */ public int size(Object key) { Collection coll = getCollection(key); if (coll == null) { return 0; } return coll.size(); }
/** * Checks whether the collection at the specified key contains the value. * * @param value the value to search for * @return true if the map contains the value */ public boolean containsValue(Object key, Object value) { Collection coll = getCollection(key); if (coll == null) { return false; } return coll.contains(value); }
public ValuesIterator(Object key) { this.key = key; this.values = getCollection(key); this.iterator = values.iterator(); }
/** * Checks whether the collection at the specified key contains the value. * * @param value the value to search for * @return true if the map contains the value */ public boolean containsValue(Object key, Object value) { Collection coll = getCollection(key); if (coll == null) { return false; } return coll.contains(value); }
/** * Gets the size of the collection mapped to the specified key. * * @param key the key to get size for * @return the size of the collection at the key, zero if key not in map */ public int size(Object key) { Collection coll = getCollection(key); if (coll == null) { return 0; } return coll.size(); }
/** * Removes a specific value from map. * <p> * The item is removed from the collection mapped to the specified key. * Other values attached to that key are unaffected. * <p> * If the last value for a key is removed, <code>null</code> will be returned * from a subsequant <code>get(key)</code>. * * @param key the key to remove from * @param value the value to remove * @return the value removed (which was passed in), null if nothing removed */ public Object remove(Object key, Object value) { Collection valuesForKey = getCollection(key); if (valuesForKey == null) { return null; } boolean removed = valuesForKey.remove(value); if (removed == false) { return null; } if (valuesForKey.isEmpty()) { remove(key); } return value; }
/** * Removes a specific value from map. * <p> * The item is removed from the collection mapped to the specified key. * Other values attached to that key are unaffected. * <p> * If the last value for a key is removed, <code>null</code> will be returned * from a subsequant <code>get(key)</code>. * * @param key the key to remove from * @param value the value to remove * @return the value removed (which was passed in), null if nothing removed */ public Object remove(Object key, Object value) { Collection valuesForKey = getCollection(key); if (valuesForKey == null) { return null; } boolean removed = valuesForKey.remove(value); if (removed == false) { return null; } if (valuesForKey.isEmpty()) { remove(key); } return value; }
/** * Adds a collection of values to the collection associated with * the specified key. * * @param key the key to store against * @param values the values to add to the collection at the key, null ignored * @return true if this map changed */ public boolean putAll(Object key, Collection values) { if (values == null || values.size() == 0) { return false; } boolean result = false; Collection coll = getCollection(key); if (coll == null) { coll = createCollection(values.size()); coll.addAll(values); if (coll.size() > 0) { // only add if non-zero size to maintain class state getMap().put(key, coll); result = true; // map definitely changed } } else { result = coll.addAll(values); } return result; }
/** * Adds the value to the collection associated with the specified key. * <p> * Unlike a normal <code>Map</code> the previous value is not replaced. * Instead the new value is added to the collection stored against the key. * * @param key the key to store against * @param value the value to add to the collection at the key * @return the value added if the map changed and null if the map did not change */ public Object put(Object key, Object value) { boolean result = false; Collection coll = getCollection(key); if (coll == null) { coll = createCollection(1); result = coll.add(value); if (coll.size() > 0) { // only add if non-zero size to maintain class state getMap().put(key, coll); result = true; // map definitely changed } } else { result = coll.add(value); } return (result ? value : null); }
/** * Adds the value to the collection associated with the specified key. * <p> * Unlike a normal <code>Map</code> the previous value is not replaced. * Instead the new value is added to the collection stored against the key. * * @param key the key to store against * @param value the value to add to the collection at the key * @return the value added if the map changed and null if the map did not change */ public Object put(Object key, Object value) { boolean result = false; Collection coll = getCollection(key); if (coll == null) { coll = createCollection(1); result = coll.add(value); if (coll.size() > 0) { // only add if non-zero size to maintain class state getMap().put(key, coll); result = true; // map definitely changed } } else { result = coll.add(value); } return (result ? value : null); }
/** * Adds a collection of values to the collection associated with * the specified key. * * @param key the key to store against * @param values the values to add to the collection at the key, null ignored * @return true if this map changed */ public boolean putAll(Object key, Collection values) { if (values == null || values.size() == 0) { return false; } boolean result = false; Collection coll = getCollection(key); if (coll == null) { coll = createCollection(values.size()); coll.addAll(values); if (coll.size() > 0) { // only add if non-zero size to maintain class state getMap().put(key, coll); result = true; // map definitely changed } } else { result = coll.addAll(values); } return result; }
public void testGetCollection() { MultiValueMap map = new MultiValueMap(); map.put("A", "AA"); assertSame(map.get("A"), map.getCollection("A")); }
public void testPutAll_Map2() { Map original = new HashMap(); original.put("keyX", "object1"); original.put("keyY", "object2"); MultiValueMap test = new MultiValueMap(); test.put("keyA", "objectA"); test.put("keyX", "object0"); test.putAll(original); assertEquals(3, test.size()); assertEquals(4, test.totalSize()); assertEquals(1, test.getCollection("keyA").size()); assertEquals(2, test.getCollection("keyX").size()); assertEquals(1, test.getCollection("keyY").size()); assertEquals(true, test.containsValue("objectA")); assertEquals(true, test.containsValue("object0")); assertEquals(true, test.containsValue("object1")); assertEquals(true, test.containsValue("object2")); }
/** * Gets a collection of {@link Traverser} objects that contain the specified value. * * @param k the key produced by the indexing function * @return */ public Collection<Traverser.Admin<S>> get(final I k) { final Collection<Traverser.Admin<S>> c = index.getCollection(k); // if remove() is called on this class, then the MultiValueMap *may* (javadoc wasn't clear // what the expectation was - used the word "typically") return an empty list if the last // item removed leaves the list empty. i think we want to enforce null for TraverserSet // semantics return c != null && c.isEmpty() ? null : c; }
public void testPutAll_Map1() { MultiMap original = new MultiValueMap(); original.put("key", "object1"); original.put("key", "object2"); MultiValueMap test = new MultiValueMap(); test.put("keyA", "objectA"); test.put("key", "object0"); test.putAll(original); assertEquals(2, test.size()); assertEquals(4, test.totalSize()); assertEquals(1, test.getCollection("keyA").size()); assertEquals(3, test.getCollection("key").size()); assertEquals(true, test.containsValue("objectA")); assertEquals(true, test.containsValue("object0")); assertEquals(true, test.containsValue("object1")); assertEquals(true, test.containsValue("object2")); }
private static void initBackend(final HugeGraph graph) throws InterruptedException { int retries = RETRIES; retry: do { try { graph.initBackend(); } catch (Exception e) { String clz = e.getClass().getSimpleName(); String message = e.getMessage(); if (exceptions.containsKey(clz) && retries > 0) { @SuppressWarnings("unchecked") Collection<String> keywords = exceptions.getCollection(clz); for (String keyword : keywords) { if (message.contains(keyword)) { LOG.info("Init failed with exception '{} : {}', " + "retry {}...", clz, message, RETRIES - retries + 1); Thread.sleep(RETRY_INTERVAL); continue retry; } } } throw e; } break; } while(retries-- > 0); } }
public Collection /*<ExternalCustomFieldOption>*/getParentOptions(final String configurationSchemeId) { final Collection collection = parentOptionMap.getCollection(configurationSchemeId); if (collection == null) { return Collections.EMPTY_LIST; } return collection; }
public Collection /*<ExternalCustomFieldOption>*/getChildOptions(final String parentOptionId) { final Collection collection = childOptionMap.getCollection(parentOptionId); if (collection == null) { return Collections.EMPTY_LIST; } return collection; }
@Override public List<Service> getService(String name) { @SuppressWarnings("unchecked") Collection<Service> list = services.getCollection(name); log.checkService(name, list); return unmodifiableList(new ArrayList<Service>(list)); }