public void testSimple() throws Exception { File tmp = new File("tmp"); PersistentMap<String> pm = new PersistentMap<String>(new File(tmp, "simple"), String.class); try { assertNull(pm.put("abc", "def")); assertEquals("def", pm.get("abc")); pm.close(); PersistentMap<String> pm2 = new PersistentMap<String>(new File(tmp, "simple"), String.class); assertEquals("def", pm2.get("abc")); assertEquals(Arrays.asList("abc"), new ArrayList<String>(pm2.keySet())); for (Map.Entry<String, String> e : pm2.entrySet()) { e.setValue("XXX"); } assertEquals("XXX", pm2.get("abc")); pm2.close(); } finally { pm.close(); IO.delete(tmp); } }
protected void initAuFeatureMap() { if (definitionMap.containsKey(DefinableArchivalUnit.KEY_AU_FEATURE_URL_MAP)) { Map<String, ?> featMap = definitionMap.getMap(DefinableArchivalUnit.KEY_AU_FEATURE_URL_MAP); for (Map.Entry ent : featMap.entrySet()) { Object val = ent.getValue(); if (val instanceof Map) { ent.setValue(MapUtil.expandAlternativeKeyLists((Map) val)); } } } }
public static void main(String[] args) { long start = System.currentTimeMillis(); Scanner input = new Scanner(System.in); int numberOfTestCases = input.nextInt(); ArrayList<Integer> order = new ArrayList<Integer>(numberOfTestCases); int previousKey = -1; int previousValue = 0; int cycleNumber = 0; Map<Integer, Integer> testCases = new TreeMap<Integer, Integer>(); for (int i = 0; i < numberOfTestCases; i++) { int numberOfCycles = input.nextInt(); testCases.put(numberOfCycles, 1); order.add(numberOfCycles); } for (Map.Entry<Integer, Integer> entry : testCases.entrySet()) { int numberOfCycles; int initialHeight; if (previousKey == -1) { numberOfCycles = entry.getKey(); initialHeight = entry.getValue(); } else { numberOfCycles = entry.getKey() - previousKey; initialHeight = previousValue; } for (int i = 0; i < numberOfCycles; i++) { if (cycleNumber % 2 == 0) { initialHeight *= 2; } else { initialHeight += 1; } cycleNumber++; } entry.setValue(initialHeight); previousKey = entry.getKey(); previousValue = initialHeight; } for (Integer element : order) { System.out.println(testCases.get(element)); } long elapsed = System.currentTimeMillis() - start; System.out.println("time: " + elapsed); }
/** pollLastEntry returns entries in order */ public void testDescendingPollLastEntry() { ConcurrentNavigableMap map = dmap5(); Map.Entry e = map.pollLastEntry(); assertEquals(m5, e.getKey()); assertEquals("E", e.getValue()); e = map.pollLastEntry(); assertEquals(m4, e.getKey()); map.put(m5, "E"); e = map.pollLastEntry(); assertEquals(m5, e.getKey()); assertEquals("E", e.getValue()); e = map.pollLastEntry(); assertEquals(m3, e.getKey()); map.remove(m2); e = map.pollLastEntry(); assertEquals(m1, e.getKey()); try { e.setValue("E"); shouldThrow(); } catch (UnsupportedOperationException success) { } e = map.pollLastEntry(); assertNull(e); }
/** pollLastEntry returns entries in order */ public void testPollLastEntry() { ConcurrentNavigableMap map = map5(); Map.Entry e = map.pollLastEntry(); assertEquals(five, e.getKey()); assertEquals("E", e.getValue()); e = map.pollLastEntry(); assertEquals(four, e.getKey()); map.put(five, "E"); e = map.pollLastEntry(); assertEquals(five, e.getKey()); assertEquals("E", e.getValue()); e = map.pollLastEntry(); assertEquals(three, e.getKey()); map.remove(two); e = map.pollLastEntry(); assertEquals(one, e.getKey()); try { e.setValue("E"); shouldThrow(); } catch (UnsupportedOperationException success) { } e = map.pollLastEntry(); assertNull(e); }
static void twoMapTest2(Map s, Object[] key, Object[] absent) { int size = key.length; Map s2 = newMap(); putAllTest("Add Absent ", size, s, s2); putAllTest("Modify Present ", size, s, s2); Object lastkey = kitTest(s2, size); Object hold = s2.get(lastkey); int sum = 0; timer.start("Traverse entry ", size * 12); // 12 until finish int sh1 = s.hashCode() - s2.hashCode(); reallyAssert(sh1 == 0); boolean eq1 = s2.equals(s); boolean eq2 = s.equals(s2); reallyAssert(eq1 && eq2); Set es2 = s2.entrySet(); for (Iterator it = s.entrySet().iterator(); it.hasNext(); ) { Object entry = it.next(); if (es2.contains(entry)) ++sum; } reallyAssert(sum == size); s2.put(lastkey, MISSING); int sh2 = s.hashCode() - s2.hashCode(); reallyAssert(sh2 != 0); eq1 = s2.equals(s); eq2 = s.equals(s2); reallyAssert(!eq1 && !eq2); sum = 0; for (Iterator it = s.entrySet().iterator(); it.hasNext(); ) { Map.Entry e = (Map.Entry) it.next(); e.setValue(absent[sum++]); } reallyAssert(sum == size); for (Iterator it = s2.entrySet().iterator(); it.hasNext(); ) { Map.Entry e = (Map.Entry) it.next(); e.setValue(s.get(e.getKey())); } timer.finish(); int rmiss = 0; timer.start("Remove Present ", size * 2); Iterator s2i = s2.entrySet().iterator(); Set es = s.entrySet(); while (s2i.hasNext()) { if (!es.remove(s2i.next())) ++rmiss; } timer.finish(); reallyAssert(rmiss == 0); clrTest(size, s2); reallyAssert(s2.isEmpty() && s.isEmpty()); }
public Object setValue(Object o) { if (!predicate.evaluate(o)) { throw new IllegalArgumentException("Cannot set value - Predicate rejected it"); } return entry.setValue(o); }