Example usage for java.util Collections emptyMap

List of usage examples for java.util Collections emptyMap

Introduction

In this page you can find the example usage for java.util Collections emptyMap.

Prototype

@SuppressWarnings("unchecked")
public static final <K, V> Map<K, V> emptyMap() 

Source Link

Document

Returns an empty map (immutable).

Usage

From source file:com.google.android.gcm.demo.server.Datastore.java

/**
 * Saves the Alerts/*from   www.j  a  va  2s .c  o  m*/
 * 
 * @param from
 * @param alertMessage
 */
public static void saveAlert(String from, String alertMessage) {
    logger.info("Saving alert from " + from);
    Transaction txn = datastore.beginTransaction();
    try {
        Entity entity = null;
        entity = new Entity(ALERTS);
        entity.setProperty(ALERT_FROM, from);
        entity.setProperty(ALERT_MESSAGE, alertMessage);
        entity.setProperty(ALERT_TIME, new Date());
        datastore.put(entity);
        txn.commit();

        CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();
        Cache cache = cacheFactory.createCache(Collections.emptyMap());
        cache.clear();
    } catch (CacheException e) {
        e.printStackTrace();
    } finally {
        if (txn.isActive()) {
            txn.rollback();
        }
    }
}

From source file:edu.wisc.hrs.dao.absbal.SoapAbsenceBalanceDao.java

@Override
@Cacheable(cacheName = "absenceBalance", exceptionCacheName = "hrsUnknownExceptionCache")
public List<AbsenceBalance> getAbsenceBalance(String emplId) {
    final GetCompIntfcUWPORTAL1ABSBAL request = this.createRequest(emplId);

    final GetCompIntfcUWPORTAL1ABSBALResponse response = this.internalInvoke(request);

    final PersonInformation personalData = this.contactInfoDao.getPersonalData(emplId);
    final Map<Integer, Job> jobMap;
    if (personalData == null) {
        jobMap = Collections.emptyMap();
    } else {/*  ww  w  .ja  va 2 s .c o m*/
        jobMap = personalData.getJobMap();
    }

    return this.convertAbsenceBalance(response, jobMap);
}

From source file:hudson.plugins.mercurial.MercurialSCMHeadEvent.java

@NonNull
@Override/* w  w  w . j a v  a  2  s .c  o m*/
public Map<SCMHead, SCMRevision> heads(@NonNull SCMSource source) {
    if (source instanceof MercurialSCMSource) {
        MercurialSCMSource hg = (MercurialSCMSource) source;
        String repository = hg.getSource();
        if (repository != null) {
            if (MercurialStatus.looselyMatches(payload.getUrl(), repository)) {
                SCMHead head = new SCMHead(getPayload().getBranch());
                SCMRevision revision = new MercurialSCMSource.MercurialRevision(head,
                        getPayload().getChangesetId());
                return Collections.singletonMap(head, revision);
            }
        }
    }
    return Collections.emptyMap();
}

From source file:cn.com.xxutils.volley.toolbox.BasicNetwork.java

