當前位置: 首頁>>代碼示例>>Java>>正文


Java SortedMap類代碼示例

本文整理匯總了Java中java.util.SortedMap的典型用法代碼示例。如果您正苦於以下問題:Java SortedMap類的具體用法?Java SortedMap怎麽用?Java SortedMap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SortedMap類屬於java.util包,在下文中一共展示了SortedMap類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: deepCopy

import java.util.SortedMap; //導入依賴的package包/類
/**
 * Performs a deep copy of the supplied {@link Map} such that the
 * {@link SortedMap} returned has copies of the supplied {@link
 * Map}'s {@linkplain Map#values() values}.
 *
 * <p>This method may return {@code null} if {@code source} is
 * {@code null}.</p>
 *
 * <p>The {@link SortedMap} returned by this method is
 * mutable.</p>
 *
 * @param source the {@link Map} to copy; may be {@code null} in
 * which case {@code null} will be returned
 *
 * @return a mutable {@link SortedMap}, or {@code null}
 */
private static final SortedMap<String, SortedSet<Entry>> deepCopy(final Map<? extends String, ? extends SortedSet<Entry>> source) {
  final SortedMap<String, SortedSet<Entry>> returnValue;
  if (source == null) {
    returnValue = null;
  } else if (source.isEmpty()) {
    returnValue = Collections.emptySortedMap();
  } else {
    returnValue = new TreeMap<>();
    final Collection<? extends Map.Entry<? extends String, ? extends SortedSet<Entry>>> entrySet = source.entrySet();
    if (entrySet != null && !entrySet.isEmpty()) {
      for (final Map.Entry<? extends String, ? extends SortedSet<Entry>> entry : entrySet) {
        final String key = entry.getKey();
        final SortedSet<Entry> value = entry.getValue();
        if (value == null) {
          returnValue.put(key, null);
        } else {
          final SortedSet<Entry> newValue = new TreeSet<>(value.comparator());
          newValue.addAll(value);
          returnValue.put(key, newValue);
        }
      }
    }
  }
  return returnValue;
}
 
開發者ID:microbean,項目名稱:microbean-helm,代碼行數:42,代碼來源:ChartRepository.java

示例2: buildGammaMap

import java.util.SortedMap; //導入依賴的package包/類
private static ImmutableSortedMap<Integer, BigDecimal> buildGammaMap(Map<Integer, BigDecimal> gammaInput) {
    ImmutableSortedMap.Builder<Integer, BigDecimal> mapBuilder = ImmutableSortedMap.naturalOrder();
    SortedMap<Integer, BigDecimal> sortedInput = new TreeMap<>(gammaInput);
    Preconditions.checkArgument(sortedInput.firstKey() == 1,
            "Gamma Values must (exclusively) be specified for quantities 1 and (optionally) higher",
            sortedInput);
    Preconditions.checkArgument(sortedInput.lastKey().equals(sortedInput.size()), ""
                    + "Gamma Values must be specified for all capacities in {0, ..., k_{max}}, where k_{max} > 0 is any natural number > 0",
            sortedInput);

    for (Entry<Integer, BigDecimal> inputGammaEntry : sortedInput.entrySet()) {
        Preconditions.checkArgument(inputGammaEntry.getValue().compareTo(BigDecimal.ZERO) >= 0, "Gamma must not be negative", inputGammaEntry);
        mapBuilder.put(inputGammaEntry);
    }
    return mapBuilder.build();
}
 
開發者ID:spectrumauctions,項目名稱:sats-core,代碼行數:17,代碼來源:MRVMNationalBidder.java

示例3: testSortedMapDifferenceEquals

