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.ssbusy.controller.app.AppCartController.java

private Map<String, Object> wrapCart(Order cart, boolean detail) {
    if (cart == null || cart instanceof NullOrderImpl) {
        return Collections.emptyMap();
    }/*from w w  w.  j  a va  2  s. co m*/

    Map<String, Object> ret = new HashMap<String, Object>();

    ret.put("cartItemCount", cart.getItemCount());
    if (detail) {
        ret.put("currencyCode", cart.getCurrency() == null ? null : cart.getCurrency().getCurrencyCode());
        ret.put("total", cart.getTotal());
        List<OrderAdjustment> oadjusts = cart.getOrderAdjustments();
        if (oadjusts != null && oadjusts.size() > 0) {
            List<Map<String, Object>> adjusts = new ArrayList<Map<String, Object>>(oadjusts.size());
            ret.put("adjusts", adjusts);
            for (OrderAdjustment oa : oadjusts) {
                Map<String, Object> adjust = new HashMap<String, Object>(1);
                adjusts.add(adjust);
                adjust.put("marketingMessage", oa.getOffer().getMarketingMessage());
            }
        }
        List<OrderItem> oitems = cart.getOrderItems();
        if (oitems != null && oitems.size() > 0) {
            List<Map<String, Object>> items = new ArrayList<Map<String, Object>>(oitems.size());
            ret.put("items", items);
            for (OrderItem oi : oitems) {
                Map<String, Object> item = new HashMap<String, Object>(7);
                items.add(item);
                item.put("id", oi.getId());
                item.put("name", oi.getName());
                item.put("price", oi.getPriceBeforeAdjustments(true));
                item.put("quantity", oi.getQuantity());
                if (oi instanceof SkuAccessor) {
                    Product p = null;
                    Sku sku = ((SkuAccessor) oi).getSku();
                    if (sku != null)
                        p = sku.getProduct();
                    if (p != null) {
                        item.put("pid", p.getId());
                        item.put("url", p.getUrl());
                        Map<String, Media> media = p.getMedia();
                        if (media != null) {
                            item.put("media", media.get("primary"));
                        }
                    }
                } else {
                    throw new UnsupportedOperationException(
                            "unsupported orderItem type: " + oi.getClass().getName());
                }
            }
        }
        List<MyOfferCode> myOfferCodes = offerService.listOfferCodeByOwner(CustomerState.getCustomer().getId());
        if (myOfferCodes != null && myOfferCodes.size() > 0) {
            List<Map<String, Object>> offerCodes = new ArrayList<Map<String, Object>>(myOfferCodes.size());
            ret.put("offercodes", offerCodes);
            for (MyOfferCode moc : myOfferCodes) {
                Map<String, Object> offerscodes = new HashMap<String, Object>(2);
                offerCodes.add(offerscodes);
                offerscodes.put("offerCode", moc.getOfferCode());
                offerscodes.put("marketingMessage", moc.getOffer().getMarketingMessage());
            }
        }
    }
    return ret;
}

From source file:com.hiyjeain.android.DevBase.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 a v  a  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);
                }

                // 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);
            }

            // 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);
        } 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);
                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.azaptree.services.http.handler.AsyncHttpHandlerSupport.java

/**
 * Validate the request and extract any data from the HTTP request that will be required to process the request asynchronously.
 * //from  w  w w  . ja  v  a2s  .com
 * If the request is invalid, then handle the request appropriately.
 * 
 * *** NOTE: to indicate that this method handled the request, set Request.handled to true: <code>baseRequest.setHandled(true);</code>
 * 
 * @param target
 * @param baseRequest
 * @param request
 * @param response
 * @return
 */
protected Map<String, Object> preProcess(final String target, final Request baseRequest,
        final HttpServletRequest request, final HttpServletResponse response)
        throws IOException, ServletException {
    return Collections.emptyMap();
}

From source file:com.voodoodyne.hattery.HttpRequest.java

/**
 * Default values/* ww  w  . ja  v a 2 s.  co m*/
 */
public HttpRequest(Transport transport) {
    this.transport = transport;
    this.method = HttpMethod.GET.name();
    this.url = null;
    this.params = Collections.emptyMap();
    this.headers = Collections.emptyMap();
    this.timeout = 0;
    this.retries = 0;
    this.mapper = new ObjectMapper();
    this.contentType = null;
    this.body = null;
}

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