@Override
public NetworkResponse performRequest(Request<?> request) throws VolleyError {
    long requestStart = SystemClock.elapsedRealtime();
    while (true) {
        HttpResponse httpResponse = null;
        byte[] responseContents = null;
        Map<String, String> responseHeaders = Collections.emptyMap();
        try {//from  w  w w.j av a  2s. com
            // Gather headers.
            Map<String, String> headers = new HashMap<String, String>();
            addCacheHeaders(headers, request.getCacheEntry());
            httpResponse = mHttpStack.performRequest(request, headers);
            StatusLine statusLine = httpResponse.getStatusLine();
            int statusCode = statusLine.getStatusCode();

            responseHeaders = convertHeaders(httpResponse.getAllHeaders());
            // Handle cache validation.
            if (statusCode == HttpStatus.SC_NOT_MODIFIED) {

                Cache.Entry entry = request.getCacheEntry();
                if (entry == null) {
                    return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, null, responseHeaders, true,
                            SystemClock.elapsedRealtime() - requestStart);
                }

                // A HTTP 304 response does not have all header fields. We
                // have to use the header fields from the cache entry plus
                // the new ones from the response.
                // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
                entry.responseHeaders.putAll(responseHeaders);
                return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, entry.data, entry.responseHeaders, true,
                        SystemClock.elapsedRealtime() - requestStart);
            }

            // Some responses such as 204s do not have content.  We must check.
            if (httpResponse.getEntity() != null) {
                responseContents = entityToBytes(httpResponse.getEntity());
            } else {
                // Add 0 byte response as a way of honestly representing a
                // no-content request.
                responseContents = new byte[0];
            }

            // if the request is slow, log it.
            long requestLifetime = SystemClock.elapsedRealtime() - requestStart;
            logSlowRequests(requestLifetime, request, responseContents, statusLine);

            if (statusCode < 200 || statusCode > 299) {
                throw new IOException();
            }
            return new NetworkResponse(statusCode, responseContents, responseHeaders, false,
                    SystemClock.elapsedRealtime() - requestStart);
        } catch (SocketTimeoutException e) {
            attemptRetryOnException("socket", request, new TimeoutError());
        } catch (ConnectTimeoutException e) {
            attemptRetryOnException("connection", request, new TimeoutError());
        } catch (MalformedURLException e) {
            throw new RuntimeException("Bad URL " + request.getUrl(), e);
        } catch (IOException e) {
            int statusCode = 0;
            NetworkResponse networkResponse = null;
            if (httpResponse != null) {
                statusCode = httpResponse.getStatusLine().getStatusCode();
            } else {
                throw new NoConnectionError(e);
            }
            VolleyLog.e("Unexpected response code %d for %s", statusCode, request.getUrl());
            if (responseContents != null) {
                networkResponse = new NetworkResponse(statusCode, responseContents, responseHeaders, false,
                        SystemClock.elapsedRealtime() - requestStart);
                if (statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN) {
                    attemptRetryOnException("auth", request, new AuthFailureError(networkResponse));
                } else {
                    // TODO: Only throw ServerError for 5xx status codes.
                    throw new ServerError(networkResponse);
                }
            } else {
                throw new NetworkError(networkResponse);
            }
        }
    }
}

From source file:com.android.volley.toolbox.BasicNetwork.java

@Override
public NetworkResponse performRequest(Request<?> request) throws VolleyError {
    long requestStart = SystemClock.elapsedRealtime();
    while (true) {
        HttpResponse httpResponse = null;
        byte[] responseContents = null;
        Map<String, String> responseHeaders = Collections.emptyMap();
        try {/* w w  w.j  a va2s  .co  m*/
            // Gather headers.
            Map<String, String> headers = new HashMap<String, String>();
            addCacheHeaders(headers, request.getCacheEntry());
            httpResponse = mHttpStack.performRequest(request, headers);
            StatusLine statusLine = httpResponse.getStatusLine();
            int statusCode = statusLine.getStatusCode();

            responseHeaders = convertHeaders(httpResponse.getAllHeaders());
            // Handle cache validation.
            if (statusCode == HttpStatus.SC_NOT_MODIFIED) {

                Entry entry = request.getCacheEntry();
                if (entry == null) {
                    return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, null, responseHeaders, true,
                            SystemClock.elapsedRealtime() - requestStart);
                }

                // A HTTP 304 response does not have all header fields. We
                // have to use the header fields from the cache entry plus
                // the new ones from the response.
                // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
                entry.responseHeaders.putAll(responseHeaders);
                return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, entry.data, entry.responseHeaders, true,
                        SystemClock.elapsedRealtime() - requestStart);
            }

            // Some responses such as 204s do not have content.  We must check.
            if (httpResponse.getEntity() != null) {
                responseContents = entityToBytes(httpResponse.getEntity());
            } else {
                // Add 0 byte response as a way of honestly representing a
                // no-content request.
                responseContents = new byte[0];
            }

            // if the request is slow, log it.
            long requestLifetime = SystemClock.elapsedRealtime() - requestStart;
            logSlowRequests(requestLifetime, request, responseContents, statusLine);

            if (statusCode < 200 || statusCode > 299) {
                throw new IOException();
            }
            return new NetworkResponse(statusCode, responseContents, responseHeaders, false,
                    SystemClock.elapsedRealtime() - requestStart);
        } catch (SocketTimeoutException e) {
            attemptRetryOnException("socket", request, new TimeoutError());
        } catch (ConnectTimeoutException e) {
            attemptRetryOnException("connection", request, new TimeoutError());
        } catch (MalformedURLException e) {
            throw new RuntimeException("Bad URL " + request.getUrl(), e);
        } catch (IOException e) {
            int statusCode = 0;
            NetworkResponse networkResponse = null;
            if (httpResponse != null) {
                statusCode = httpResponse.getStatusLine().getStatusCode();
            } else {
                throw new NoConnectionError(e);
            }
            VolleyLog.e("Unexpected response code %d for %s", statusCode, request.getUrl());
            if (responseContents != null) {
                networkResponse = new NetworkResponse(statusCode, responseContents, responseHeaders, false,
                        SystemClock.elapsedRealtime() - requestStart);
                if (statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN) {
                    attemptRetryOnException("auth", request, new AuthFailureError(networkResponse));
                } else {
                    // TODO: Only throw ServerError for 5xx status codes.
                    throw new ServerError(networkResponse);
                }
            } else {
                throw new NetworkError(networkResponse);
            }
        }
    }
}

