@MapFeature.Require(SUPPORTS_PUT) @CollectionSize.Require(absent = ZERO) public void testPutPresentKeyPropagatesToAsMapEntrySet() { List<K> keys = Helpers.copyToList(multimap().keySet()); for (K key : keys) { resetContainer(); int size = getNumElements(); Iterator<Entry<K, Collection<V>>> asMapItr = multimap().asMap().entrySet().iterator(); Collection<V> collection = null; while (asMapItr.hasNext()) { Entry<K, Collection<V>> asMapEntry = asMapItr.next(); if (key.equals(asMapEntry.getKey())) { collection = asMapEntry.getValue(); break; } } assertNotNull(collection); Collection<V> expectedCollection = Helpers.copyToList(collection); multimap().put(key, sampleValues().e3); expectedCollection.add(sampleValues().e3); assertThat(collection).has().exactlyAs(expectedCollection); assertEquals(size + 1, multimap().size()); } }
protected K getPeriodicalWithFakeDates(K periodical, Date beginDate, Date endDate) throws CloneNotSupportedException { K partOfPeriodical = (K) periodical.clone(); partOfPeriodical.setBeginDate(beginDate); partOfPeriodical.setEndDate(endDate); return partOfPeriodical; }
public static <K extends BaseFuture> FutureDone<K[]> whenAllSuccess(final K... all) { final AtomicInteger counter = new AtomicInteger(); final int size = all.length; final FutureDone<K[]> futureDone = new FutureDone<K[]>(); for (final K future : all) { future.addListener( new BaseFutureAdapter<K>() { @Override public void operationComplete(final K future) throws Exception { if (futureDone.isCompleted()) { return; } if (future.isFailed()) { // at least one future failed futureDone.failed(future); } else if (counter.incrementAndGet() == size) { futureDone.done(all); } } }); } return futureDone; }
protected boolean periodicalIsFullyInPeriod( Date periodBeginDate, Date periodEndDate, K periodical) { return (periodical.getBeginDate().after(periodBeginDate) || DateUtils.isSameDay(periodical.getBeginDate(), periodBeginDate)) && (periodical.getEndDate().before(periodEndDate) || (DateUtils.isSameDay(periodical.getEndDate(), periodEndDate))); }
/** * Associate the specified value with the specified key in this {@code Hashtable}. If the key * already exists, the old value is replaced. The key and value cannot be null. * * @param key the key to add. * @param value the value to add. * @return the old value associated with the specified key, or {@code null} if the key did not * exist. * @see #elements * @see #get * @see #keys * @see java.lang.Object#equals */ public synchronized V put(K key, V value) { if (key == null) { throw new NullPointerException("key == null"); } else if (value == null) { throw new NullPointerException("value == null"); } int hash = secondaryHash(key.hashCode()); HashtableEntry<K, V>[] tab = table; int index = hash & (tab.length - 1); HashtableEntry<K, V> first = tab[index]; for (HashtableEntry<K, V> e = first; e != null; e = e.next) { if (e.hash == hash && key.equals(e.key)) { V oldValue = e.value; e.value = value; return oldValue; } } // No entry for key is present; create one modCount++; if (size++ > threshold) { rehash(); // Does nothing!! tab = doubleCapacity(); index = hash & (tab.length - 1); first = tab[index]; } tab[index] = new HashtableEntry<K, V>(key, value, hash, first); return null; }
/** * Get the behaviour for the activity specified * * @param toActivity the activity to get the activity for * @param <K> the type of the activity * @return the behaviour or null if no behaviour was found */ public <K extends IActivity> Behaviour<K> getBehaviourFor(K toActivity) { // First check for a live behaviour if (m_oActivityMap != null && m_oActivityMap.containsKey(toActivity)) { return (Behaviour<K>) m_oActivityMap.get(toActivity); } if (m_oBehaviourMap != null && m_oBehaviourMap.containsKey(toActivity.getClass())) { List<Class<? extends Behaviour<? extends IActivity>>> loBehaviours = m_oBehaviourMap.get(toActivity.getClass()); for (Class<? extends Behaviour<? extends IActivity>> loBehaviourClass : loBehaviours) { try { Behaviour<K> loBehaviour = (Behaviour<K>) loBehaviourClass.newInstance(); if (loBehaviour.isValid(toActivity)) { if (m_oActivityMap == null) { m_oActivityMap = new HashMap<IActivity, Behaviour<? extends IActivity>>(); } m_oActivityMap.put(toActivity, loBehaviour); return loBehaviour; } } catch (InstantiationException ex) { Application.log(ex); } catch (IllegalAccessException ex) { Application.log(ex); } } } return null; }
@Override public boolean contains(Object aObject) { for (K aKey : this) { if (aObject == null ? aKey == null : aKey.equals(aObject)) return true; } return false; }
@SuppressWarnings({"unchecked", "rawtypes", "unused"}) @Override public V put(K key, V value) { K k = (K) maskNull(key); int h = HashMap.hash(k.hashCode()); Entry[] tab = getTable(); int i = indexFor(h, tab.length); for (Entry<K, V> e = tab[i]; e != null; e = e.next) { if (h == e.hash && eq(k, e.get())) { V oldValue = e.value; if (value != oldValue) { e.value = value; } return oldValue; } } modCount++; Entry<K, V> e = tab[i]; // tab[i] = new Entry<K,V>(k, value, queue, h, e); if (++size >= threshold) { resize(tab.length * 2); } return null; }
/** * Returns the string representation of this {@code Hashtable}. * * @return the string representation of this {@code Hashtable}. */ @Override public synchronized String toString() { StringBuilder result = new StringBuilder(CHARS_PER_ENTRY * size); result.append('{'); Iterator<Entry<K, V>> i = entrySet().iterator(); boolean hasMore = i.hasNext(); while (hasMore) { Entry<K, V> entry = i.next(); K key = entry.getKey(); result.append(key == this ? "(this Map)" : key.toString()); result.append('='); V value = entry.getValue(); result.append(value == this ? "(this Map)" : value.toString()); if (hasMore = i.hasNext()) { result.append(", "); } } result.append('}'); return result.toString(); }
/** Implement InputOperator Interface. */ @Override public void emitTuples() { int bufferLength = consumer.messageSize(); for (int i = tuplesBlast < bufferLength ? tuplesBlast : bufferLength; i-- > 0; ) { emitTuple(consumer.pollMessage()); } }
@MapFeature.Require(SUPPORTS_REMOVE) @CollectionSize.Require(absent = ZERO) public void testRemovePropagatesToAsMapEntrySet() { List<Entry<K, V>> entries = Helpers.copyToList(multimap().entries()); for (Entry<K, V> entry : entries) { resetContainer(); K key = entry.getKey(); V value = entry.getValue(); Iterator<Entry<K, Collection<V>>> asMapItr = multimap().asMap().entrySet().iterator(); Collection<V> collection = null; while (asMapItr.hasNext()) { Entry<K, Collection<V>> asMapEntry = asMapItr.next(); if (key.equals(asMapEntry.getKey())) { collection = asMapEntry.getValue(); break; } } assertNotNull(collection); Collection<V> expectedCollection = Helpers.copyToList(collection); multimap().remove(key, value); expectedCollection.remove(value); ASSERT.that(collection).hasContentsAnyOrder(expectedCollection.toArray()); assertEquals(!expectedCollection.isEmpty(), multimap().containsKey(key)); } }
@Override public V remove(final Object key) { final Entry<K, V>[] table = this.table; final int hash = key.hashCode(); final int index = HashUtil.indexFor(hash, table.length, shift, mask); Entry<K, V> e = table[index]; if (e == null) return null; K entryKey; if (e.keyHash == hash && ((entryKey = e.key) == key || entryKey.equals(key))) { table[index] = e.hashNext; } else { for (; ; ) { final Entry<K, V> last = e; e = e.hashNext; if (e == null) return null; if (e.keyHash == hash && ((entryKey = e.key) == key || entryKey.equals(key))) { last.hashNext = e.hashNext; break; } } } unlink(e); size = size - 1; return e.value; }
@Override public V put(final K key, final V value) { final Entry<K, V>[] table = this.table; final int hash = key.hashCode(); final int index = HashUtil.indexFor(hash, table.length, shift, mask); for (Entry<K, V> e = table[index]; e != null; e = e.hashNext) { final K entryKey; if (e.keyHash == hash && ((entryKey = e.key) == key || entryKey.equals(key))) { moveToTop(e); return e.setValue(value); } } final Entry<K, V> e = new Entry<K, V>(key, value); e.hashNext = table[index]; table[index] = e; final Entry<K, V> top = this.top; e.next = top; if (top != null) { top.previous = e; } else { back = e; } this.top = e; size = size + 1; if (removeEldestEntry(back)) { remove(back.key); } else if (size > capacity) { rehash(HashUtil.nextCapacity(capacity)); } return null; }
public V remove(K key) { int hashCode = key.hashCode(); int index = hashCode & mask; if (key.equals(keyTable[index])) { keyTable[index] = null; V oldValue = valueTable[index]; valueTable[index] = null; size--; return oldValue; } index = hash2(hashCode); if (key.equals(keyTable[index])) { keyTable[index] = null; V oldValue = valueTable[index]; valueTable[index] = null; size--; return oldValue; } index = hash3(hashCode); if (key.equals(keyTable[index])) { keyTable[index] = null; V oldValue = valueTable[index]; valueTable[index] = null; size--; return oldValue; } return removeStash(key); }
public int remove(K key, int defaultValue) { int hashCode = key.hashCode(); int index = hashCode & mask; if (key.equals(keyTable[index])) { keyTable[index] = null; int oldValue = valueTable[index]; size--; return oldValue; } index = hash2(hashCode); if (key.equals(keyTable[index])) { keyTable[index] = null; int oldValue = valueTable[index]; size--; return oldValue; } index = hash3(hashCode); if (key.equals(keyTable[index])) { keyTable[index] = null; int oldValue = valueTable[index]; size--; return oldValue; } return removeStash(key, defaultValue); }
public void put(K key, float value) { if (key == null) throw new IllegalArgumentException("key cannot be null."); K[] keyTable = this.keyTable; // Check for existing keys. int hashCode = key.hashCode(); int index1 = hashCode & mask; K key1 = keyTable[index1]; if (key.equals(key1)) { valueTable[index1] = value; return; } int index2 = hash2(hashCode); K key2 = keyTable[index2]; if (key.equals(key2)) { valueTable[index2] = value; return; } int index3 = hash3(hashCode); K key3 = keyTable[index3]; if (key.equals(key3)) { valueTable[index3] = value; return; } // Update key in the stash. for (int i = capacity, n = i + stashSize; i < n; i++) { if (key.equals(keyTable[i])) { valueTable[i] = value; return; } } // Check for empty buckets. if (key1 == null) { keyTable[index1] = key; valueTable[index1] = value; if (size++ >= threshold) resize(capacity << 1); return; } if (key2 == null) { keyTable[index2] = key; valueTable[index2] = value; if (size++ >= threshold) resize(capacity << 1); return; } if (key3 == null) { keyTable[index3] = key; valueTable[index3] = value; if (size++ >= threshold) resize(capacity << 1); return; } push(key, value, index1, key1, index2, key2, index3, key3); }
private static <K, V> void rewriteKeys(Map<K, V> map, Function<K, K> keyRewriter) { for (K key : ImmutableSet.copyOf(map.keySet())) { K newKey = keyRewriter.apply(key); if (!newKey.equals(key)) { map.put(newKey, map.remove(key)); } } }
public com.jcumulus.server.rtmfp.stream.BinaryWriter A(boolean flag) { K k = H(); if (!flag) { k.E().B((byte) 4); k.E().A(0); } return k.E(); }
private T addCommonPartOfPartOfPeriodicleToMounthStatistics( T report, K periodical, Date beginDate, Date endDate) throws CloneNotSupportedException { K partOfPeriodical = getPeriodicalWithFakeDates(periodical, beginDate, endDate); report = addCommonPartOfPeriodicleToMounthStatistics(report, partOfPeriodical); replaseFakeDatesWithRealDates( partOfPeriodical, periodical.getBeginDate(), periodical.getEndDate()); return report; }
public com.jcumulus.server.rtmfp.flow.F B(String s) { K k = H(); k.E().B((byte) 15); k.E().B((byte) 0); k.E().A(0); k.F().A(s); return k.F(); }
/** * Queries whether this task is canceled. A task is considered canceled if it or any of its * parents have been canceled. * * @return {@code true} if this task or any parent is canceled. */ protected boolean taskCanceled() { boolean cancel = canceled; if (!cancel) { for (K parent = getParent(); !cancel && parent != null; parent = parent.getParent()) cancel = parent.canceled; } return cancel; }
@Override public boolean exists(K pk) { for (K ck : this) { if (ck.equals(pk)) { return true; } } return false; }
@NotNull public HashPMap<K, V> plus(K key, V value) { ConsPStack<MapEntry<K, V>> entries = getEntries(key.hashCode()); int size0 = entries.size(); int i = keyIndexIn(entries, key); if (i != -1) entries = entries.minus(i); entries = entries.plus(new MapEntry<K, V>(key, value)); return new HashPMap<K, V>(intMap.plus(key.hashCode(), entries), size - size0 + entries.size()); }
@Override public boolean add(K k) { if (k == null) throw new NullPointerException(); boolean retVal = !bitSet.get(k.getOrdinal()); if (retVal) { bitSet.set(k.getOrdinal()); size++; } return retVal; }
/** Vrati hodnotu asociovanou s danym klicem nebo null, pokud dany klic v tabulce neni. */ V get(K key) { if (storage[key.hashCode() % storage.length].isEmpty()) return null; Iterator iter = storage[key.hashCode() % storage.length].iterator(); while (iter.hasNext()) { Pair<K, V> temp = (Pair<K, V>) iter.next(); if (temp.key.equals(key)) { return temp.value; } } return null; }
/* @ensures \result = (\forall Object x1,x2; map.getSet().contains(x1) && map.keySet().contains(x2) && x1 != x2; map.get(x1) != map.get(x2)); */ public static <K, V> boolean isOneOnOne(Map<K, V> map) { boolean ans = true; for (K key : map.keySet()) { for (K key2 : map.keySet()) { if (!key.equals(key2)) { if (map.get(key).equals(map.get(key2))) ans = false; } } } return ans; }
public void put(K key, int value) { if (key == null) throw new IllegalArgumentException("key cannot be null."); // Check for existing keys. int hashCode = key.hashCode(); int index1 = hashCode & mask; K key1 = keyTable[index1]; if (key.equals(key1)) { int oldValue = valueTable[index1]; valueTable[index1] = value; return; } int index2 = hash2(hashCode); K key2 = keyTable[index2]; if (key.equals(key2)) { int oldValue = valueTable[index2]; valueTable[index2] = value; return; } int index3 = hash3(hashCode); K key3 = keyTable[index3]; if (key.equals(key3)) { int oldValue = valueTable[index3]; valueTable[index3] = value; return; } // Check for empty buckets. if (key1 == null) { keyTable[index1] = key; valueTable[index1] = value; if (size++ >= threshold) resize(capacity << 1); return; } if (key2 == null) { keyTable[index2] = key; valueTable[index2] = value; if (size++ >= threshold) resize(capacity << 1); return; } if (key3 == null) { keyTable[index3] = key; valueTable[index3] = value; if (size++ >= threshold) resize(capacity << 1); return; } push(key, value, index1, key1, index2, key2, index3, key3); return; }
@Override public boolean containsKey(Object keyo) { try { K key = (K) Objects.requireNonNull(keyo); AHTMapEntry<K, V> e = new AHTMapEntry<>(key, null); int hash = key.hashCode(); int[] address = address(hash); return find(e, hash, address).precise; } catch (ClassCastException ex) { return false; } }
public V put(K key, V value) { memcachedClient.set(key.toString(), NOT_EXPIRE, value); // Key index update if (!keySet().contains(key)) { String index = (String) get(name + KEYS_LOCATION); index = index + key.toString() + KEY_SEPARATOR; memcachedClient.set(name + KEYS_LOCATION, NOT_EXPIRE, index); } return value; }
@Override public boolean remove(Object o) { if (o == null) return false; K k = (K) o; boolean retVal = bitSet.get(k.getOrdinal()); if (retVal) { bitSet.set(k.getOrdinal(), false); size--; } return retVal; }