congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
TreeMap.comparator
Code IndexAdd Tabnine to your IDE (free)

How to use
comparator
method
in
java.util.TreeMap

Best Java code snippets using java.util.TreeMap.comparator (Showing top 20 results out of 630)

origin: commons-collections/commons-collections

/**
 * Return the comparator used to order this map, or <code>null</code>
 * if this map uses its keys' natural order.
 * 
 * @return the comparator used to order the map, or null if natural order
 */
public Comparator comparator() {
  if (fast) {
    return (map.comparator());
  } else {
    synchronized (map) {
      return (map.comparator());
    }
  }
}
origin: goldmansachs/gs-collections

public Comparator<? super K> comparator()
{
  return this.treeMap.comparator();
}
origin: eclipse/eclipse-collections

@Override
public Comparator<? super K> comparator()
{
  return this.treeMap.comparator();
}
origin: eclipse/eclipse-collections

@Override
public Comparator<? super K> comparator()
{
  return this.treeMap.comparator();
}
origin: wildfly/wildfly

/**
 * Return the comparator used to order this map, or <code>null</code>
 * if this map uses its keys' natural order.
 * 
 * @return the comparator used to order the map, or null if natural order
 */
public Comparator comparator() {
  if (fast) {
    return (map.comparator());
  } else {
    synchronized (map) {
      return (map.comparator());
    }
  }
}
origin: jenkinsci/jenkins

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
  TreeMap tm = (TreeMap) super.unmarshal(reader,context);
  return new Tree(tm,tm.comparator());
}
origin: apache/ignite

/**
 * Attempts to create a new map of the same type as {@code map} has. Otherwise returns new {@code HashMap}
 * instance.
 *
 * @param map Original map.
 * @return New map.
 */
public static <K, V> Map<K, V> newMap(Map<K, V> map) {
  if (map instanceof LinkedHashMap)
    return U.newLinkedHashMap(map.size());
  else if (map instanceof TreeMap)
    return new TreeMap<>(((TreeMap<Object, Object>)map).comparator());
  else if (map instanceof ConcurrentHashMap)
    return new ConcurrentHashMap<>(map.size());
  return U.newHashMap(map.size());
}
origin: robovm/robovm

private void writeObject(ObjectOutputStream stream) throws IOException {
  stream.putFields().put("comparator", comparator());
  stream.writeFields();
  stream.writeInt(size);
  for (Map.Entry<K, V> entry : entrySet()) {
    stream.writeObject(entry.getKey());
    stream.writeObject(entry.getValue());
  }
}
origin: google/guava

public void testTreeMapWithInitialMap() {
 SortedMap<Integer, Integer> map = Maps.newTreeMap();
 map.put(5, 10);
 map.put(3, 20);
 map.put(1, 30);
 TreeMap<Integer, Integer> copy = Maps.newTreeMap(map);
 assertEquals(copy, map);
 assertSame(copy.comparator(), map.comparator());
}
origin: google/guava

public void testTreeMap() {
 TreeMap<Integer, Integer> map = Maps.newTreeMap();
 assertEquals(Collections.emptyMap(), map);
 assertNull(map.comparator());
}
origin: apache/ignite

/**
 * Attempts to create a new map of the same known type. Will return null if map type is not supported.
 *
 * @param map Map.
 * @return New map of the same type or null.
 */
public static <K, V> Map<K, V> newKnownMap(Object map) {
  Class<?> cls = map == null ? null : map.getClass();
  if (cls == HashMap.class)
    return U.newHashMap(((Map)map).size());
  else if (cls == LinkedHashMap.class)
    return U.newLinkedHashMap(((Map)map).size());
  else if (!wrapTrees() && cls == TreeMap.class)
    return new TreeMap<>(((TreeMap<Object, Object>)map).comparator());
  else if (cls == ConcurrentHashMap.class)
    return new ConcurrentHashMap<>(((Map)map).size());
  return null;
}
origin: google/guava