import java.util.SortedMap; //導入依賴的package包/類
public void testSortedMapDifferenceEquals() {
  SortedMap<Integer, String> left =
      ImmutableSortedMap.of(1, "a", 2, "b", 3, "c", 4, "d", 5, "e");
  SortedMap<Integer, String> right =
      ImmutableSortedMap.of(1, "a", 3, "f", 5, "g", 6, "z");
  SortedMap<Integer, String> right2 =
      ImmutableSortedMap.of(1, "a", 3, "h", 5, "g", 6, "z");
  SortedMapDifference<Integer, String> original =
      Maps.difference(left, right);
  SortedMapDifference<Integer, String> same =
      Maps.difference(left, right);
  SortedMapDifference<Integer, String> reverse =
      Maps.difference(right, left);
  SortedMapDifference<Integer, String> diff2 =
      Maps.difference(left, right2);

  new EqualsTester()
      .addEqualityGroup(original, same)
      .addEqualityGroup(reverse)
      .addEqualityGroup(diff2)
      .testEquals();
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:23,代碼來源:MapsTest.java

示例4: createCacheEntryName

import java.util.SortedMap; //導入依賴的package包/類
/**
 * Creates a unique entry name string for a request. It consists of the method name and all the parameter names
 * and values concatenated in alphabetical order. It is used to identify cache entries in the backend storage.
 * If <code>hashCacheEntryNames</code> is set to <code>true</code> this method will return a MD5 hash of
 * the generated name.
 *
 * @param method The request method
 * @param params The request parameters
 * @return a cache entry name
 */
public static String createCacheEntryName(String method, Map<String, String> params) {
	if (!(params instanceof SortedMap)) {
		params = new TreeMap<String, String>(params);
	}
	StringBuilder b = new StringBuilder(100);
	b.append(method.toLowerCase());
	b.append('.');
	for (Map.Entry<String, String> e : params.entrySet()) {
		b.append(e.getKey());
		b.append(e.getValue());
	}
	String name = b.toString();
	if (hashCacheEntryNames)
		return StringUtilities.md5(name);
	return StringUtilities.cleanUp(name);
}
 
開發者ID:kawaiiDango,項目名稱:pScrobbler,代碼行數:27,代碼來源:Cache.java

示例5: nextKey

import java.util.SortedMap; //導入依賴的package包/類
@Override
public K nextKey(final K key) {
    if (isEmpty()) {
        return null;
    }
    if (normalMap instanceof OrderedMap) {
        return ((OrderedMap<K, ?>) normalMap).nextKey(key);
    }
    final SortedMap<K, V> sm = (SortedMap<K, V>) normalMap;
    final Iterator<K> it = sm.tailMap(key).keySet().iterator();
    it.next();
    if (it.hasNext()) {
        return it.next();
    }
    return null;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:17,代碼來源:DualTreeBidiMap.java

示例6: assertTranslation

import java.util.SortedMap; //導入依賴的package包/類
private void assertTranslation(String expectedOsgi, String netbeans, Set<String> importedPackages, Set<String> exportedPackages) throws Exception {
    assertTrue(netbeans.endsWith("\n")); // JRE bug
    Manifest nbmani = new Manifest(new ByteArrayInputStream(netbeans.getBytes()));
    Attributes nbattr = nbmani.getMainAttributes();
    Manifest osgimani = new Manifest();
    Attributes osgi = osgimani.getMainAttributes();
    Info info = new Info();
    info.importedPackages.addAll(importedPackages);
    info.exportedPackages.addAll(exportedPackages);
    new MakeOSGi().translate(nbattr, osgi, Collections.singletonMap(nbattr.getValue("OpenIDE-Module"), info));
    // boilerplate:
    assertEquals("1.0", osgi.remove(new Attributes.Name("Manifest-Version")));
    assertEquals("2", osgi.remove(new Attributes.Name("Bundle-ManifestVersion")));
    SortedMap<String,String> osgiMap = new TreeMap<>();
    for (Map.Entry<Object,Object> entry : osgi.entrySet()) {
        osgiMap.put(((Attributes.Name) entry.getKey()).toString(), (String) entry.getValue());
    }
    assertEquals(expectedOsgi, osgiMap.toString().replace('"', '\''));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:MakeOSGiTest.java

示例7: copyOfSorted

import java.util.SortedMap; //導入依賴的package包/類
/**
 * Returns an immutable map containing the same entries as the provided sorted
 * map, with the same ordering.
 *
 * <p>Despite the method name, this method attempts to avoid actually copying
 * the data when it is safe to do so. The exact circumstances under which a
 * copy will or will not be performed are undocumented and subject to change.
 *
 * @throws NullPointerException if any key or value in {@code map} is null
 */
@SuppressWarnings("unchecked")
public static <K, V> ImmutableSortedMap<K, V> copyOfSorted(SortedMap<K, ? extends V> map) {
  Comparator<? super K> comparator = map.comparator();
  if (comparator == null) {
    // If map has a null comparator, the keys should have a natural ordering,
    // even though K doesn't explicitly implement Comparable.
    comparator = (Comparator<? super K>) NATURAL_ORDER;
  }
  if (map instanceof ImmutableSortedMap) {
    // TODO(kevinb): Prove that this cast is safe, even though
    // Collections.unmodifiableSortedMap requires the same key type.
    @SuppressWarnings("unchecked")
    ImmutableSortedMap<K, V> kvMap = (ImmutableSortedMap<K, V>) map;
    if (!kvMap.isPartialView()) {
      return kvMap;
    }
  }
  return fromEntries(comparator, true, map.entrySet());
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:30,代碼來源:ImmutableSortedMap.java

示例8: testRowEntrySetContains

import java.util.SortedMap; //導入依賴的package包/類
public void testRowEntrySetContains() {
  table =
      sortedTable =
          create("a", 2, 'X', "a", 2, 'X', "b", 3, 'X', "b", 2, 'X', "c", 10,
              'X', "c", 10, 'X', "c", 20, 'X', "d", 15, 'X', "d", 20, 'X',
              "d", 1, 'X', "e", 5, 'X');
  SortedMap<Integer, Character> row = sortedTable.row("c");
  Set<Map.Entry<Integer, Character>> entrySet = row.entrySet();
  assertTrue(entrySet.contains(Maps.immutableEntry(10, 'X')));
  assertTrue(entrySet.contains(Maps.immutableEntry(20, 'X')));
  assertFalse(entrySet.contains(Maps.immutableEntry(15, 'X')));
  entrySet = row.tailMap(15).entrySet();
  assertFalse(entrySet.contains(Maps.immutableEntry(10, 'X')));
  assertTrue(entrySet.contains(Maps.immutableEntry(20, 'X')));
  assertFalse(entrySet.contains(Maps.immutableEntry(15, 'X')));
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:17,代碼來源:TreeBasedTableTest.java

示例9: testTailMapRemoveThrough

import java.util.SortedMap; //導入依賴的package包/類
public void testTailMapRemoveThrough() {
  final SortedMap<K, V> map;
  try {
    map = makePopulatedMap();
  } catch (UnsupportedOperationException e) {
    return;
  }
  int oldSize = map.size();
  if (map.size() < 2 || !supportsRemove) {
    return;
  }
  Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
  Entry<K, V> firstEntry = iterator.next();
  Entry<K, V> secondEntry = iterator.next();
  K key = secondEntry.getKey();
  SortedMap<K, V> subMap = map.tailMap(key);
  subMap.remove(key);
  assertNull(subMap.remove(firstEntry.getKey()));
  assertEquals(map.size(), oldSize - 1);
  assertFalse(map.containsKey(key));
  assertEquals(subMap.size(), oldSize - 2);
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:23,代碼來源:SortedMapInterfaceTest.java

示例10: testColumnComparator

import java.util.SortedMap; //導入依賴的package包/類
public void testColumnComparator() {
  sortedTable = TreeBasedTable.create();
  sortedTable.put("", 42, 'x');
  assertSame(Ordering.natural(), sortedTable.columnComparator());
  assertSame(
      Ordering.natural(),
      ((SortedMap<Integer, Character>) sortedTable.rowMap().values().iterator().next())
          .comparator());

  sortedTable = TreeBasedTable.create(
      Collections.reverseOrder(), Ordering.usingToString());
  sortedTable.put("", 42, 'x');
  assertSame(Ordering.usingToString(), sortedTable.columnComparator());
  assertSame(
      Ordering.usingToString(),
      ((SortedMap<Integer, Character>) sortedTable.rowMap().values().iterator().next())
          .comparator());
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:19,代碼來源:TreeBasedTableTest.java

示例11: testAsMapSorted

import java.util.SortedMap; //導入依賴的package包/類
public void testAsMapSorted() {
  SortedSet<String> strings = new NonNavigableSortedSet();
  Collections.addAll(strings, "one", "two", "three");
  SortedMap<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION);
  assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map);
  assertEquals(Integer.valueOf(5), map.get("three"));
  assertNull(map.get("five"));
  assertThat(map.entrySet()).containsExactly(
      mapEntry("one", 3),
      mapEntry("three", 5),
      mapEntry("two", 3)).inOrder();
  assertThat(map.tailMap("onea").entrySet()).containsExactly(
      mapEntry("three", 5),
      mapEntry("two", 3)).inOrder();
  assertThat(map.subMap("one", "two").entrySet()).containsExactly(
      mapEntry("one", 3),
      mapEntry("three", 5)).inOrder();
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:19,代碼來源:MapsTest.java

示例12: report

import java.util.SortedMap; //導入依賴的package包/類
@Override
public void report(final SortedMap<String, Gauge> gauges,
                   final SortedMap<String, Counter> counters,
                   final SortedMap<String, Histogram> histograms,
                   final SortedMap<String, Meter> meters,
                   final SortedMap<String, Timer> timers) {
  final long timestamp = clock.instant().toEpochMilli();

  final ImmutableList<InfluxDbMeasurement> influxDbMeasurements = ImmutableList.<InfluxDbMeasurement>builder()
    .addAll(transformer.fromGauges(gauges, timestamp))
    .addAll(transformer.fromCounters(counters, timestamp))
    .addAll(transformer.fromHistograms(histograms, timestamp))
    .addAll(transformer.fromMeters(meters, timestamp))
    .addAll(transformer.fromTimers(timers, timestamp))
    .build();

  sender.send(influxDbMeasurements);
}
 
開發者ID:kickstarter,項目名稱:dropwizard-influxdb-reporter,代碼行數:19,代碼來源:InfluxDbMeasurementReporter.java

示例13: getAllPartialJobs

import java.util.SortedMap; //導入依賴的package包/類
@Override
public Map<JobId, Job> getAllPartialJobs() {
  LOG.debug("Called getAllPartialJobs()");
  SortedMap<JobId, Job> result = new TreeMap<JobId, Job>();
  try {
    for (HistoryFileInfo mi : hsManager.getAllFileInfo()) {
      if (mi != null) {
        JobId id = mi.getJobId();
        result.put(id, new PartialJob(mi.getJobIndexInfo(), id));
      }
    }
  } catch (IOException e) {
    LOG.warn("Error trying to scan for all FileInfos", e);
    throw new YarnRuntimeException(e);
  }
  return result;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:CachedHistoryStorage.java

示例14: removeMaxFromReplica

import java.util.SortedMap; //導入依賴的package包/類
private static void removeMaxFromReplica(
    SortedMap<Integer, AtomicInteger> replica,
    int maxValue) {
  Integer replicatedMaxValue = replica.lastKey();
  assertTrue("maxValue is incorrect", replicatedMaxValue == maxValue);
  removeFromReplica(replica, replicatedMaxValue);
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:8,代碼來源:MinMaxPriorityQueueTest.java

示例15: buildHierarchy

import java.util.SortedMap; //導入依賴的package包/類
private SortedMap<String, SortedMap> buildHierarchy(String parentId, List<LocalFolder> folders) {
    SortedMap<String, SortedMap> folderStructure = new TreeMap<>();
    for (Folder folder: folders) {
        if (parentId.equals(folder.getParentId())) {
            folderStructure.put(folder.getId(), buildHierarchy(folder.getId(), folders));
        }
    }
    return folderStructure;
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:10,代碼來源:ChooseFolder.java


注:本文中的java.util.SortedMap類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。