/** * Get all elements associated with the given key. * * @param key key to look up * @return a collection of elements found, or null if {@code contains(key) == false} */ @SuppressWarnings("unchecked") // index is a MultiMap which returns a Collection public Collection<C> values(final K key) { return (Collection<C>) index.get(key); }
/** * Populates a MultiMap using the supplied <code>Transformer</code>s to transform the elements * into keys and values. * * @param <K> the key type * @param <V> the value type * @param <E> the type of object contained in the {@link Iterable} * @param map the <code>MultiMap</code> to populate. * @param elements the <code>Iterable</code> containing the input values for the map. * @param keyTransformer the <code>Transformer</code> used to transform the element into a key value * @param valueTransformer the <code>Transformer</code> used to transform the element into a value * @throws NullPointerException if the map, collection or transformers are null */ public static <K, V, E> void populateMap(final MultiMap<K, V> map, final Iterable<? extends E> elements, final Transformer<E, K> keyTransformer, final Transformer<E, V> valueTransformer) { final Iterator<? extends E> iter = elements.iterator(); while (iter.hasNext()) { final E temp = iter.next(); map.put(keyTransformer.transform(temp), valueTransformer.transform(temp)); } }
@Override public void clear() { super.clear(); index.clear(); }
/** * Provides checking for adding the index. * * @param object the object to index * @throws IllegalArgumentException if the object maps to an existing key and the index * enforces a uniqueness constraint */ private void addToIndex(final C object) { final K key = keyTransformer.transform(object); if (uniqueIndex && index.containsKey(key)) { throw new IllegalArgumentException("Duplicate key in uniquely indexed collection."); } index.put(key, object); }
/** * Method used to find ATR description from ATS (Answer to select) * * @param pAts * EMV card ATS * @return card description */ @SuppressWarnings("unchecked") public static final Collection<String> getDescriptionFromAts(final String pAts) { Collection<String> ret = null; if (StringUtils.isNotBlank(pAts)) { String val = StringUtils.deleteWhitespace(pAts); for (String key : MAP.keySet()) { if (key.contains(val)) { // TODO Fix this ret = (Collection<String>) MAP.get(key); break; } } } return ret; }
public InMemoryCachedEntry(byte[] out, String contentType, String characterEncoding, int statusCode, MultiMap headers, long modificationDate, String originalUrl, int timeToLiveInSeconds) throws IOException { super(contentType, characterEncoding, statusCode, headers, modificationDate, originalUrl, timeToLiveInSeconds); // content which is actually of a compressed type must stay that way if (GZipUtil.isGZipped(out)) { this.gzippedContent = out; boolean isGzippedResponse = headers.containsKey("Content-Encoding") && ((Collection)headers.get("Content-Encoding")).contains("gzip"); if(isGzippedResponse){ this.plainContent = GZipUtil.ungzip(out); } // in case of serving a gzip file (gif for instance) else{ this.plainContent = null; } } else { this.gzippedContent = GZipUtil.gzip(out); this.plainContent = out; } }
/** * {@inheritDoc} * <p> * Note: uses the index for fast lookup */ @SuppressWarnings("unchecked") @Override public boolean contains(final Object object) { return index.containsKey(keyTransformer.transform((C) object)); }
/** * Override superclass to ensure that MultiMap instances are * correctly handled. * <p> * If you call this method with a normal map, each entry is * added using <code>put(Object,Object)</code>. * If you call this method with a multi map, each entry is * added using <code>putAll(Object,Collection)</code>. * * @param map the map to copy (either a normal or multi map) */ @Override @SuppressWarnings("unchecked") public void putAll(final Map<? extends K, ?> map) { if (map instanceof MultiMap) { for (final Map.Entry<? extends K, Object> entry : ((MultiMap<? extends K, V>) map).entrySet()) { putAll(entry.getKey(), (Collection<V>) entry.getValue()); } } else { for (final Map.Entry<? extends K, ?> entry : map.entrySet()) { put(entry.getKey(), entry.getValue()); } } }
/** * Removes an object from the index. * * @param object the object to remove */ private void removeFromIndex(final C object) { index.remove(keyTransformer.transform(object)); }
/** * Method used to find description from ATR * * @param pAtr * Card ATR * @return list of description */ @SuppressWarnings("unchecked") public static final Collection<String> getDescription(final String pAtr) { Collection<String> ret = null; if (StringUtils.isNotBlank(pAtr)) { String val = StringUtils.deleteWhitespace(pAtr); for (String key : MAP.keySet()) { if (val.matches("^" + key + "$")) { ret = (Collection<String>) MAP.get(key); break; } } } return ret; }
@Override public boolean containsHeader(String name) { return headers.containsKey(name); }
private void writeObject(ObjectOutputStream out) throws IOException { serializableHeadersBackingList = new HashMap(); Iterator iter = headers.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Entry) iter.next(); serializableHeadersBackingList.put(entry.getKey(), new ArrayList((Collection)entry.getValue())); } out.defaultWriteObject(); }
/** * Method used to find description from ATR * * @param pAtr * Card ATR * @return list of description */ @SuppressWarnings("unchecked") public static final Collection<String> getDescription(final String pAtr) { Collection<String> ret = null; if (StringUtils.isNotBlank(pAtr)) { String val = StringUtils.deleteWhitespace(pAtr); for (String key : MAP.keySet()) { if (val.matches("^" + key + "$")) { ret = (Collection<String>) MAP.get(key); break; } } } return ret; }
/** * Get the element associated with the given key. * <p> * In case of a non-unique index, this method will return the first * value associated with the given key. To retrieve all elements associated * with a key, use {@link #values(Object)}. * * @param key key to look up * @return element found * @see #values(Object) */ public C get(final K key) { @SuppressWarnings("unchecked") // index is a MultiMap which returns a Collection final Collection<C> coll = (Collection<C>) index.get(key); return coll == null ? null : coll.iterator().next(); }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); headers = new MultiValueMap(); Iterator iter = serializableHeadersBackingList.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Entry) iter.next(); Collection c = (Collection) entry.getValue(); for (Iterator ic = c.iterator(); ic.hasNext();) { headers.put(entry.getKey(), ic.next()); } } serializableHeadersBackingList = null; }
/** * Clears the index and re-indexes the entire decorated {@link Collection}. */ public void reindex() { index.clear(); for (final C c : decorated()) { addToIndex(c); } }
/** * Method used to find ATR description from ATS (Answer to select) * * @param pAts * EMV card ATS * @return card description */ @SuppressWarnings("unchecked") public static final Collection<String> getDescriptionFromAts(final String pAts) { Collection<String> ret = null; if (StringUtils.isNotBlank(pAts)) { String val = StringUtils.deleteWhitespace(pAts); for (String key : MAP.keySet()) { if (key.contains(val)) { // TODO Fix this ret = (Collection<String>) MAP.get(key); break; } } } return ret; }
@SuppressWarnings("unchecked") @Override public List<String> getPronunciations(String word) throws PronouncingDictionaryException { return (List<String>) dict.get(word); }
private void appendHeader(String name, Object value) { if (responseExpirationCalculator != null) { responseExpirationCalculator.addHeader(name, value); } headers.put(name, value); }