public void testTreeMapWithComparator() {
 TreeMap<Integer, Integer> map = Maps.newTreeMap(SOME_COMPARATOR);
 assertEquals(Collections.emptyMap(), map);
 assertSame(SOME_COMPARATOR, map.comparator());
}
origin: apache/ignite

/** {@inheritDoc} */
@Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
  BinaryRawWriter rawWriter = writer.rawWriter();
  rawWriter.writeObject(map.comparator());
  int size = map.size();
  rawWriter.writeInt(size);
  for (Map.Entry<Object, Object> entry : ((TreeMap<Object, Object>)map).entrySet()) {
    rawWriter.writeObject(entry.getKey());
    rawWriter.writeObject(entry.getValue());
  }
}
origin: looly/hutool

/**
 * 排序已有Map,Key有序的Map
 * 
 * @param map Map
 * @param comparator Key比较器
 * @return TreeMap
 * @since 4.0.1
 * @see #newTreeMap(Map, Comparator)
 */
public static <K, V> TreeMap<K, V> sort(Map<K, V> map, Comparator<? super K> comparator) {
  TreeMap<K, V> result;
  if (map instanceof TreeMap) {
    // 已经是可排序Map,此时只有比较器一致才返回原map
    result = (TreeMap<K, V>) map;
    if (null == comparator || comparator.equals(result.comparator())) {
      return result;
    }
  } else {
    result = newTreeMap(map, comparator);
  }
  return result;
}
origin: looly/hutool

/**
 * 排序已有Map,Key有序的Map
 * 
 * @param map Map
 * @param comparator Key比较器
 * @return TreeMap
 * @since 4.0.1
 * @see #newTreeMap(Map, Comparator)
 */
public static <K, V> TreeMap<K, V> sort(Map<K, V> map, Comparator<? super K> comparator) {
  TreeMap<K, V> result;
  if (map instanceof TreeMap) {
    // 已经是可排序Map,此时只有比较器一致才返回原map
    result = (TreeMap<K, V>) map;
    if (null == comparator || comparator.equals(result.comparator())) {
      return result;
    }
  } else {
    result = newTreeMap(map, comparator);
  }
  return result;
}
origin: google/guava

public void testTreeMapNonGeneric() {
 TreeMap<LegacyComparable, Integer> map = Maps.newTreeMap();
 assertEquals(Collections.emptyMap(), map);
 map.put(new LegacyComparable("foo"), 1);
 map.put(new LegacyComparable("bar"), 2);
 assertThat(map.keySet())
   .containsExactly(new LegacyComparable("bar"), new LegacyComparable("foo"))
   .inOrder();
 assertThat(map.values()).containsExactly(2, 1).inOrder();
 assertNull(map.comparator());
}
origin: google/guava

public void testTreeMapDerived() {
 TreeMap<Derived, Integer> map = Maps.newTreeMap();
 assertEquals(Collections.emptyMap(), map);
 map.put(new Derived("foo"), 1);
 map.put(new Derived("bar"), 2);
 assertThat(map.keySet()).containsExactly(new Derived("bar"), new Derived("foo")).inOrder();
 assertThat(map.values()).containsExactly(2, 1).inOrder();
 assertNull(map.comparator());
}
origin: apache/kylin

/**
 * Creates a new instance that will have both the same property entries and
 * the same behavior as the given source.
 * <p/>
 * Note that the source instance and the copy instance will share the same
 * comparator instance if a custom ordering had been configured on the source.
 *
 * @param source the source to copy from
 * @return the copy
 */
public static OrderedProperties copyOf(OrderedProperties source) {
  // create a copy that has the same behaviour
  OrderedPropertiesBuilder builder = new OrderedPropertiesBuilder();
  if (source.properties instanceof TreeMap) {
    builder.withOrdering(((TreeMap<String, String>) source.properties).comparator());
  }
  OrderedProperties result = builder.build();
  // copy the properties from the source to the target
  for (Map.Entry<String, String> entry : source.entrySet()) {
    result.setProperty(entry.getKey(), entry.getValue());
  }
  return result;
}
origin: apache/ignite

