java.util.concurrent.ConcurrentSkipListMap.findFirst()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(144)

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

ConcurrentSkipListMap.findFirst介绍

[英]Specialized variant of findNode to get first valid node.
[中]获取第一个有效节点的findNode的专用变量。

代码示例

代码示例来源:origin: robovm/robovm

/**
 * Returns {@code true} if this map contains no key-value mappings.
 * @return {@code true} if this map contains no key-value mappings
 */
public boolean isEmpty() {
  return findFirst() == null;
}

代码示例来源:origin: robovm/robovm

/**
 * @throws NoSuchElementException {@inheritDoc}
 */
public K firstKey() {
  Node<K,V> n = findFirst();
  if (n == null)
    throw new NoSuchElementException();
  return n.key;
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a key-value mapping associated with the least
 * key in this map, or {@code null} if the map is empty.
 * The returned entry does <em>not</em> support
 * the {@code Entry.setValue} method.
 */
public Map.Entry<K,V> firstEntry() {
  for (;;) {
    Node<K,V> n = findFirst();
    if (n == null)
      return null;
    AbstractMap.SimpleImmutableEntry<K,V> e = n.createSnapshot();
    if (e != null)
      return e;
  }
}

代码示例来源:origin: robovm/robovm

/**
 * Returns {@code true} if this map maps one or more keys to the
 * specified value.  This operation requires time linear in the
 * map size. Additionally, it is possible for the map to change
 * during execution of this method, in which case the returned
 * result may be inaccurate.
 *
 * @param value value whose presence in this map is to be tested
 * @return {@code true} if a mapping to {@code value} exists;
 *         {@code false} otherwise
 * @throws NullPointerException if the specified value is null
 */
public boolean containsValue(Object value) {
  if (value == null)
    throw new NullPointerException();
  for (Node<K,V> n = findFirst(); n != null; n = n.next) {
    V v = n.getValidValue();
    if (v != null && value.equals(v))
      return true;
  }
  return false;
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the number of key-value mappings in this map.  If this map
 * contains more than {@code Integer.MAX_VALUE} elements, it
 * returns {@code Integer.MAX_VALUE}.
 *
 * <p>Beware that, unlike in most collections, this method is
 * <em>NOT</em> a constant-time operation. Because of the
 * asynchronous nature of these maps, determining the current
 * number of elements requires traversing them all to count them.
 * Additionally, it is possible for the size to change during
 * execution of this method, in which case the returned result
 * will be inaccurate. Thus, this method is typically not very
 * useful in concurrent applications.
 *
 * @return the number of elements in this map
 */
public int size() {
  long count = 0;
  for (Node<K,V> n = findFirst(); n != null; n = n.next) {
    if (n.getValidValue() != null)
      ++count;
  }
  return (count >= Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) count;
}

代码示例来源:origin: robovm/robovm

/**
 * Saves this map to a stream (that is, serializes it).
 *
 * @serialData The key (Object) and value (Object) for each
 * key-value mapping represented by the map, followed by
 * {@code null}. The key-value mappings are emitted in key-order
 * (as determined by the Comparator, or by the keys' natural
 * ordering if no Comparator).
 */
private void writeObject(java.io.ObjectOutputStream s)
  throws java.io.IOException {
  // Write out the Comparator and any hidden stuff
  s.defaultWriteObject();
  // Write out keys and values (alternating)
  for (Node<K,V> n = findFirst(); n != null; n = n.next) {
    V v = n.getValidValue();
    if (v != null) {
      s.writeObject(n.key);
      s.writeObject(v);
    }
  }
  s.writeObject(null);
}

代码示例来源:origin: robovm/robovm

/**
 * Returns lowest node. This node might not be in range, so
 * most usages need to check bounds.
 */
private ConcurrentSkipListMap.Node<K,V> loNode() {
  if (lo == null)
    return m.findFirst();
  else if (loInclusive)
    return m.findNear(lo, GT|EQ);
  else
    return m.findNear(lo, GT);
}

代码示例来源:origin: robovm/robovm

/**
 * Removes first entry; returns its snapshot.
 * @return null if empty, else snapshot of first entry
 */
Map.Entry<K,V> doRemoveFirstEntry() {
  for (;;) {
    Node<K,V> b = head.node;
    Node<K,V> n = b.next;
    if (n == null)
      return null;
    Node<K,V> f = n.next;
    if (n != b.next)
      continue;
    Object v = n.value;
    if (v == null) {
      n.helpDelete(b, f);
      continue;
    }
    if (!n.casValue(v, null))
      continue;
    if (!n.appendMarker(f) || !b.casNext(n, f))
      findFirst(); // retry
    clearIndexToFirst();
    return new AbstractMap.SimpleImmutableEntry<K,V>(n.key, (V)v);
  }
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Returns {@code true} if this map contains no key-value mappings.
 * @return {@code true} if this map contains no key-value mappings
 */
public boolean isEmpty() {
  return findFirst() == null;
}

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

/**
 * Returns <tt>true</tt> if this map contains no key-value mappings.
 * @return <tt>true</tt> if this map contains no key-value mappings
 */
public boolean isEmpty() {
  return findFirst() == null;
}

代码示例来源:origin: org.codehaus.jsr166-mirror/jsr166

/**
 * Returns <tt>true</tt> if this map contains no key-value mappings.
 * @return <tt>true</tt> if this map contains no key-value mappings
 */
public boolean isEmpty() {
  return findFirst() == null;
}

代码示例来源:origin: ibinti/bugvm

/**
 * @throws NoSuchElementException {@inheritDoc}
 */
public K firstKey() {
  Node<K,V> n = findFirst();
  if (n == null)
    throw new NoSuchElementException();
  return n.key;
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * @throws NoSuchElementException {@inheritDoc}
 */
public K firstKey() {
  Node<K,V> n = findFirst();
  if (n == null)
    throw new NoSuchElementException();
  return n.key;
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * @throws NoSuchElementException {@inheritDoc}
 */
public K firstKey() {
  Node<K,V> n = findFirst();
  if (n == null)
    throw new NoSuchElementException();
  return n.key;
}

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

/**
 * @throws NoSuchElementException {@inheritDoc}
 */
public K firstKey() {
  Node<K,V> n = findFirst();
  if (n == null)
    throw new NoSuchElementException();
  return n.key;
}

代码示例来源:origin: ibinti/bugvm

/**
 * Returns lowest node. This node might not be in range, so
 * most usages need to check bounds.
 */
private ConcurrentSkipListMap.Node<K,V> loNode() {
  if (lo == null)
    return m.findFirst();
  else if (loInclusive)
    return m.findNear(lo, GT|EQ);
  else
    return m.findNear(lo, GT);
}

代码示例来源:origin: org.codehaus.jsr166-mirror/jsr166

/**
 * Returns lowest node. This node might not be in range, so
 * most usages need to check bounds
 */
private ConcurrentSkipListMap.Node<K,V> loNode() {
  if (lo == null)
    return m.findFirst();
  else if (loInclusive)
    return m.findNear(lo, m.GT|m.EQ);
  else
    return m.findNear(lo, m.GT);
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * Returns lowest node. This node might not be in range, so
 * most usages need to check bounds.
 */
private ConcurrentSkipListMap.Node<K,V> loNode() {
  if (lo == null)
    return m.findFirst();
  else if (loInclusive)
    return m.findNear(lo, GT|EQ);
  else
    return m.findNear(lo, GT);
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * Returns lowest node. This node might not be in range, so
 * most usages need to check bounds.
 */
private ConcurrentSkipListMap.Node<K,V> loNode() {
  if (lo == null)
    return m.findFirst();
  else if (loInclusive)
    return m.findNear(lo, GT|EQ);
  else
    return m.findNear(lo, GT);
}

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

/**
 * Returns lowest node. This node might not be in range, so
 * most usages need to check bounds
 */
private ConcurrentSkipListMap.Node<K,V> loNode() {
  if (lo == null)
    return m.findFirst();
  else if (loInclusive)
    return m.findNear(lo, m.GT|m.EQ);
  else
    return m.findNear(lo, m.GT);
}

相关文章

ConcurrentSkipListMap类方法