当前位置: 首页>>代码示例>>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;未经允许,请勿转载。