List of usage examples for java.util TreeMap put
public V put(K key, V value)
From source file:org.jaqpot.core.data.serialize.custom.DataEntryDeSerializer.java
@Override public DataEntry deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { DataEntry dataEntry = (DataEntry) parent.deserialize(p, ctxt); TreeMap<String, Object> valuesMap = new TreeMap<>(); for (Map.Entry<String, Object> entry : dataEntry.getValues().entrySet()) { valuesMap.put(entry.getKey().replaceAll("\\(DOT\\)", "\\."), entry.getValue()); }//from w w w.j a v a 2 s. com dataEntry.setValues(valuesMap); return dataEntry; }
From source file:com.shigengyu.hyperion.server.RestServer.java
private static Collection<ControllerMethod> extractControllerMethods( Iterable<ResourceProvider> resourceProviders) { TreeMap<String, ControllerMethod> controllerMethods = Maps.newTreeMap(new Comparator<String>() { @Override/*from w w w . ja v a2s . c om*/ public int compare(String first, String second) { return first.compareTo(second); } }); for (ResourceProvider resourceProvider : resourceProviders) { String controllerPath = resourceProvider.getResourceClass().getAnnotation(Path.class).value(); for (Method method : resourceProvider.getResourceClass().getMethods()) { if (!method.isAnnotationPresent(Path.class)) { continue; } String methodPath = method.getAnnotation(Path.class).value(); String httpMethod = null; if (method.isAnnotationPresent(GET.class)) { httpMethod = HttpMethods.GET; } else if (method.isAnnotationPresent(POST.class)) { httpMethod = HttpMethods.POST; } ControllerMethod controllerMethod = new ControllerMethod(httpMethod, controllerPath, methodPath); controllerMethods.put(controllerMethod.getUrl(), controllerMethod); } } return controllerMethods.values(); }
From source file:no.digipost.api.useragreements.client.filters.request.RequestToSign.java
public SortedMap<String, String> getHeaders() { TreeMap<String, String> sortedHeaders = new TreeMap<String, String>(); Header[] headers = clientRequest.getAllHeaders(); for (Header header : headers) { sortedHeaders.put(header.getName(), header.getValue()); }/* w w w. j a v a 2 s .c o m*/ return sortedHeaders; }
From source file:org.apache.ambari.server.controller.metrics.timeline.MetricsRequestHelperTest.java
@Test public void testFetchTimelineMetrics() throws Exception { EasyMockSupport easyMockSupport = new EasyMockSupport(); final long now = System.currentTimeMillis(); TimelineMetrics metrics = new TimelineMetrics(); TimelineMetric timelineMetric = new TimelineMetric(); timelineMetric.setMetricName("cpu_user"); timelineMetric.setAppId("app1"); TreeMap<Long, Double> metricValues = new TreeMap<Long, Double>(); metricValues.put(now + 100, 1.0); metricValues.put(now + 200, 2.0);/*from w ww . j a v a 2s. c o m*/ metricValues.put(now + 300, 3.0); timelineMetric.setMetricValues(metricValues); metrics.getMetrics().add(timelineMetric); ObjectMapper mapper = new ObjectMapper(); AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); mapper.setAnnotationIntrospector(introspector); ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter(); String metricsResponse = writer.writeValueAsString(metrics); InputStream inputStream = IOUtils.toInputStream(metricsResponse); HttpURLConnection httpURLConnectionMock = createMock(HttpURLConnection.class); expect(httpURLConnectionMock.getInputStream()).andReturn(inputStream).once(); expect(httpURLConnectionMock.getResponseCode()).andReturn(HttpStatus.SC_OK).once(); URLStreamProvider urlStreamProviderMock = createMock(URLStreamProvider.class); expect(urlStreamProviderMock.processURL(EasyMock.isA(String.class), EasyMock.isA(String.class), isNull(String.class), EasyMock.isA(Map.class))).andReturn(httpURLConnectionMock).once(); replay(httpURLConnectionMock, urlStreamProviderMock); //Case 1 : No error. String randomSpec = "http://localhost:6188/ws/v1/timeline/metrics?metricNames=cpu_wio&hostname=host1&appId=HOST" + "&startTime=1447912834&endTime=1447990034&precision=SECONDS"; MetricsRequestHelper metricsRequestHelper = new MetricsRequestHelper(urlStreamProviderMock); metricsRequestHelper.fetchTimelineMetrics(new URIBuilder(randomSpec), now, now + 300); easyMockSupport.verifyAll(); //Case 2 : Precision Error returned first time. String metricsPrecisionErrorResponse = "{\"exception\": \"PrecisionLimitExceededException\",\n" + "\"message\": \"Requested precision (SECONDS) for given time range causes result set size of 169840, " + "which exceeds the limit - 15840. Please request higher precision.\",\n" + "\"javaClassName\": \"org.apache.hadoop.metrics2.sink.timeline.PrecisionLimitExceededException\"\n" + "}"; InputStream errorStream = IOUtils.toInputStream(metricsPrecisionErrorResponse); inputStream = IOUtils.toInputStream(metricsResponse); //Reloading stream. httpURLConnectionMock = createMock(HttpURLConnection.class); expect(httpURLConnectionMock.getErrorStream()).andReturn(errorStream).once(); expect(httpURLConnectionMock.getInputStream()).andReturn(inputStream).once(); expect(httpURLConnectionMock.getResponseCode()).andReturn(HttpStatus.SC_BAD_REQUEST).once() .andReturn(HttpStatus.SC_OK).once(); urlStreamProviderMock = createMock(URLStreamProvider.class); expect(urlStreamProviderMock.processURL(EasyMock.isA(String.class), EasyMock.isA(String.class), isNull(String.class), EasyMock.isA(Map.class))).andReturn(httpURLConnectionMock).times(2); replay(httpURLConnectionMock, urlStreamProviderMock); metricsRequestHelper = new MetricsRequestHelper(urlStreamProviderMock); metricsRequestHelper.fetchTimelineMetrics(new URIBuilder(randomSpec), now, now + 300); easyMockSupport.verifyAll(); }
From source file:eu.freme.broker.tools.internationalization.BodySwappingServletRequest.java
@Override public Map<String, String[]> getParameterMap() { TreeMap<String, String[]> map = new TreeMap<String, String[]>(); map.putAll(super.getParameterMap()); map.put("informat", new String[] { "turtle" }); map.remove("input"); if (changeResponse) { map.put("outformat", new String[] { "turtle" }); }/*from w w w . j a v a 2 s .c o m*/ return Collections.unmodifiableMap(map); }
From source file:org.powertac.factoredcustomer.FactoredCustomerServiceTests.java
public void initializeService() { TreeMap<String, String> map = new TreeMap<String, String>(); map.put("factoredcustomer.factoredCustomerService.configResource", "FactoredCustomers.xml"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig);/*from w ww . j a v a2s. c o m*/ List<String> inits = new ArrayList<String>(); inits.add("DefaultBroker"); inits.add("TariffMarket"); factoredCustomerService.initialize(comp, inits); }
From source file:com.mmounirou.spotirss.spotify.tracks.SpotifyHrefQuery.java
private XTracks findBestMatchingTrack(List<XTracks> xtracks, final Track track) { if (xtracks.size() == 1) { return xtracks.get(0); }// w w w . j a v a 2 s.c o m TreeMap<Integer, XTracks> sortedTrack = Maps.newTreeMap(); for (XTracks xTrack : xtracks) { sortedTrack.put(getLevenshteinDistance(xTrack, track), xTrack); } Integer minDistance = Iterables.get(sortedTrack.keySet(), 0); XTracks choosedTrack = sortedTrack.get(minDistance); if (minDistance > 1) { SpotiRss.LOGGER.info(String.format("(%s:%s) choosed for (%s:%s) with distance %d", choosedTrack.getOriginalTrackName(), Joiner.on(",").join(choosedTrack.getAllArtists()), track.getSong(), Joiner.on(",").join(track.getArtists()), minDistance)); } else { SpotiRss.LOGGER.debug(String.format("(%s:%s) choosed for (%s:%s) with distance %d", choosedTrack.getOriginalTrackName(), Joiner.on(",").join(choosedTrack.getAllArtists()), track.getSong(), Joiner.on(",").join(track.getArtists()), minDistance)); } return choosedTrack; }
From source file:net.anthonypoon.ngram.correlation.CorrelationReducer.java
@Override protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException { TreeMap<String, Double> currElement = new TreeMap(); for (Text val : values) { String[] strArray = val.toString().split("\t"); currElement.put(strArray[0], Double.valueOf(strArray[1])); }/*www. j ava 2 s .c o m*/ double[] currElementPrimitve = new double[upbound - lowbound + 1]; for (Integer i = 0; i <= upbound - lowbound; i++) { if (currElement.containsKey(String.valueOf(lowbound + i - lag))) { currElementPrimitve[i] = currElement.get(String.valueOf(lowbound + i - lag)); } else { currElementPrimitve[i] = 0; } } for (Map.Entry<String, TreeMap<String, Double>> pair : corrTargetArray.entrySet()) { double[] targetElemetPrimitive = new double[upbound - lowbound + 1]; for (Integer i = 0; i <= upbound - lowbound; i++) { if (pair.getValue().containsKey(String.valueOf(lowbound + i))) { targetElemetPrimitive[i] = pair.getValue().get(String.valueOf(lowbound + i)); } else { targetElemetPrimitive[i] = 0; } } Double correlation = new PearsonsCorrelation().correlation(targetElemetPrimitive, currElementPrimitve); if (correlation > threshold) { NumberFormat formatter = new DecimalFormat("#0.000"); context.write(key, new Text(pair.getKey() + "\t" + formatter.format(correlation))); } } }
From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.JSONGenerator.java
/** * @param node/* w w w. j a v a 2 s . co m*/ * @param opts * @param out * @throws RepositoryException * @throws IOException * @throws JSONException */ private static void outputChildNodes(Node node, ChecksumGeneratorOptions opts, JsonWriter out) throws RepositoryException, IOException { Set<String> nodeTypeExcludes = opts.getExcludedNodeTypes(); NodeIterator nodeIterator = node.getNodes(); TreeMap<String, Node> childSortMap = new TreeMap<String, Node>(); boolean hasOrderedChildren = false; try { hasOrderedChildren = node.getPrimaryNodeType().hasOrderableChildNodes(); } catch (Exception expected) { // ignore } while (nodeIterator.hasNext()) { Node child = nodeIterator.nextNode(); if (!nodeTypeExcludes.contains(child.getPrimaryNodeType().getName())) { if (hasOrderedChildren) { //output child node if parent is has orderable children out.name(child.getName()); out.beginObject(); generateSubnodeJSON(child, opts, out); out.endObject(); } else { // otherwise put the child nodes into a sorted map // to output them with consistent ordering childSortMap.put(child.getName(), child); } } } // output the non-ordered child nodes in sorted order (lexicographically) for (Node child : childSortMap.values()) { out.name(child.getName()); out.beginObject(); generateSubnodeJSON(child, opts, out); out.endObject(); } }
From source file:com.rackspacecloud.blueflood.io.serializers.HistogramSerializationTest.java
private TreeMap<Double, Double> getNonZeroBinsAsMap(HistogramRollup histogramRollup) { Collection<Bin<SimpleTarget>> bins = histogramRollup.getBins(); final TreeMap<Double, Double> binsMap = new TreeMap<Double, Double>(); for (Bin<SimpleTarget> bin : bins) { if (bin.getCount() > 0) { binsMap.put(bin.getMean(), bin.getCount()); }/* w ww . ja v a 2 s. c o m*/ } return binsMap; }