List of usage examples for java.util SortedMap put
V put(K key, V value);
From source file:org.jets3t.service.utils.RestUtils.java
/** * Calculate the canonical string for a REST/HTTP request to a storage service. * * When expires is non-null, it will be used instead of the Date header. * @throws UnsupportedEncodingException//from www. j av a2s. c om */ public static String makeServiceCanonicalString(String method, String resource, Map<String, Object> headersMap, String expires, String headerPrefix, List<String> serviceResourceParameterNames) throws UnsupportedEncodingException { StringBuilder canonicalStringBuf = new StringBuilder(); canonicalStringBuf.append(method).append("\n"); // Add all interesting headers to a list, then sort them. "Interesting" // is defined as Content-MD5, Content-Type, Date, and x-amz- SortedMap<String, Object> interestingHeaders = new TreeMap<String, Object>(); if (headersMap != null && headersMap.size() > 0) { for (Map.Entry<String, Object> entry : headersMap.entrySet()) { Object key = entry.getKey(); Object value = entry.getValue(); if (key == null) { continue; } String lk = key.toString().toLowerCase(Locale.getDefault()); // Ignore any headers that are not particularly interesting. if (lk.equals("content-type") || lk.equals("content-md5") || lk.equals("date") || lk.startsWith(headerPrefix)) { interestingHeaders.put(lk, value); } } } // Remove default date timestamp if "x-amz-date" or "x-goog-date" is set. if (interestingHeaders.containsKey(Constants.REST_METADATA_ALTERNATE_DATE_AMZ) || interestingHeaders.containsKey(Constants.REST_METADATA_ALTERNATE_DATE_GOOG)) { interestingHeaders.put("date", ""); } // Use the expires value as the timestamp if it is available. This trumps both the default // "date" timestamp, and the "x-amz-date" header. if (expires != null) { interestingHeaders.put("date", expires); } // these headers require that we still put a new line in after them, // even if they don't exist. if (!interestingHeaders.containsKey("content-type")) { interestingHeaders.put("content-type", ""); } if (!interestingHeaders.containsKey("content-md5")) { interestingHeaders.put("content-md5", ""); } // Finally, add all the interesting headers (i.e.: all that start with x-amz- ;-)) for (Map.Entry<String, Object> entry : interestingHeaders.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (key.startsWith(headerPrefix)) { canonicalStringBuf.append(key).append(':').append(value); } else { canonicalStringBuf.append(value); } canonicalStringBuf.append("\n"); } // don't include the query parameters... int queryIndex = resource.indexOf('?'); if (queryIndex == -1) { canonicalStringBuf.append(resource); } else { canonicalStringBuf.append(resource.substring(0, queryIndex)); } // ...unless the parameter(s) are in the set of special params // that actually identify a service resource. if (queryIndex >= 0) { SortedMap<String, String> sortedResourceParams = new TreeMap<String, String>(); // Parse parameters from resource string String query = resource.substring(queryIndex + 1); for (String paramPair : query.split("&")) { String[] paramNameValue = paramPair.split("="); String name = URLDecoder.decode(paramNameValue[0], "UTF-8"); String value = null; if (paramNameValue.length > 1) { value = URLDecoder.decode(paramNameValue[1], "UTF-8"); } // Only include parameter (and its value if present) in canonical // string if it is a resource-identifying parameter if (serviceResourceParameterNames.contains(name)) { sortedResourceParams.put(name, value); } } // Add resource parameters if (sortedResourceParams.size() > 0) { canonicalStringBuf.append("?"); } boolean addedParam = false; for (Map.Entry<String, String> entry : sortedResourceParams.entrySet()) { if (addedParam) { canonicalStringBuf.append("&"); } canonicalStringBuf.append(entry.getKey()); if (entry.getValue() != null) { canonicalStringBuf.append("=").append(entry.getValue()); } addedParam = true; } } return canonicalStringBuf.toString(); }
From source file:at.christophwurst.orm.service.BurnDownServiceImpl.java
@Override public Map<Date, Float> getBurnDownData(Long sprintId) { Map<Date, Float> result = new HashMap<>(); Sprint sprint = sprintRepository.getSprintAndWorklogs(sprintId); int totalTime = sprint.getRequirements().stream().mapToInt((s) -> { return s.getTasks().stream().mapToInt(Task::getEstimatedTime).sum(); }).sum();// w w w .j a v a 2s . c o m SortedMap<Date, List<LogbookEntry>> workLogs = new TreeMap<>(); sprint.getRequirements().forEach((r) -> { r.getTasks().forEach((t) -> { t.getLogbookEntries().forEach((e) -> { Date day = stripDate(e.getStartTime()); if (!workLogs.containsKey(day)) { workLogs.put(day, new ArrayList<>()); } workLogs.get(day).add(e); }); }); }); int left = totalTime; for (Map.Entry<Date, List<LogbookEntry>> entry : workLogs.entrySet()) { long Ldone = entry.getValue().stream().mapToLong(LogbookEntry::getTotalTime).sum(); int done = (int) (Ldone / (1000 * 3600)); left -= done; result.put(entry.getKey(), (float) left / totalTime); } return result; }
From source file:net.centro.rtb.monitoringcenter.MonitoringCenter.java
@SuppressWarnings("unchecked") private static <T extends Metric> SortedMap<String, T> getMetricsByNames(boolean appendPrefix, String[] startsWithFilters, Class<T> metricClass) { if (!configured.get()) { return (SortedMap<String, T>) EMPTY_METRIC_MAP; }/*from www. jav a 2s . com*/ SortedMap<String, T> metricsByNames = new TreeMap<>(); for (Map.Entry<String, Metric> entry : metricRegistry.getMetrics().entrySet()) { if (metricClass == null || metricClass.isAssignableFrom(entry.getValue().getClass())) { if (startsWithFilters == null || matchesStartsWithFilters(entry.getKey(), startsWithFilters)) { String metricName = (appendPrefix ? prefix + MetricNamingUtil.SEPARATOR : StringUtils.EMPTY) + entry.getKey(); metricsByNames.put(metricName, (T) entry.getValue()); } } } return metricsByNames; }
From source file:cn.ctyun.amazonaws.auth.AWS3Signer.java
protected String getCanonicalizedHeadersForStringToSign(Request<?> request) { List<String> headersToSign = getHeadersForStringToSign(request); for (int i = 0; i < headersToSign.size(); i++) { headersToSign.set(i, headersToSign.get(i).toLowerCase()); }//from ww w.j av a 2 s.com SortedMap<String, String> sortedHeaderMap = new TreeMap<String, String>(); for (Map.Entry<String, String> entry : request.getHeaders().entrySet()) { if (headersToSign.contains(entry.getKey().toLowerCase())) { sortedHeaderMap.put(entry.getKey().toLowerCase(), entry.getValue()); } } StringBuilder builder = new StringBuilder(); for (Map.Entry<String, String> entry : sortedHeaderMap.entrySet()) { builder.append(entry.getKey().toLowerCase()).append(":").append(entry.getValue()).append("\n"); } return builder.toString(); }
From source file:com.aurel.track.item.link.ItemLinkBL.java
/** * Gets the links to successors from itemID as predecessor * @param itemID//from w w w. j a v a 2 s. com * @return */ static SortedMap<Integer, TWorkItemLinkBean> getSuccessorsForMeAsPredecessorMap(Integer itemID) { SortedMap<Integer, TWorkItemLinkBean> itemLinkMap = new TreeMap<Integer, TWorkItemLinkBean>(); List<TWorkItemLinkBean> linksToSuccessors = workItemLinkDAO.loadByWorkItemPred(itemID); if (linksToSuccessors != null) { for (TWorkItemLinkBean workItemLinkBean : linksToSuccessors) { itemLinkMap.put(workItemLinkBean.getObjectID(), workItemLinkBean); } } return itemLinkMap; }
From source file:info.magnolia.cms.util.ExtendingContentWrapper.java
@Override public Collection<NodeData> getNodeDataCollection() { final Content wrapped = getWrappedContent(); Collection<NodeData> directChildren = wrapped.getNodeDataCollection(); try {/*from w w w . j a v a 2 s. c o m*/ if (wrapped.hasNodeData(EXTENDING_NODE_DATA)) { for (NodeData child : directChildren) { if (EXTENDING_NODE_DATA.equals(child.getName())) { directChildren.remove(child); break; } } } } catch (RepositoryException e) { throw new RuntimeException("Can't read nodedata collection from node [" + wrapped.getHandle() + "]", e); } if (extending) { Collection<NodeData> inheritedChildren = extendedContent.getNodeDataCollection(); // sort by name SortedMap<String, NodeData> merged = new TreeMap<String, NodeData>(); for (NodeData nodeData : inheritedChildren) { merged.put(nodeData.getName(), nodeData); } for (NodeData nodeData : directChildren) { merged.put(nodeData.getName(), nodeData); } return wrapNodeDatas(merged.values()); } return wrapNodeDatas(directChildren); }
From source file:org.hk.jt.client.core.Request.java
private String getRequestParameters() throws UnsupportedEncodingException { SortedMap<String, String> map = authParameter; if (postParameter != null && postParameter.size() > 0) { for (Map.Entry<String, String> param : postParameter.entrySet()) { map.put(param.getKey(), encodeURL(param.getValue())); }//from w ww . j a v a 2s .c o m } StringBuilder builder = new StringBuilder(); for (Map.Entry<String, String> param : map.entrySet()) { builder.append(param.getKey()); builder.append("="); builder.append(param.getValue()); builder.append("&"); } String parameters = builder.toString(); if (parameters != null && parameters.length() != 0) { parameters = builder.toString().substring(0, builder.length() - 1); } return parameters; }
From source file:com.espertech.esper.schedule.SchedulingServiceImpl.java
private void addTrigger(ScheduleSlot slot, ScheduleHandle handle, long triggerTime) { SortedMap<ScheduleSlot, ScheduleHandle> handleSet = timeHandleMap.get(triggerTime); if (handleSet == null) { handleSet = new TreeMap<ScheduleSlot, ScheduleHandle>(); timeHandleMap.put(triggerTime, handleSet); }/*from w w w . j av a 2 s. c o m*/ handleSet.put(slot, handle); handleSetMap.put(handle, handleSet); }
From source file:io.lavagna.service.ProjectService.java
public ProjectMetadata getMetadata(String shortName) { SortedMap<Integer, CardLabel> res = new TreeMap<>(); Project project = findByShortName(shortName); for (CardLabel cl : cardLabelRepository.findLabelsByProject(project.getId())) { res.put(cl.getId(), cl); }/*from w w w. ja va 2s.co m*/ SortedMap<Integer, LabelListValueWithMetadata> labelListValues = cardLabelRepository .findLabeListValueAggregatedByCardLabelId(project.getId()); Map<ColumnDefinition, BoardColumnDefinition> columnsDefinition = findMappedColumnDefinitionsByProjectId( project.getId()); return new ProjectMetadata(res, labelListValues, columnsDefinition); }