Refine search
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 MultiValueMap createTestMap(Class collectionClass) { final MultiValueMap map = MultiValueMap.decorate(new HashMap(), collectionClass); map.put("one", "uno"); map.put("one", "un"); map.put("two", "dos"); map.put("two", "deux"); map.put("three", "tres"); map.put("three", "trois"); return map; }
/** * Gets an iterator for the collection mapped to the specified key. * * @param key the key to get an iterator for * @return the iterator of the collection at the key, empty iterator if key not in map */ public Iterator iterator(Object key) { if (!containsKey(key)) { return EmptyIterator.INSTANCE; } else { return new ValuesIterator(key); } }
@Override @SuppressWarnings("unchecked") public Map<String, Collection<SkuAttribute>> getMultiValueSkuAttributes() { MultiValueMap multiValueMap = new MultiValueMap(); for (SkuAttribute skuAttribute : skuAttributes) { multiValueMap.put(skuAttribute.getName(), skuAttribute); } return multiValueMap; }
/** * 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 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); }
private MultiMap getAsPropertiesKeyValueMultiMap(List<String> fileLines) { MultiMap multiMap = new MultiValueMap(); for (String line : fileLines) { if (isCorectKeyValueLine(line)) { Map.Entry<String, String> tuple = extractKeyValue(line); multiMap.put(tuple.getKey(), tuple.getValue()); } } return multiMap; }
/** * Removes all occurrences of the given header in this stub response (using a case insensitive search) * and sets its single value. * @param name header name * @param value header value */ @SuppressWarnings("unchecked") void setHeaderCaseInsensitive(final String name, final String value) { final MultiMap result = new MultiValueMap(); for (final Object o: this.headers.keySet()) { final String key = (String) o; //fucking non-generics MultiMap if (!name.equalsIgnoreCase(key)) { //copy all other headers to the result multimap for(final String s: (Collection<String>)this.headers.get(o)) { result.put(o, s); } } } this.headers.clear(); this.headers.putAll(result); this.addHeader(name, value); }
public void testGetCollection() { MultiValueMap map = new MultiValueMap(); map.put("A", "AA"); assertSame(map.get("A"), map.getCollection("A")); }
public void testSize() { MultiValueMap map = new MultiValueMap(); assertEquals(0, map.size()); map.put("A", "AA"); assertEquals(1, map.size()); map.put("B", "BA"); assertEquals(2, map.size()); map.put("B", "BB"); assertEquals(2, map.size()); map.put("B", "BC"); assertEquals(2, map.size()); map.remove("A"); assertEquals(2, map.size()); map.remove("B", "BC"); assertEquals(2, map.size()); }
public void testMapEquals() { MultiValueMap one = new MultiValueMap(); Integer value = new Integer(1); one.put("One", value); one.remove("One", value); MultiValueMap two = new MultiValueMap(); assertEquals(two, one); }
public void testTotalSize() { MultiValueMap map = new MultiValueMap(); assertEquals(0, map.totalSize()); map.put("A", "AA"); assertEquals(1, map.totalSize()); map.put("B", "BA"); assertEquals(2, map.totalSize()); map.put("B", "BB"); assertEquals(3, map.totalSize()); map.put("B", "BC"); assertEquals(4, map.totalSize()); map.remove("A"); assertEquals(3, map.totalSize()); map.remove("B", "BC"); assertEquals(2, map.totalSize()); }
int total = 0; int count = 0; MultiMap transactionMap = new MultiValueMap(); Set<Long> eventPointers = inflightPuts.get(txnID); for (Long eventPointer : eventPointers) { transactionMap.put(txnID, FlumeEventPointer.fromLong(eventPointer)); putCount++; ptr = new FlumeEventPointer(fileId, offset); transactionMap.put(trans, ptr); } else if (type == TransactionEventRecord.Type.TAKE.get()) { takeCount++; Take take = (Take) record; ptr = new FlumeEventPointer(take.getFileID(), take.getOffset()); transactionMap.put(trans, ptr); } else if (type == TransactionEventRecord.Type.ROLLBACK.get()) { rollbackCount++;
/** * Creates a map which decorates the given <code>map</code> and * creates the value collections using the supplied <code>collectionFactory</code>. * * @param map the map to decorate * @param collectionFactory the collection factory (must return a Collection object). */ public static MultiValueMap decorate(Map map, Factory collectionFactory) { return new MultiValueMap(map, collectionFactory); }
public void testPut_ReturnValue() { MultiValueMap test = new MultiValueMap(); assertNotNull(test.put("key", "object1")); assertNotNull(test.put("key", "object2")); List coll = Arrays.asList(new String[]{"uno", "un"}); assertTrue(test.putAll("key", coll)); assertFalse(test.putAll("key", new ArrayList())); }
public void testContainsValue_Key() { MultiValueMap map = new MultiValueMap(); assertEquals(false, map.containsValue("A", "AA")); assertEquals(false, map.containsValue("B", "BB")); map.put("A", "AA"); assertEquals(true, map.containsValue("A", "AA")); assertEquals(false, map.containsValue("A", "AB")); }
private static void bindMetaAttributes(Element element, Table table, OverrideRepository repository) { MultiMap map = MetaAttributeBinder.loadAndMergeMetaMap( element, new MultiValueMap()); if(map!=null && !map.isEmpty()) { repository.addMetaAttributeInfo( table, map); } }
public void testIterator_Key() { MultiValueMap map = new MultiValueMap(); assertEquals(false, map.iterator("A").hasNext()); map.put("A", "AA"); Iterator it = map.iterator("A"); assertEquals(true, it.hasNext()); it.next(); assertEquals(false, it.hasNext()); }
public void setParameter(String name, String[] values) { if(parameterMap.containsKey(name)) parameterMap.remove(name); for (int i = 0; i < values.length; i++) { parameterMap.put("javax.portlet.prp_" + portletId + "_" + name, values[i]); } }
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); } }