/**
 * Check {@code TreeMap} data structure.
 *
 * @param useBinary Whether to go through binary mode.
 * @param useComparator Whether comparator should be used.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private void checkTreeMapAsValue(boolean useBinary, boolean useComparator) throws Exception {
  // Populate map.
  TreeMap<TestKey, Integer> map;
  map = testMap(useComparator);
  // Put and get value from cache.
  cache().put(KEY, map);
  TreeMap<TestKey, Integer> resMap;
  if (useBinary) {
    BinaryObject resMapBinary = (BinaryObject)cache().withKeepBinary().get(KEY);
    resMap = resMapBinary.deserialize();
  }
  else
    resMap = (TreeMap<TestKey, Integer>)cache().get(KEY);
  // Ensure content is correct.
  if (useComparator)
    assert resMap.comparator() instanceof TestKeyComparator;
  else
    assertNull(resMap.comparator());
  assertEquals(map, resMap);
  cache().clear();
}
origin: apache/ignite

/**
 * Check {@code TreeMap} data structure when used as key.
 *
 * @param useComparator Whether comparator should be used.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private void checkTreeMapAsKey(boolean useComparator) throws Exception {
  // Populate map.
  TreeMap<TestKey, Integer> map;
  map = testMap(useComparator);
  // Put and get value from cache.
  cache().put(map, KEY);
  TreeMap<TestKey, Integer> resMap = (TreeMap<TestKey, Integer>)((Entry)cache().iterator().next()).getKey();
  // Ensure content is correct.
  if (useComparator)
    assert resMap.comparator() instanceof TestKeyComparator;
  else
    assertNull(resMap.comparator());
  assertEquals(map, resMap);
  // Ensure value is correct.
  Integer resSameMap = (Integer)cache().get(map);
  assertEquals((Object)KEY, resSameMap);
  Integer resIdenticalMap = (Integer)cache().get(testMap(useComparator));
  assertEquals((Object)KEY, resIdenticalMap);
  // Ensure wrong comparator is not accepted.
  Integer resDifferentComp = (Integer)cache().get(testMap(!useComparator));
  assertEquals(null, resDifferentComp);
  cache().clear();
}
java.utilTreeMapcomparator

Javadoc

The comparator used to maintain order in this tree map, or null if it uses the natural ordering of its keys.

Popular methods of TreeMap

  • <init>
    Constructs a new tree map containing the same mappings and using the same ordering as the specified
  • put
    Associates the specified value with the specified key in this map. If the map previously contained a
  • get
    Returns the value to which the specified key is mapped, or null if this map contains no mapping for
  • entrySet
    Returns a Set view of the mappings contained in this map. The set's iterator returns the entries in
  • values
    Returns a Collection view of the values contained in this map. The collection's iterator returns the
  • size
    Returns the number of key-value mappings in this map.
  • keySet
    Returns a Set view of the keys contained in this map. The set's iterator returns the keys in ascendi
  • remove
    Removes the mapping for this key from this TreeMap if present.
  • containsKey
    Returns true if this map contains a mapping for the specified key.
  • isEmpty
  • clear
    Removes all of the mappings from this map. The map will be empty after this call returns.
  • firstKey
  • clear,
  • firstKey,
  • putAll,
  • lastKey,
  • firstEntry,
  • tailMap,
  • lastEntry,
  • floorEntry,
  • headMap,
  • subMap

Popular in Java

  • Finding current android device location
  • scheduleAtFixedRate (Timer)
  • setRequestProperty (URLConnection)
  • findViewById (Activity)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • String (java.lang)
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • BoxLayout (javax.swing)
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now