public static JSONArray getAllAlerts(int offset, int limit) {
    Cache cache;/*  w  w  w  . j a  va2 s. co m*/
    String cacheKey = "offset_" + offset + "_limit_" + limit;
    byte[] cacheValue = null;

    JSONArray alerts = null;
    try {
        CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();
        cache = cacheFactory.createCache(Collections.emptyMap());
        cacheValue = (byte[]) cache.get(cacheKey);
        if (cacheValue == null) {
            alerts = getAllAlertsFromDataStore(offset, limit);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = null;
            try {
                oos = new ObjectOutputStream(baos);
            } catch (Exception e) {
                e.printStackTrace();
            }
            oos.writeObject(alerts);
            byte cval[] = baos.toByteArray();
            if (cval.length < 1024 * 1024) {
                Logger.getLogger(Datastore.class.getName()).log(Level.SEVERE,
                        "Alerts Size is in limits:" + cval.length);
                cache.put(cacheKey, cval);
            } else {
                Logger.getLogger(Datastore.class.getName()).log(Level.SEVERE,
                        "Length Size has exceeded:" + cval.length);
            }

        } else {
            ByteArrayInputStream bais = new ByteArrayInputStream(cacheValue);
            ObjectInputStream ois = null;
            try {
                ois = new ObjectInputStream(bais);
            } catch (Exception e) {
                e.printStackTrace();
            }
            alerts = (JSONArray) ois.readObject();
            Logger.getLogger(Datastore.class.getName()).log(Level.WARNING, "From the Cache");
        }
    } catch (CacheException e) {

    } catch (IOException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    return alerts;
}

From source file:io.jenkins.plugins.pipelineaction.PipelineAction.java

/**
 * Get the known fields for this pipeline action. Can be empty if there are no specific keys required or needed.
 *
 * @return Map of known fields, with the values being booleans marking whether the field is required, or an empty
 * map if no fields are specified.// w w w  .  j a va  2 s .c  o  m
 */
public Map<String, Boolean> getFields() {
    return Collections.emptyMap();
}

From source file:net.camelpe.extension.camel.spi.CdiRegistry.java

/**
 * @see org.apache.camel.spi.Registry#lookupByType(java.lang.Class)
 *//*w ww  .  java 2 s .  co  m*/
@Override
public <T> Map<String, T> lookupByType(final Class<T> type) {
    Validate.notNull(type, "type");
    getLog().trace("Looking up all beans having expected type = [{}] in CDI registry ...", type.getName());

    final Set<Bean<?>> beans = getDelegate().getBeans(type);
    if (beans.isEmpty()) {
        getLog().debug("Found no beans having expected type = [{}] in CDI registry.", type.getName());

        return Collections.emptyMap();
    }
    getLog().debug("Found [{}] beans having expected type = [{}] in CDI registry.",
            Integer.valueOf(beans.size()), type.getName());

    final Map<String, T> beansByName = new HashMap<String, T>(beans.size());
    final CreationalContext<?> creationalContext = getDelegate().createCreationalContext(null);
    for (final Bean<?> bean : beans) {
        beansByName.put(bean.getName(), type.cast(getDelegate().getReference(bean, type, creationalContext)));
    }

    return beansByName;
}

From source file:io.specto.hoverfly.junit.core.model.Request.java

public Map<String, List<String>> getHeaders() {
    return requestType == RequestType.RECORDING ? Collections.emptyMap() : headers;
}

From source file:eu.europa.ec.fisheries.uvms.rules.service.bean.FactRuleEvaluator.java

@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
private Map<String, String> generateRulesFromTemplate(String templateName, String templateFile,
        List<RuleType> rules) {
    if (CollectionUtils.isEmpty(rules)) {
        return Collections.emptyMap();
    }// w  w  w  .jav  a2 s. c  o  m
    InputStream templateStream = this.getClass().getResourceAsStream(templateFile);
    TemplateContainer tc = new DefaultTemplateContainer(templateStream);
    Map<String, String> drlsAndBrId = new HashMap<>();
    TemplateDataListener listener = new TemplateDataListener(tc);
    int rowNum = 0;
    for (RuleType ruleDto : rules) {
        listener.newRow(rowNum, 0);
        listener.newCell(rowNum, 0, templateName, 0);
        listener.newCell(rowNum, 1, ruleDto.getExpression(), 0);
        listener.newCell(rowNum, 2, ruleDto.getBrId(), 0);
        listener.newCell(rowNum, 3, ruleDto.getMessage(), 0);
        listener.newCell(rowNum, 4, ruleDto.getErrorType().value(), 0);
        listener.newCell(rowNum, 5, ruleDto.getLevel(), 0);
        listener.newCell(rowNum, 6, ruleDto.getPropertyNames(), 0);
        rowNum++;
    }
    listener.finishSheet();
    String drl = listener.renderDRL();
    log.debug(drl);
    drlsAndBrId.put(drl, templateName);
    return drlsAndBrId;
}

From source file:edu.wisc.hrs.dao.tlpayable.SoapTimeLeavePayableDao.java

@Override
@Cacheable(cacheName = "timeSheets", exceptionCacheName = "hrsUnknownExceptionCache")
public List<TimeSheet> getTimeSheets(String emplId) {
    final GetCompIntfcUWPORTAL1TLPAYBL request = this.createRequest(emplId);

    final GetCompIntfcUWPORTAL1TLPAYBLResponse response = this.internalInvoke(request);

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

    return this.convertTimeSheets(response, jobs);
}