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:grails.util.Holders.java

public static Map<?, ?> getFlatConfig() {
    Map<?, ?> flatConfig = get(flatConfigs, "flatConfig");
    return flatConfig == null ? Collections.emptyMap() : flatConfig;
}

From source file:edu.wisc.hrs.dao.abshis.SoapAbsenceHistoryDao.java

@Override
@Cacheable(cacheName = "absenceHistory", exceptionCacheName = "hrsUnknownExceptionCache")
public List<AbsenceHistory> getAbsenceHistory(String emplId) {
    final GetCompIntfcUWPORTAL1ABSHIS request = this.createRequest(emplId);

    final GetCompIntfcUWPORTAL1ABSHISResponse response = this.internalInvoke(request);

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

    return this.convertAbsenceHistory(response, jobs);
}

From source file:com.haulmont.cuba.gui.theme.ThemeConstantsRepository.java

protected void init() {
    String configName = AppContext.getProperty("cuba.themeConfig");
    if (!StringUtils.isBlank(configName)) {
        Map<String, Map<String, String>> themeProperties = new HashMap<>();

        StrTokenizer tokenizer = new StrTokenizer(configName);
        for (String fileName : tokenizer.getTokenArray()) {
            String themeName = parseThemeName(fileName);
            if (StringUtils.isNotBlank(themeName)) {
                Map<String, String> themeMap = themeProperties.get(themeName);
                if (themeMap == null) {
                    themeMap = new HashMap<>();
                    themeProperties.put(themeName, themeMap);
                }//  w ww  .  ja  va  2 s . c o  m

                loadThemeProperties(fileName, themeMap);
            }
        }

        Map<String, ThemeConstants> themes = new LinkedHashMap<>();

        for (Map.Entry<String, Map<String, String>> entry : themeProperties.entrySet()) {
            themes.put(entry.getKey(), new ThemeConstants(entry.getValue()));
        }

        this.themeConstantsMap = Collections.unmodifiableMap(themes);
    } else {
        this.themeConstantsMap = Collections.emptyMap();
    }
}

From source file:it.lic.cli.Main.java

private void run(final CommandLine cli) throws Exception {
    final Wallet wallet = new Wallet.Default(new FileStorage(new System.Default()));
    if (cli.hasOption("h")) {
        this.help();
    } else if (cli.hasOption("l")) {
        final LicenseKeyPair lkp = wallet.licenseKeyPair(cli.getOptionValue("l"));
        java.lang.System.out.println(String.format("[%s] Public key: %s", lkp.name(),
                new String(Base64.getEncoder().encode(lkp.publicKey().getEncoded()))));
    } else if (cli.hasOption("L")) {
        final Iterator<License> licenses = wallet.licenses(wallet.licenseKeyPair(cli.getOptionValue("L")), "");
        while (licenses.hasNext()) {
            License current = licenses.next();
            java.lang.System.out.println(String.format("%s\t%s\t%s\t%s", current.name(), current.issuer(),
                    current.until(), current.encode()));
        }/*from   w w  w.  j  a  v  a  2s.  c  om*/
    } else if (cli.hasOption("k")) {
        final LicenseKeyPair lkp = wallet.newLicenseKeyPair(cli.getOptionValue("k"));
        java.lang.System.out.println(String.format("new keypair created: %s",
                new String(Base64.getEncoder().encode(lkp.publicKey().getEncoded()))));
    } else if (cli.hasOption("K")) {
        final Calendar expire = Calendar.getInstance();
        expire.add(Calendar.YEAR, 1);
        Optional<License> license = wallet.hasLicenseFor(wallet.licenseKeyPair("prometeo"),
                cli.getOptionValue("K"));
        if (license.isPresent()) {
            java.lang.System.out.println(String.format("license already esists: %s", license.get().encode()));
        } else {
            final License newlicense = wallet.newLicense(cli.getOptionValue("K"),
                    wallet.licenseKeyPair("prometeo"), cli.getOptionValue("K"), expire.getTime(),
                    Collections.emptyMap());
            java.lang.System.out.println(String.format("new license created: %s", newlicense.encode()));
        }
    }
}

From source file:com.zdhx.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  ww  .j ava 2s  . c  o  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();

            System.out.println("leimingtech--------------server response:-statusCode:" + statusCode + "-reason:"
                    + statusLine.getReasonPhrase());

            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:org.djodjo.comm.jus.toolbox.BasicNetwork.java

@Override
public NetworkResponse performRequest(Request<?> request) throws JusError {
    long requestStart = SystemClock.elapsedRealtime();
    while (true) {
        HttpResponse httpResponse = null;
        byte[] responseContents = null;
        Map<String, String> responseHeaders = Collections.emptyMap();
        try {// w  w  w. ja  va 2s .c  om
            // 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);
            }
            JusLog.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 {//ww w.j  ava  2 s. 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();
            }
            if (statusCode > 299 && statusCode < 503) {

                throw new RuntimeException();
            }
            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.volley.air.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 ww. ja va 2s. c o m*/
            // Gather headers.
            Map<String, String> headers = new HashMap<>();
            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(request, 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;
            NetworkResponse networkResponse = null;
            if (httpResponse != null) {
                statusCode = httpResponse.getStatusLine().getStatusCode();
            } else {
                throw new NoConnectionError(new NetworkResponse(-1, null, responseHeaders, false,
                        SystemClock.elapsedRealtime() - requestStart), 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_INTERNAL_SERVER_ERROR) {
                    throw new ServerError(networkResponse);
                } else {
                    if (statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN) {
                        attemptRetryOnException("auth", request, new AuthFailureError(networkResponse));
                    } else {
                        throw new VolleyError(networkResponse);
                    }
                }
            } else {
                throw new NetworkError(networkResponse);
            }
        }
    }
}

From source file:org.elasticsearch.client.Request.java

static Request info() {
    return new Request(HttpGet.METHOD_NAME, "/", Collections.emptyMap(), null);
}

From source file:mum.waa.fd.app.service.impl.DoctorServiceImpl.java

/** {@inheritDoc} */
@Override/*from ww w  .j a  v a 2s  . co  m*/
public Map<Integer, String> findDoctorBySpecialization(Specialization spec) {
    List<Doctor> doctors = doctorRepository.findDoctorBySpecialization(spec);

    if (doctors.isEmpty()) {
        return Collections.emptyMap();
    }

    Map<Integer, String> doctorMap = new HashMap<>();
    for (Doctor doctor : doctors) {
        doctorMap.put(doctor.getDoctorId(), doctor.getFullName());
    }

    return doctorMap;
}