/** * 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); }
/** * 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(); }
/** * 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; }
/** * 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; }
@SuppressWarnings("unchecked") @Override public List<String> getPronunciations(String word) throws PronouncingDictionaryException { return (List<String>) dict.get(word); }
@SuppressWarnings("unchecked") @Override public List<String> getPronunciations(String word) throws PronouncingDictionaryException { return (List<String>) dict.get(word.toUpperCase()); }
public long getLastModified() { // we're using a MultiMap. And all this is to workaround code that would possibly set the Last-Modified header with a String value // it will also fail if multiple values have been set. final Collection values = (Collection) headers.get("Last-Modified"); if (values == null || values.size() != 1) { throw new IllegalStateException("Can't get Last-Modified header : no or multiple values : " + values); } final Object value = values.iterator().next(); if (value instanceof String) { return parseStringDate((String) value); } else if (value instanceof Long) { return ((Long) value).longValue(); } else { throw new IllegalStateException("Can't get Last-Modified header : " + value); } }
/** * 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; }
/** * 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 void replayHeadersAndStatus(HttpServletResponse target) throws IOException { if (isError) { if (errorMsg != null) { target.sendError(status, errorMsg); } else { target.sendError(status); } } else if (redirectionLocation != null) { target.sendRedirect(redirectionLocation); } else { target.setStatus(status); } target.setStatus(getStatus()); final Iterator it = headers.keySet().iterator(); while (it.hasNext()) { final String header = (String) it.next(); final Collection values = (Collection) headers.get(header); final Iterator valIt = values.iterator(); while (valIt.hasNext()) { final Object val = valIt.next(); RequestHeaderUtil.setHeader(target, header, val); } } target.setContentType(getContentType()); target.setCharacterEncoding(getCharacterEncoding()); target.setContentLength(getContentLength()); }
final Collection values = (Collection) headers.get(header); final Iterator valIt = values.iterator(); while (valIt.hasNext()) {
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; } }
@Test public void testCacheHeadersAreAddedToTheResponse() throws Exception { // GIVEN final HttpServletRequest request = mock(HttpServletRequest.class); final HttpServletResponse response = mock(HttpServletResponse.class); final DummyFilterChain chain = new DummyFilterChain(); final GZipFilter filter = new GZipFilter(); final ServletOutputStream stream = mock(ServletOutputStream.class); when(response.containsHeader("Content-Encoding")).thenReturn(true); when(response.containsHeader("Vary")).thenReturn(true); when(response.getOutputStream()).thenReturn(stream); filter.doFilter(request, response, chain); final CacheResponseWrapper wrapper = (CacheResponseWrapper) chain.response; // WHEN wrapper.setHeader(CacheConstants.HEADER_CACHE_CONTROL, CacheConstants.HEADER_VALUE_MAX_AGE + ":525600"); wrapper.setHeader(CacheConstants.HEADER_EXPIRES, "someDate"); // THEN MultiMap map = ((CacheResponseWrapper) chain.response).getHeaders(); assertEquals("max-age:525600", ((List<String>) map.get(CacheConstants.HEADER_CACHE_CONTROL)).get(0)); assertEquals("someDate", ((List<String>) map.get(CacheConstants.HEADER_EXPIRES)).get(0)); }
@Test public void testSetHeader() { // set one value - one will be in... String testName = "name"; wrapper.setHeader(testName, "value"); Collection names = (Collection) wrapper.getHeaders().get(testName); assertEquals(1, names.size()); // set another value - only this should be in then wrapper.setHeader(testName, "anotherValue"); names = (Collection) wrapper.getHeaders().get(testName); assertEquals(1, names.size()); }
@Test public void cacheNegotiationHeadersAreNotSwallowedWhenAddingHeader() { //GIVEN wrapper.setResponseExpirationDetectionEnabled(); //WHEN wrapper.addHeader(CacheConstants.HEADER_CACHE_CONTROL, CacheConstants.HEADER_VALUE_NO_CACHE); //THEN assertThat((Collection<String>) wrapper.getHeaders().get(CacheConstants.HEADER_CACHE_CONTROL), hasItem(CacheConstants.HEADER_VALUE_NO_CACHE)); }
@Test public void cacheNegotiationHeadersAreNotSwallowedWhenSettingHeader() { //GIVEN wrapper.setResponseExpirationDetectionEnabled(); //WHEN wrapper.setHeader(CacheConstants.HEADER_CACHE_CONTROL, CacheConstants.HEADER_VALUE_NO_CACHE); //THEN assertThat((Collection<String>) wrapper.getHeaders().get(CacheConstants.HEADER_CACHE_CONTROL), hasItem(CacheConstants.HEADER_VALUE_NO_CACHE)); }