From source file:io.cloudslang.lang.systemtests.BindingScopeTest.java

@Test
public void testInputMissing() throws Exception {
    URL resource = getClass().getResource("/yaml/check_weather_missing_input.sl");
    CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource.toURI()),
            new HashSet<SlangSource>());

    Map<String, Value> userInputs = Collections.emptyMap();
    Set<SystemProperty> systemProperties = Collections.emptySet();

    exception.expect(RuntimeException.class);

    exception.expectMessage(new BaseMatcher<String>() {
        public void describeTo(Description description) {
        }/*from  w  ww.j a  v  a 2s .  c  o  m*/

        public boolean matches(Object o) {
            String message = o.toString();
            return message.contains("Error running: 'check_weather_missing_input'")
                    && message.contains("Error binding input: 'input_get_missing_input'")
                    && message.contains("Error is: Error in running script expression: 'missing_input'")
                    && message.contains("Exception is: name 'missing_input' is not defined");
        }
    });
    triggerWithData(compilationArtifact, userInputs, systemProperties);
}

From source file:com.volley.toolbox.BasicNetwork.java

/**
 * //from  w ww .j a  v a  2  s  .c  o  m
 * @param request Request to process ??
 * @return
 * @throws VolleyError
 */
@Override
public NetworkResponse performRequest(Request<?> request) throws VolleyError {
    long requestStart = SystemClock.elapsedRealtime();
    while (true) {
        HttpResponse httpResponse = null;
        byte[] responseContents = null;
        Map<String, String> responseHeaders = Collections.emptyMap();
        try {
            // Gather headers.
            Map<String, String> headers = new HashMap<String, String>();
            addCacheHeaders(headers, request.getCacheEntry());
            httpResponse = mHttpStack.performRequest(request, headers);
            StatusLine statusLine = httpResponse.getStatusLine();
            int statusCode = statusLine.getStatusCode();

            responseHeaders = convertHeaders(httpResponse.getAllHeaders());
            // Handle cache validation.
            if (statusCode == HttpStatus.SC_NOT_MODIFIED) {

                Cache.Entry entry = request.getCacheEntry();
                if (entry == null) {
                    return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, null, responseHeaders, true,
                            SystemClock.elapsedRealtime() - requestStart);
                }

                // A HTTP 304 response does not have all header fields. We
                // have to use the header fields from the cache entry plus
                // the new ones from the response.
                // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
                entry.responseHeaders.putAll(responseHeaders);
                return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, entry.data, entry.responseHeaders, true,
                        SystemClock.elapsedRealtime() - requestStart);
            }

            // Some responses such as 204s do not have content.  We must check.
            if (httpResponse.getEntity() != null) {
                responseContents = entityToBytes(httpResponse.getEntity());
            } else {
                // Add 0 byte response as a way of honestly representing a
                // no-content request.
                responseContents = new byte[0];
            }

            // if the request is slow, log it.
            long requestLifetime = SystemClock.elapsedRealtime() - requestStart;
            logSlowRequests(requestLifetime, request, responseContents, statusLine);

            if (statusCode < 200 || statusCode > 299) {
                throw new IOException();
            }
            return new NetworkResponse(statusCode, responseContents, responseHeaders, false,
                    SystemClock.elapsedRealtime() - requestStart);
        } catch (SocketTimeoutException e) {
            attemptRetryOnException("socket", request, new TimeoutError());
        } catch (ConnectTimeoutException e) {
            attemptRetryOnException("connection", request, new TimeoutError());
        } catch (MalformedURLException e) {
            throw new RuntimeException("Bad URL " + request.getUrl(), e);
        } catch (IOException e) {
            int statusCode = 0;
            NetworkResponse networkResponse = null;
            if (httpResponse != null) {
                statusCode = httpResponse.getStatusLine().getStatusCode();
            } else {
                throw new NoConnectionError(e);
            }
            VolleyLog.e("Unexpected response code %d for %s", statusCode, request.getUrl());
            if (responseContents != null) {
                networkResponse = new NetworkResponse(statusCode, responseContents, responseHeaders, false,
                        SystemClock.elapsedRealtime() - requestStart);
                if (statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN) {
                    attemptRetryOnException("auth", request, new AuthFailureError(networkResponse));
                } else {
                    // TODO: Only throw ServerError for 5xx status codes.
                    throw new ServerError(networkResponse);
                }
            } else {
                throw new NetworkError(networkResponse);
            }
        }
    }
}

