List of usage examples for java.util SortedMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:org.apache.james.mailbox.maildir.mail.MaildirMessageMapper.java
private List<MailboxMessage> findMessagesInMailboxBetweenUIDs(Mailbox mailbox, FilenameFilter filter, long from, long to, int max) throws MailboxException { MaildirFolder folder = maildirStore.createMaildirFolder(mailbox); int cur = 0;//from www . j av a 2s .c o m SortedMap<Long, MaildirMessageName> uidMap = null; try { if (filter != null) uidMap = folder.getUidMap(mailboxSession, filter, from, to); else uidMap = folder.getUidMap(mailboxSession, from, to); ArrayList<MailboxMessage> messages = new ArrayList<MailboxMessage>(); for (Entry<Long, MaildirMessageName> entry : uidMap.entrySet()) { messages.add(new MaildirMailboxMessage(mailbox, entry.getKey(), entry.getValue())); if (max != -1) { cur++; if (cur >= max) break; } } return messages; } catch (IOException e) { throw new MailboxException("Failure while search for Messages in Mailbox " + mailbox, e); } }
From source file:org.apache.accumulo.server.master.balancer.HostRegexTableLoadBalancer.java
/** * Group the set of current tservers by pool name. Tservers that don't match a regex are put into a default pool. This could be expensive in the terms of the * amount of time to recompute the groups, so HOST_BALANCER_POOL_RECHECK_KEY should be specified in the terms of minutes, not seconds or less. * * @param current//from w ww .j a v a 2s .c o m * map of current tservers * @return current servers grouped by pool name, if not a match it is put into a default pool. */ protected synchronized Map<String, SortedMap<TServerInstance, TabletServerStatus>> splitCurrentByRegex( SortedMap<TServerInstance, TabletServerStatus> current) { if ((System.currentTimeMillis() - lastPoolRecheck) > poolRecheckMillis) { LOG.debug("Performing pool recheck - regrouping tablet servers based on regular expressions"); Map<String, SortedMap<TServerInstance, TabletServerStatus>> newPools = new HashMap<String, SortedMap<TServerInstance, TabletServerStatus>>(); for (Entry<TServerInstance, TabletServerStatus> e : current.entrySet()) { List<String> poolNames = getPoolNamesForHost(e.getKey().host()); for (String pool : poolNames) { SortedMap<TServerInstance, TabletServerStatus> np = newPools.get(pool); if (null == np) { np = new TreeMap<TServerInstance, TabletServerStatus>(current.comparator()); newPools.put(pool, np); } np.put(e.getKey(), e.getValue()); } } pools = newPools; this.lastPoolRecheck = System.currentTimeMillis(); } return pools; }
From source file:org.eclipse.jubula.client.ui.widgets.DirectCombo.java
/** * Sort the keys according to the comparator which is applied to the display * values. For performance reasons the display values are generated and * returned, the keys are stored internally. * @param values the original objects/*from w w w .j a va 2 s .co m*/ * @param displayValues the Strings to be displayed in the Combo * @param comparator how to compare the display string values * @param isNullSelectionAllowed add an empty entry at the start of the list? * @return a sorted list of display values */ private List<String> sortKeys(List<TheObject> values, List<String> displayValues, Comparator<String> comparator, boolean isNullSelectionAllowed) { SortedMap<String, TheObject> sorter = new TreeMap<String, TheObject>(comparator); int size = values.size(); for (int i = 0; i < size; ++i) { sorter.put(displayValues.get(i), values.get(i)); } if (isNullSelectionAllowed) { size++; } m_values = new ArrayList<TheObject>(size); List<String> result = new ArrayList<String>(size); if (isNullSelectionAllowed) { m_values.add(null); result.add(StringConstants.EMPTY); } for (Entry<String, TheObject> entry : sorter.entrySet()) { m_values.add(entry.getValue()); result.add(entry.getKey()); } return result; }
From source file:com.codahale.metrics.riemann.DropWizardRiemannReporter.java
@Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { final long timestamp = clock.getTime() / 1000; log.debug("Reporting metrics: for {} at {}", timestamp, System.currentTimeMillis()); // oh it'd be lovely to use Java 7 here try {/* w w w. j av a 2s.c om*/ riemann.connect(); for (Map.Entry<String, Gauge> entry : gauges.entrySet()) { reportGauge(entry.getKey(), entry.getValue(), timestamp); } for (Map.Entry<String, Counter> entry : counters.entrySet()) { reportCounter(entry.getKey(), entry.getValue(), timestamp); } for (Map.Entry<String, Histogram> entry : histograms.entrySet()) { reportHistogram(entry.getKey(), entry.getValue(), timestamp); } for (Map.Entry<String, Meter> entry : meters.entrySet()) { reportMetered(entry.getKey(), entry.getValue(), timestamp); } for (Map.Entry<String, Timer> entry : timers.entrySet()) { reportTimer(entry.getKey(), entry.getValue(), timestamp); } log.trace("Flushing events to riemann"); riemann.client.flush(); log.debug("Completed at {}", System.currentTimeMillis()); } catch (IOException e) { log.warn("Unable to report to Riemann", riemann, e); } }
From source file:org.kalypsodeegree_impl.graphics.displayelements.RasterDisplayElement_Impl.java
RasterDisplayElement_Impl(final Feature feature, final GM_Object[] geometry, final RasterSymbolizer symbolizer) { super(feature, geometry, symbolizer); // fetch preferences m_interpolation = KalypsoDeegreePreferences.getRasterPaintingInterpolationMethod(); m_pixelResolution = KalypsoDeegreePreferences.getRasterPaintingPixelResolution(); // PERFORMANCE: create doubles and colors as arrays for quick access final SortedMap<Double, ColorMapEntry> colorMap = symbolizer.getColorMap(); final Set<Entry<Double, ColorMapEntry>> entrySet = colorMap.entrySet(); final Entry<Double, ColorMapEntry>[] entries = entrySet.toArray(new Entry[entrySet.size()]); m_values = new double[entries.length]; m_colors = new Color[entries.length]; for (int i = 0; i < entries.length; i++) { final Entry<Double, ColorMapEntry> entry = entries[i]; m_values[i] = entry.getKey();//from w w w . ja va2s . c om m_colors[i] = entry.getValue().getColorAndOpacity(); } if (m_values.length == 0) { m_min = Double.MAX_VALUE; m_max = -Double.MAX_VALUE; } else { m_min = m_values[0]; m_max = m_values[m_values.length - 1]; } }
From source file:org.apache.hadoop.hive.accumulo.mr.TestHiveAccumuloTableInputFormat.java
@Test public void testNameEqualBrian() throws Exception { Connector con = mockInstance.getConnector(USER, new PasswordToken(PASS.getBytes())); Scanner scan = con.createScanner(TEST_TABLE, new Authorizations("blah")); IteratorSetting is = new IteratorSetting(1, PrimitiveComparisonFilter.FILTER_PREFIX + 1, PrimitiveComparisonFilter.class); is.addOption(PrimitiveComparisonFilter.P_COMPARE_CLASS, StringCompare.class.getName()); is.addOption(PrimitiveComparisonFilter.COMPARE_OPT_CLASS, Equal.class.getName()); is.addOption(PrimitiveComparisonFilter.CONST_VAL, new String(Base64.encodeBase64("brian".getBytes()))); is.addOption(PrimitiveComparisonFilter.COLUMN, "cf:name"); scan.addScanIterator(is);//w w w. j a v a2s . c o m boolean foundName = false; boolean foundSid = false; boolean foundDegrees = false; boolean foundMillis = false; for (Map.Entry<Key, Value> kv : scan) { SortedMap<Key, Value> items = PrimitiveComparisonFilter.decodeRow(kv.getKey(), kv.getValue()); for (Map.Entry<Key, Value> item : items.entrySet()) { assertEquals(item.getKey().getRow().toString(), "r1"); if (item.getKey().getColumnQualifier().equals(NAME)) { foundName = true; assertArrayEquals(item.getValue().get(), "brian".getBytes()); } else if (item.getKey().getColumnQualifier().equals(SID)) { foundSid = true; assertArrayEquals(item.getValue().get(), parseIntBytes("1")); } else if (item.getKey().getColumnQualifier().equals(DEGREES)) { foundDegrees = true; assertArrayEquals(item.getValue().get(), parseDoubleBytes("44.5")); } else if (item.getKey().getColumnQualifier().equals(MILLIS)) { foundMillis = true; assertArrayEquals(item.getValue().get(), parseLongBytes("555")); } } } assertTrue(foundDegrees & foundMillis & foundName & foundSid); }
From source file:org.apache.hadoop.hive.accumulo.mr.TestHiveAccumuloTableInputFormat.java
@Test public void testGreaterThan1Sid() throws Exception { Connector con = mockInstance.getConnector(USER, new PasswordToken(PASS.getBytes())); Scanner scan = con.createScanner(TEST_TABLE, new Authorizations("blah")); IteratorSetting is = new IteratorSetting(1, PrimitiveComparisonFilter.FILTER_PREFIX + 1, PrimitiveComparisonFilter.class); is.addOption(PrimitiveComparisonFilter.P_COMPARE_CLASS, IntCompare.class.getName()); is.addOption(PrimitiveComparisonFilter.COMPARE_OPT_CLASS, GreaterThan.class.getName()); is.addOption(PrimitiveComparisonFilter.CONST_VAL, new String(Base64.encodeBase64(parseIntBytes("1")))); is.addOption(PrimitiveComparisonFilter.COLUMN, "cf:sid"); scan.addScanIterator(is);//from w w w . jav a 2 s .co m boolean foundMark = false; boolean foundDennis = false; int totalCount = 0; for (Map.Entry<Key, Value> kv : scan) { boolean foundName = false; boolean foundSid = false; boolean foundDegrees = false; boolean foundMillis = false; SortedMap<Key, Value> items = PrimitiveComparisonFilter.decodeRow(kv.getKey(), kv.getValue()); for (Map.Entry<Key, Value> item : items.entrySet()) { if (item.getKey().getRow().toString().equals("r2")) { foundMark = true; } else if (item.getKey().getRow().toString().equals("r3")) { foundDennis = true; } if (item.getKey().getColumnQualifier().equals(NAME)) { foundName = true; } else if (item.getKey().getColumnQualifier().equals(SID)) { foundSid = true; } else if (item.getKey().getColumnQualifier().equals(DEGREES)) { foundDegrees = true; } else if (item.getKey().getColumnQualifier().equals(MILLIS)) { foundMillis = true; } } totalCount++; assertTrue(foundDegrees & foundMillis & foundName & foundSid); } assertTrue(foundDennis & foundMark); assertEquals(totalCount, 2); }
From source file:org.apache.nifi.fingerprint.FingerprintFactory.java
private void addPropertiesFingerprint(final StringBuilder builder, final ConfigurableComponent component, final Map<String, String> properties) { if (properties == null) { builder.append("NO_PROPERTIES"); } else {//from ww w . ja v a 2 s .co m final SortedMap<String, String> sortedProps = new TreeMap<>(properties); for (final Map.Entry<String, String> entry : sortedProps.entrySet()) { addPropertyFingerprint(builder, component, entry.getKey(), entry.getValue()); } } }
From source file:cn.ctyun.amazonaws.auth.AbstractAWSSigner.java
/** * Examines the specified query string parameters and returns a * canonicalized form.//w w w . j a v a 2 s .c o m * <p> * The canonicalized query string is formed by first sorting all the query * string parameters, then URI encoding both the key and value and then * joining them, in order, separating key value pairs with an '&'. * * @param parameters * The query string parameters to be canonicalized. * * @return A canonicalized form for the specified query string parameters. */ protected String getCanonicalizedQueryString(Map<String, String> parameters) { SortedMap<String, String> sorted = new TreeMap<String, String>(); Iterator<Map.Entry<String, String>> pairs = parameters.entrySet().iterator(); while (pairs.hasNext()) { Map.Entry<String, String> pair = pairs.next(); String key = pair.getKey(); String value = pair.getValue(); sorted.put(HttpUtils.urlEncode(key, false), HttpUtils.urlEncode(value, false)); } StringBuilder builder = new StringBuilder(); pairs = sorted.entrySet().iterator(); while (pairs.hasNext()) { Map.Entry<String, String> pair = pairs.next(); builder.append(pair.getKey()); builder.append("="); builder.append(pair.getValue()); if (pairs.hasNext()) { builder.append("&"); } } return builder.toString(); }
From source file:com.facebook.buck.util.unarchive.Unzip.java
/** Unzips a file to a destination and returns the paths of the written files. */ @Override/*from w w w . j a v a 2 s . co m*/ public ImmutableSet<Path> extractArchive(Path archiveFile, ProjectFilesystem filesystem, Path relativePath, Optional<Path> stripPrefix, PatternsMatcher entriesToExclude, ExistingFileMode existingFileMode) throws IOException { // We want to remove stale contents of directories listed in {@code archiveFile}, but avoid // deleting and // re-creating any directories that already exist. We *also* want to avoid a full recursive // scan of listed directories, since that's almost as slow as deleting. So we preprocess the // contents of {@code archiveFile} and then scan the existing filesystem to remove stale // artifacts. ImmutableSet.Builder<Path> filesWritten = ImmutableSet.builder(); try (ZipFile zip = new ZipFile(archiveFile.toFile())) { SortedMap<Path, ZipArchiveEntry> pathMap; if (stripPrefix.isPresent()) { pathMap = getZipFilePathsStrippingPrefix(zip, relativePath, stripPrefix.get(), entriesToExclude); } else { pathMap = getZipFilePaths(zip, relativePath, entriesToExclude); } // A zip file isn't required to list intermediate paths (e.g., it can contain "foo/" and // "foo/bar/baz"), but we need to know not to delete those intermediates, so fill them in. for (SortedMap.Entry<Path, ZipArchiveEntry> p : new ArrayList<>(pathMap.entrySet())) { if (!isTopLevel(p.getKey(), pathMap)) { fillIntermediatePaths(p.getKey(), pathMap); } } DirectoryCreator creator = new DirectoryCreator(filesystem); for (SortedMap.Entry<Path, ZipArchiveEntry> p : pathMap.entrySet()) { Path target = p.getKey(); ZipArchiveEntry entry = p.getValue(); if (entry.isDirectory()) { extractDirectory(existingFileMode, pathMap, creator, target); } else { extractFile(filesWritten, zip, creator, target, entry); } } } return filesWritten.build(); }