@Test public void testPair() { Pair<String, String> o1 = new Pair<String, String>(); o1.setKey("key"); o1.setValue("value"); Pair<String, String> o2 = new Pair<String, String>("key", "value"); Assert.assertEquals(o1, o2); Assert.assertEquals(o1.hashCode(), o2.hashCode()); Assert.assertEquals(o1.toString(), o2.toString()); }
public Long put(K1 key, K2 dataKey, long value) { Pair<K2, Long> pair = get(key); if (null == pair) { pair = new Pair<K2, Long>(dataKey, value); map.put(key, data.size()); data.add(pair); return null; } else { Long oldValue = pair.getValue(); pair.setValue(value); return oldValue; } }
public long inc(K1 key, K2 dataKey, long step) { Pair<K2, Long> pair = get(key); if (null == pair) { pair = new Pair<K2, Long>(dataKey, step); map.put(key, data.size()); data.add(pair); return step; } else { Long oldValue = pair.getValue(); pair.setValue(oldValue + step); return oldValue + step; } }
/** * Store a new key-value pair, or add a new one. The normal functionality is taken care of by the * superclass in the call to {@link #setProperty}; this method takes care of this classes * extensions. * * @param key the key of the property to be stored * @param value the value to be stored */ private void innerSetProperty(String key, String value) { value = escapeValue(value); if (keyedPairLines.containsKey(key)) { Integer i = (Integer) keyedPairLines.get(key); Pair p = (Pair) logicalLines.get(i.intValue()); p.setValue(value); } else { key = escapeName(key); Pair p = new Pair(key, value); p.setNew(true); keyedPairLines.put(key, new Integer(logicalLines.size())); logicalLines.add(p); } }