From source file:com.arpnetworking.metrics.vertx.SinkHandlerTest.java

@Test
public void testHandleWithMessageWithoutTimerSamples() throws JsonProcessingException {
    final String messageBody = OBJECT_MAPPER
            .writeValueAsString(ImmutableMap.of(ANNOTATIONS_KEY, Collections.emptyMap(), COUNTER_SAMPLES_KEY,
                    Collections.emptyMap(), GAUGE_SAMPLES_KEY, Collections.emptyMap()));
    Mockito.doReturn(messageBody).when(_message).body();
    _handler.handle(_message);// ww  w  .  j  av  a 2  s .c o  m
    Mockito.verifyZeroInteractions(_mockSink);
}

From source file:io.hops.erasure_coding.Codec.java

public static void initializeCodecs(Configuration conf) throws IOException {
    try {//w w  w  . j a v  a  2  s.co m
        String source = conf.get(DFSConfigKeys.ERASURE_CODING_CODECS_KEY);
        if (source == null) {
            codecs = Collections.emptyList();
            idToCodec = Collections.emptyMap();
            if (LOG.isDebugEnabled()) {
                LOG.info("No codec is specified");
            }
            return;
        }
        JSONArray jsonArray = new JSONArray(source);
        List<Codec> localCodecs = new ArrayList<>();
        Map<String, Codec> localIdToCodec = new HashMap<>();
        for (int i = 0; i < jsonArray.length(); ++i) {
            Codec codec = new Codec(jsonArray.getJSONObject(i));
            localIdToCodec.put(codec.id, codec);
            localCodecs.add(codec);
        }
        Collections.sort(localCodecs, new Comparator<Codec>() {
            @Override
            public int compare(Codec c1, Codec c2) {
                // Higher priority on top
                return c2.priority - c1.priority;
            }
        });
        codecs = Collections.unmodifiableList(localCodecs);
        idToCodec = Collections.unmodifiableMap(localIdToCodec);
    } catch (JSONException e) {
        throw new IOException(e);
    }
}