public Builder addSymbolStatistics(Symbol symbol, SymbolStatsEstimate statistics) { symbolStatistics = symbolStatistics.plus(symbol, statistics); return this; }
public Builder removeSymbolStatistics(Symbol symbol) { symbolStatistics = symbolStatistics.minus(symbol); return this; }
@Override public boolean contains(final Object e) { return map.containsKey(e); }
Random r = new Random(); for(int i=0;i<10000;i++) { if(pmap.size()==0 || r.nextBoolean()) { // add int k = r.nextInt(), v = r.nextInt(); assertEquals(map.containsKey(k), pmap.containsKey(k)); assertEquals(map.get(k), pmap.get(k)); pmap = pmap.plus(k, v); } else { // remove a random key int j = r.nextInt(pmap.size()); for(Entry<Integer,Integer> e : pmap.entrySet()) { int k = e.getKey(); assertTrue(pmap.containsKey(k)); assertEquals(map.get(k), pmap.get(k)); assertTrue(map.entrySet().contains(e)); assertTrue(pmap.entrySet().contains(e)); UtilityTest.assertEqualsAndHash( pmap, pmap.plus(k,e.getValue()) ); pmap = pmap.minus(k); assertFalse(pmap.entrySet().contains(e)); assertEquals(map.containsKey(k), pmap.containsKey(k)); assertEquals(map.get(k), pmap.get(k)); map.remove(k); pmap = pmap.minus(k); assertFalse( pmap.containsKey(s) );
public void testMap() { PMap<Object,String> m = HashTreePMap.<Object,String>empty(); assertEquals(m.size(),0); m = m.plus(1,"One"); assertEquals(m.get(1),"One"); // last three have same hashCode: Object[] keys = {1,2,0,3,ConsPStack.empty()}; String[] values = {"one","two","","three","emptyList"}; for(int i=0;i<keys.length;i++) { m = m.plus(keys[i],values[i]); m = m.minus(keys[i]); m = m.plus(keys[i],values[i]); assertEquals(m.size(),i+1); assertEquals(m.get(keys[i]),values[i]); } for(int i=keys.length-1;i>=0;i--) { m = m.minus(keys[i]); assertEquals(m.size(),i); } }
public Events removeEvent(UUID scopeId, UUID eventId) { PMap<UUID, EventRecord> scope = this.events.get(scopeId); if (scope == null) { throw new IllegalArgumentException("Scope not found: " + scopeId); } scope = scope.minus(eventId); if (scope.isEmpty()) { return new Events(this.events.minus(scopeId)); } else { return new Events(this.events.plus(scopeId, scope)); } }
/** * @param <K> * @param <V> * @param intMap * @return a map backed by an empty version of intMap, * i.e. backed by intMap.minusAll(intMap.keySet()) */ public static <K,V> HashPMap<K,V> empty(final PMap<Integer,PSequence<Entry<K,V>>> intMap) { return new HashPMap<K,V>(intMap.minusAll(intMap.keySet()), 0); }
@SuppressWarnings("unchecked") private int count(final Object o) { if(!contains(o)) return 0; // otherwise o must be an E: return map.get((E)o); }
private PSet<ProxyWrapper> removeProxies(Class key){ val proxies = proxyCache.get(key); val proxiesToUse = proxies==null ? HashTreePSet.singleton(new ProxyWrapper((Proxy)Proxy.newProxyInstance(InvokeDynamicComprehender.class.getClassLoader(), new Class[]{key},new FunctionExecutionInvocationHandler()))) : proxies; if(proxies!=null) proxyCache = proxyCache.minus(key); return proxiesToUse; } private void mergeProxies(Class key,PSet<ProxyWrapper> proxies){
@Override public <V> V valueOf(Property<? super T, V> property, Donor<? extends V> defaultValue) { if (values.containsKey(property)) { //noinspection unchecked return (V) values.get(property).value(); } else { return defaultValue.value(); } } }
public Builder addSymbolStatistics(Map<Symbol, SymbolStatsEstimate> symbolStatistics) { this.symbolStatistics = this.symbolStatistics.plusAll(symbolStatistics); return this; }
public Set<Symbol> getSymbolsWithKnownStatistics() { return symbolStatistics.keySet(); }
@Override public Iterator<E> iterator() { final Iterator<Entry<E,Integer>> i = map.entrySet().iterator(); return new Iterator<E>() { private E e; private int n=0; public boolean hasNext() { return n>0 || i.hasNext(); } public E next() { if(n==0) { // finished with current element Entry<E,Integer> entry = i.next(); e = entry.getKey(); n = entry.getValue(); } n--; return e; } public void remove() { throw new UnsupportedOperationException(); } }; }
@Override protected boolean matchesSafely(FixedRekord<T> actualRekord, Description mismatchDescription) { mismatchDescription.appendText("a rekord that looks like ").appendValue(actualRekord); if (!expectedProperties.keySet().equals(actualRekord.keys().toSet())) { return false; } for (Map.Entry<Key<T, ?>, Matcher<?>> property : expectedProperties.entrySet()) { Key<T, ?> expectedKey = property.getKey(); Matcher<?> expectedValue = property.getValue(); if (!expectedValue.matches(actualRekord.get(expectedKey))) { return false; } } return true; } }
public MapPSet<E> minusAll(final Collection<?> list) { PMap<E,Object> map = this.map.minusAll(list); return from(map); } }