/** * Is the key equal to the combined key. * * @param entry the entry to compare to * @param key1 the first key * @param key2 the second key * @return true if the key matches */ protected boolean isEqualKey(final AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, final Object key1, final Object key2) { final MultiKey<? extends K> multi = entry.getKey(); return multi.size() == 2 && (key1 == multi.getKey(0) || key1 != null && key1.equals(multi.getKey(0))) && (key2 == multi.getKey(1) || key2 != null && key2.equals(multi.getKey(1))); }
/** * Recalculate the hash code after deserialization. The hash code of some * keys might have change (hash codes based on the system hash code are * only stable for the same process). * @return the instance with recalculated hash code */ protected Object readResolve() { calculateHashCode(keys); return this; } }
/** * Stores the value against the specified multi-key. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @param value the value to store * @return the value previously mapped to this combined key, null if none */ public V put(final K key1, final K key2, final K key3, final K key4, final V value) { final int hashCode = hash(key1, key2, key3, key4); final int index = decorated().hashIndex(hashCode, decorated().data.length); AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4)) { final V oldValue = entry.getValue(); decorated().updateEntry(entry, value); return oldValue; } entry = entry.next; } decorated().addMapping(index, hashCode, new MultiKey<>(key1, key2, key3, key4), value); return null; }
public Licence getLicence(Metier metier, Month month) { Licence result = null; for (MapIterator i=list.mapIterator(); i.hasNext();) { MultiKey keys = (MultiKey)i.next(); Metier metierKey = (Metier)keys.getKey(0); Month firstMonth = (Month)keys.getKey(1); Month lastMonth = (Month)keys.getKey(2); if (metier.equals(metierKey) && firstMonth.compareTo(month) <= 0 && month.compareTo(lastMonth) <= 0) { result = (Licence)i.getValue(); break; } } return result; }
/** * Stores the value against the specified multi-key. * * @param key1 the first key * @param key2 the second key * @param value the value to store * @return the value previously mapped to this combined key, null if none */ public V put(final K key1, final K key2, final V value) { final int hashCode = hash(key1, key2); final int index = decorated().hashIndex(hashCode, decorated().data.length); AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2)) { final V oldValue = entry.getValue(); decorated().updateEntry(entry, value); return oldValue; } entry = entry.next; } decorated().addMapping(index, hashCode, new MultiKey<>(key1, key2), value); return null; }
/** * Is the key equal to the combined key. * * @param entry the entry to compare to * @param key1 the first key * @param key2 the second key * @param key3 the third key * @return true if the key matches */ protected boolean isEqualKey(final AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, final Object key1, final Object key2, final Object key3) { final MultiKey<? extends K> multi = entry.getKey(); return multi.size() == 3 && (key1 == multi.getKey(0) || key1 != null && key1.equals(multi.getKey(0))) && (key2 == multi.getKey(1) || key2 != null && key2.equals(multi.getKey(1))) && (key3 == multi.getKey(2) || key3 != null && key3.equals(multi.getKey(2))); }
/** * Stores the value against the specified multi-key. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param value the value to store * @return the value previously mapped to this combined key, null if none */ public V put(final K key1, final K key2, final K key3, final V value) { final int hashCode = hash(key1, key2, key3); final int index = decorated().hashIndex(hashCode, decorated().data.length); AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3)) { final V oldValue = entry.getValue(); decorated().updateEntry(entry, value); return oldValue; } entry = entry.next; } decorated().addMapping(index, hashCode, new MultiKey<>(key1, key2, key3), value); return null; }
/** * Is the key equal to the combined key. * * @param entry the entry to compare to * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @return true if the key matches */ protected boolean isEqualKey(final AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, final Object key1, final Object key2, final Object key3, final Object key4) { final MultiKey<? extends K> multi = entry.getKey(); return multi.size() == 4 && (key1 == multi.getKey(0) || key1 != null && key1.equals(multi.getKey(0))) && (key2 == multi.getKey(1) || key2 != null && key2.equals(multi.getKey(1))) && (key3 == multi.getKey(2) || key3 != null && key3.equals(multi.getKey(2))) && (key4 == multi.getKey(3) || key4 != null && key4.equals(multi.getKey(3))); }
/** * Stores the value against the specified multi-key. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @param key5 the fifth key * @param value the value to store * @return the value previously mapped to this combined key, null if none */ public V put(final K key1, final K key2, final K key3, final K key4, final K key5, final V value) { final int hashCode = hash(key1, key2, key3, key4, key5); final int index = decorated().hashIndex(hashCode, decorated().data.length); AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4, key5)) { final V oldValue = entry.getValue(); decorated().updateEntry(entry, value); return oldValue; } entry = entry.next; } decorated().addMapping(index, hashCode, new MultiKey<>(key1, key2, key3, key4, key5), value); return null; }
/** * Is the key equal to the combined key. * * @param entry the entry to compare to * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @param key5 the fifth key * @return true if the key matches */ protected boolean isEqualKey(final AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, final Object key1, final Object key2, final Object key3, final Object key4, final Object key5) { final MultiKey<? extends K> multi = entry.getKey(); return multi.size() == 5 && (key1 == multi.getKey(0) || key1 != null && key1.equals(multi.getKey(0))) && (key2 == multi.getKey(1) || key2 != null && key2.equals(multi.getKey(1))) && (key3 == multi.getKey(2) || key3 != null && key3.equals(multi.getKey(2))) && (key4 == multi.getKey(3) || key4 != null && key4.equals(multi.getKey(3))) && (key5 == multi.getKey(4) || key5 != null && key5.equals(multi.getKey(4))); }
/** * Add forbidden metier, this metier is not remove when {@link #clear()} is called * * @param metier * @param month */ public void addforbiddenMetier(Metier metier, Month month) { forbiddenMetierMonth.add(new MultiKey(metier, month)); }
/** * Removes all mappings where the first four keys are those specified. * <p> * This method removes all the mappings where the <code>MultiKey</code> * has four or more keys, and the first four match those specified. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @return true if any elements were removed */ public boolean removeAll(final Object key1, final Object key2, final Object key3, final Object key4) { boolean modified = false; final MapIterator<MultiKey<? extends K>, V> it = mapIterator(); while (it.hasNext()) { final MultiKey<? extends K> multi = it.next(); if (multi.size() >= 4 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) && (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2))) && (key4 == null ? multi.getKey(3) == null : key4.equals(multi.getKey(3)))) { it.remove(); modified = true; } } return modified; }
public void removeforbiddenMetier(Metier metier, Month month) { forbiddenMetierMonth.remove(new MultiKey(metier, month)); }
/** * Removes all mappings where the first three keys are those specified. * <p> * This method removes all the mappings where the <code>MultiKey</code> * has three or more keys, and the first three match those specified. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @return true if any elements were removed */ public boolean removeAll(final Object key1, final Object key2, final Object key3) { boolean modified = false; final MapIterator<MultiKey<? extends K>, V> it = mapIterator(); while (it.hasNext()) { final MultiKey<? extends K> multi = it.next(); if (multi.size() >= 3 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) && (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2)))) { it.remove(); modified = true; } } return modified; }
/** * Metier is forbidden is can be found in {@link #forbiddenMetier} or in * {@link #forbiddenMetierMonth}. * * @param metier * @param month * @return {@code true} if metier forbidden */ public boolean isForbidden(Metier metier, Month month) { boolean result = forbiddenMetier.contains(metier); if (!result) { result = forbiddenMetierMonth.contains(new MultiKey(metier, month)); } return result; }
/** * Removes all mappings where the first two keys are those specified. * <p> * This method removes all the mappings where the <code>MultiKey</code> * has two or more keys, and the first two match those specified. * * @param key1 the first key * @param key2 the second key * @return true if any elements were removed */ public boolean removeAll(final Object key1, final Object key2) { boolean modified = false; final MapIterator<MultiKey<? extends K>, V> it = mapIterator(); while (it.hasNext()) { final MultiKey<? extends K> multi = it.next(); if (multi.size() >= 2 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1)))) { it.remove(); modified = true; } } return modified; }
private MultiKey createCacheKey(String uri, MultiMap headers, ByteBuf body) { return new MultiKey( uri, headers.entries().stream().map(e -> e.getKey() + ": " + e.getValue()).sorted().collect(Collectors.toList()), body.hashCode() ); }
/** * Removes all mappings where the first key is that specified. * <p> * This method removes all the mappings where the <code>MultiKey</code> * has one or more keys, and the first matches that specified. * * @param key1 the first key * @return true if any elements were removed */ public boolean removeAll(final Object key1) { boolean modified = false; final MapIterator<MultiKey<? extends K>, V> it = mapIterator(); while (it.hasNext()) { final MultiKey<? extends K> multi = it.next(); if (multi.size() >= 1 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0)))) { it.remove(); modified = true; } } return modified; }