java.util.TreeMap.compare()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中java.util.TreeMap.compare()方法的一些代码示例,展示了TreeMap.compare()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TreeMap.compare()方法的具体详情如下:
包路径:java.util.TreeMap
类名称:TreeMap
方法名:compare

TreeMap.compare介绍

[英]Compares two keys using the correct comparison method for this TreeMap.
[中]使用此树映射的正确比较方法比较两个键。

代码示例

代码示例来源:origin: org.apidesign.bck2brwsr/emul

final boolean tooHigh(Object key) {
  if (!toEnd) {
    int c = m.compare(key, hi);
    if (c > 0 || (c == 0 && !hiInclusive))
      return true;
  }
  return false;
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

final boolean tooLow(Object key) {
  if (!fromStart) {
    int c = m.compare(key, lo);
    if (c < 0 || (c == 0 && !loInclusive))
      return true;
  }
  return false;
}

代码示例来源:origin: jtulach/bck2brwsr

final boolean tooHigh(Object key) {
  if (!toEnd) {
    int c = m.compare(key, hi);
    if (c > 0 || (c == 0 && !hiInclusive))
      return true;
  }
  return false;
}

代码示例来源:origin: jtulach/bck2brwsr

final boolean tooLow(Object key) {
  if (!fromStart) {
    int c = m.compare(key, lo);
    if (c < 0 || (c == 0 && !loInclusive))
      return true;
  }
  return false;
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

final boolean inClosedRange(Object key) {
  return (fromStart || m.compare(key, lo) >= 0)
    && (toEnd || m.compare(hi, key) >= 0);
}

代码示例来源:origin: jtulach/bck2brwsr

final boolean inClosedRange(Object key) {
  return (fromStart || m.compare(key, lo) >= 0)
    && (toEnd || m.compare(hi, key) >= 0);
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

SubMapIterator(TreeMap.Entry<K,V> first,
        TreeMap.Entry<K,V> fence) {
  expectedModCount = m.modCount;
  lastReturned = null;
  next = first;
  fenceKey = fence == null ? UNBOUNDED : fence.key;
}

代码示例来源:origin: jtulach/bck2brwsr

SubMapIterator(TreeMap.Entry<K,V> first,
        TreeMap.Entry<K,V> fence) {
  expectedModCount = m.modCount;
  lastReturned = null;
  next = first;
  fenceKey = fence == null ? UNBOUNDED : fence.key;
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * Returns the entry for the greatest key less than the specified key; if
 * no such entry exists (i.e., the least key in the Tree is greater than
 * the specified key), returns {@code null}.
 */
final Entry<K,V> getLowerEntry(K key) {
  Entry<K,V> p = root;
  while (p != null) {
    int cmp = compare(key, p.key);
    if (cmp > 0) {
      if (p.right != null)
        p = p.right;
      else
        return p;
    } else {
      if (p.left != null) {
        p = p.left;
      } else {
        Entry<K,V> parent = p.parent;
        Entry<K,V> ch = p;
        while (parent != null && ch == parent.left) {
          ch = parent;
          parent = parent.parent;
        }
        return parent;
      }
    }
  }
  return null;
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

Entry<K,V> p = root;
while (p != null) {
  int cmp = compare(key, p.key);
  if (cmp < 0) {
    if (p.left != null)

代码示例来源:origin: org.apidesign.bck2brwsr/emul

Entry<K,V> p = root;
while (p != null) {
  int cmp = compare(key, p.key);
  if (cmp < 0) {
    if (p.left != null)

代码示例来源:origin: org.apidesign.bck2brwsr/emul

Entry<K,V> p = root;
while (p != null) {
  int cmp = compare(key, p.key);
  if (cmp > 0) {
    if (p.right != null)

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Returns the entry for the greatest key less than the specified key; if
 * no such entry exists (i.e., the least key in the Tree is greater than
 * the specified key), returns {@code null}.
 */
final Entry<K,V> getLowerEntry(K key) {
  Entry<K,V> p = root;
  while (p != null) {
    int cmp = compare(key, p.key);
    if (cmp > 0) {
      if (p.right != null)
        p = p.right;
      else
        return p;
    } else {
      if (p.left != null) {
        p = p.left;
      } else {
        Entry<K,V> parent = p.parent;
        Entry<K,V> ch = p;
        while (parent != null && ch == parent.left) {
          ch = parent;
          parent = parent.parent;
        }
        return parent;
      }
    }
  }
  return null;
}

代码示例来源:origin: jtulach/bck2brwsr

Entry<K,V> p = root;
while (p != null) {
  int cmp = compare(key, p.key);
  if (cmp < 0) {
    if (p.left != null)

代码示例来源:origin: jtulach/bck2brwsr

Entry<K,V> p = root;
while (p != null) {
  int cmp = compare(key, p.key);
  if (cmp > 0) {
    if (p.right != null)

代码示例来源:origin: jtulach/bck2brwsr

Entry<K,V> p = root;
while (p != null) {
  int cmp = compare(key, p.key);
  if (cmp < 0) {
    if (p.left != null)

代码示例来源:origin: stackoverflow.com

Exception in thread "main" java.lang.ClassCastException: Test1 cannot be cast to java.lang.Comparable
 at java.util.TreeMap.compare(TreeMap.java:1188)
 at java.util.TreeMap.put(TreeMap.java:531)
 at java.util.TreeSet.add(TreeSet.java:255)
 at java.util.AbstractCollection.addAll(AbstractCollection.java:334)
 at java.util.TreeSet.addAll(TreeSet.java:312)
 at java.util.TreeSet.<init>(TreeSet.java:160)
 at Test1.main(Test1.java:9)

代码示例来源:origin: org.apidesign.bck2brwsr/emul

Entry<K,V> t = root;
if (t == null) {
  compare(key, key); // type (and possibly null) check

代码示例来源:origin: jtulach/bck2brwsr

Entry<K,V> t = root;
if (t == null) {
  compare(key, key); // type (and possibly null) check

相关文章

微信公众号

最新文章

更多