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; }
/** * Override superclass to ensure that MultiMap instances are * correctly handled. * <p> * If you call this method with a normal map, each entry is * added using <code>put(Object,Object)</code>. * If you call this method with a multi map, each entry is * added using <code>putAll(Object,Collection)</code>. * * @param map the map to copy (either a normal or multi map) */ public void putAll(Map map) { if (map instanceof MultiMap) { for (Iterator it = map.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); Collection coll = (Collection) entry.getValue(); putAll(entry.getKey(), coll); } } else { for (Iterator it = map.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); put(entry.getKey(), entry.getValue()); } } }
@Override @SuppressWarnings("unchecked") public Map<String, Collection<SkuAttribute>> getMultiValueSkuAttributes() { MultiValueMap multiValueMap = new MultiValueMap(); for (SkuAttribute skuAttribute : skuAttributes) { multiValueMap.put(skuAttribute.getName(), skuAttribute); } return multiValueMap; }
/** * Override superclass to ensure that MultiMap instances are * correctly handled. * <p> * If you call this method with a normal map, each entry is * added using <code>put(Object,Object)</code>. * If you call this method with a multi map, each entry is * added using <code>putAll(Object,Collection)</code>. * * @param map the map to copy (either a normal or multi map) */ public void putAll(Map map) { if (map instanceof MultiMap) { for (Iterator it = map.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); Collection coll = (Collection) entry.getValue(); putAll(entry.getKey(), coll); } } else { for (Iterator it = map.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); put(entry.getKey(), entry.getValue()); } } }
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 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())); }
@Override public Map<String, List<PromotionMessageDTO>> convertPromotionMessagesToDTOs(Set<PromotionMessage> promotionMessages, Offer offer) { MultiValueMap promotionMessageDTOs = new MultiValueMap(); for (PromotionMessage message : promotionMessages) { PromotionMessageDTO dto = new PromotionMessageDTO(message); CustomerRuleHolder customerRuleHolder = buildCustomerRuleHolder(offer); dto.setCustomerRuleHolder(customerRuleHolder); promotionMessageDTOs.put(dto.getMessagePlacement(), dto); } return promotionMessageDTOs; }
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")); }
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 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")); }
public void testGetCollection() { MultiValueMap map = new MultiValueMap(); map.put("A", "AA"); assertSame(map.get("A"), map.getCollection("A")); }
public void testRemove_KeyItem() { MultiValueMap map = new MultiValueMap(); map.put("A", "AA"); map.put("A", "AB"); map.put("A", "AC"); assertEquals(null, map.remove("C", "CA")); assertEquals(null, map.remove("A", "AD")); assertEquals("AC", map.remove("A", "AC")); assertEquals("AB", map.remove("A", "AB")); assertEquals("AA", map.remove("A", "AA")); assertEquals(new MultiValueMap(), map); }
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 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()); }
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")); }
public void testSize_Key() { MultiValueMap map = new MultiValueMap(); assertEquals(0, map.size("A")); assertEquals(0, map.size("B")); map.put("A", "AA"); assertEquals(1, map.size("A")); assertEquals(0, map.size("B")); map.put("B", "BA"); assertEquals(1, map.size("A")); assertEquals(1, map.size("B")); map.put("B", "BB"); assertEquals(1, map.size("A")); assertEquals(2, map.size("B")); map.put("B", "BC"); assertEquals(1, map.size("A")); assertEquals(3, map.size("B")); map.remove("A"); assertEquals(0, map.size("A")); assertEquals(3, map.size("B")); map.remove("B", "BC"); assertEquals(0, map.size("A")); assertEquals(2, map.size("B")); }
@Override public boolean add(final Traverser.Admin<S> traverser) { final boolean newOne = super.add(traverser); // if newly added then the traverser will be the same as the one passed in here to add(). // if it is not, then it was merged to an existing traverser and the bulk would have // updated on that reference, thus only new stuff really needs to be added to the index if (newOne) index.put(indexingFunction.apply(traverser.get()), traverser); return newOne; }
public DefaultQueryCollection(final TreeSet<QueryContext> treeSet) { this.queries = treeSet; for (QueryContext query : treeSet) { queriesByUser.put(query.getSubmittedUser(), query); } }
@Override public void addService(Service service) { String name = service.getName(); services.put(name, service); log.serviceAdded(name, service); }
public void setProperty(String key, String value) { if(properties.containsKey(key)) { properties.remove(key); } properties.put(key,value); } /**