java.util.Collections.emptyIterator()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(175)

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

Collections.emptyIterator介绍

[英]Returns an iterator containing no elements.
[中]返回不包含任何元素的迭代器。

代码示例

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

public Iterator<Neo4jError> errors()
{
  return errors == null ? emptyIterator() : errors.iterator();
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public Iterator<UIWidget> iterator() {
  if (contents == null) {
    return Collections.emptyIterator();
  }
  return Arrays.asList(contents).iterator();
}

代码示例来源:origin: googleapis/google-cloud-java

Iterator<Entity> get(com.google.datastore.v1.ReadOptions readOptionsPb, final Key... keys) {
 if (keys.length == 0) {
  return Collections.emptyIterator();
 }
 com.google.datastore.v1.LookupRequest.Builder requestPb =
   com.google.datastore.v1.LookupRequest.newBuilder();
 if (readOptionsPb != null) {
  requestPb.setReadOptions(readOptionsPb);
 }
 for (Key k : Sets.newLinkedHashSet(Arrays.asList(keys))) {
  requestPb.addKeys(k.toPb());
 }
 return new ResultsIterator(requestPb);
}

代码示例来源:origin: twosigma/beakerx

NodeLayer(TreeMapNode node, List<TreeMapNode> children) {
 this.node = node;
 this.children = children;
 this.iter = (this.children == null) ? Collections.emptyIterator() : children.iterator();
}

代码示例来源:origin: com.js-lib/tiny-container

/**
   * Get cookies iterator. Return empty iterator if not cookies on HTTP request.
   * 
   * @return cookies iterator, possible empty.
   */
  public Iterator<Cookie> iterator() {
    if (cookies == null) {
      return Collections.emptyIterator();
    }
    return Arrays.asList(cookies).iterator();
  }
}

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

assertTrue(immutability.test(null));
assertTrue(immutability.test(Collections.emptyEnumeration()));
assertTrue(immutability.test(Collections.emptyIterator()));
assertTrue(immutability.test(Collections.emptyList()));
assertTrue(immutability.test(Collections.emptyListIterator()));
assertTrue(immutability.test(Collections.singletonMap("1", new JCIPImmutableObject())));
assertTrue(immutability.test(Collections.unmodifiableCollection(Arrays.asList("1", "2"))));
assertTrue(immutability.test(Collections.unmodifiableList(Arrays.asList("1", "2"))));
assertTrue(immutability.test(Collections.unmodifiableMap(Collections.singletonMap("1", "2"))));
assertTrue(immutability.test(Collections.unmodifiableNavigableMap(new TreeMap<>(Collections.singletonMap("1", "2")))));

代码示例来源:origin: chewiebug/GCViewer

public Iterator<T> details() {
  if (details == null) return Collections.emptyIterator();
  return details.iterator();
}

代码示例来源:origin: org.apache.myfaces.tobago/tobago-core

@Override
public Iterator<String> iterator() {
 if (value != null) {
  return Collections.singleton(value).iterator();
 }
 if (values != null) {
  return Arrays.asList(values).iterator();
 }
 return Collections.emptyIterator();
}

代码示例来源:origin: NationalSecurityAgency/datawave

@Test
  public void testEmptyExceededValueThreshold() throws ParseException {
    List<? extends IndexStream> iterable = Arrays.asList(ScannerStream.exceededValueThreshold(Collections.emptyIterator(),
            JexlASTHelper.parseJexlQuery("THIS_FIELD == 20")));
    
    Intersection intersection = new Intersection(iterable, null);
    
    Assert.assertEquals(IndexStream.StreamContext.ABSENT, intersection.context());
  }
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public Iterator<UIWidget> iterator() {
  if (!contents.isEmpty()) {
    return contents.iterator();
  }
  return Collections.emptyIterator();
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
  public Iterator<UIWidget> iterator() {
    if (content != null) {
      return Collections.singletonList(content).iterator();
    }
    return Collections.emptyIterator();
  }
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public Iterator<UIWidget> iterator() {
  if (content != null) {
    return Collections.singletonList(content).iterator();
  }
  return Collections.emptyIterator();
}

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

Iterator<CapableIndexDescriptor> indexesByProperty( int propertyId )
{
  List<CapableIndexDescriptor> indexes = indexByProperty.get( propertyId );
  return (indexes == null) ? emptyIterator() : indexes.iterator();
}

代码示例来源:origin: thinkaurelius/titan

@Override
public <V> Iterator<VertexProperty<V>> properties(String... keys) {
  if (vertexMemory.elementKeyMap.isEmpty()) return Collections.emptyIterator();
  if (keys==null || keys.length==0) {
    return Collections.emptyIterator(); //Do NOT return compute keys as part of all the properties...
    //keys = vertexMemory.elementKeyMap.keySet().toArray(new String[vertexMemory.elementKeyMap.size()]);
  }
  //..but only if specifically asked for by key
  List<VertexProperty<V>> result = new ArrayList<>(Math.min(keys.length,vertexMemory.elementKeyMap.size()));
  for (String key : keys) {
    if (!supports(key)) continue;
    V value = vertexMemory.getProperty(vertexId,key);
    if (value!=null) result.add(constructProperty(key,value));
  }
  return result.iterator();
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override protected Cursor findAllFetched(List<Row> fetched, SearchRow first, SearchRow last) {
  Iterator<Row> iter;
  if (fetched.isEmpty())
    iter = emptyIterator();
  else if (first == null && last == null)
    iter = fetched.iterator();
  else {
    int low = first == null ? 0 : binarySearchRow(fetched, first, firstRowCmp, false);
    if (low == fetched.size())
      iter = emptyIterator();
    else {
      int high = last == null ? fetched.size() : binarySearchRow(fetched, last, lastRowCmp, false);
      iter = fetched.subList(low, high).iterator();
    }
  }
  return new GridH2Cursor(iter);
}

代码示例来源:origin: JanusGraph/janusgraph

@Override
public <V> Iterator<VertexProperty<V>> properties(String... keys) {
  final Set<String> memoryKeys = vertexMemory.getMemoryKeys();
  if (memoryKeys.isEmpty()) return Collections.emptyIterator();
  if (keys==null || keys.length==0) {
    keys = memoryKeys.stream().filter(k -> !k.equals(TraversalVertexProgram.HALTED_TRAVERSERS)).toArray(String[]::new);
  }
  final List<VertexProperty<V>> result = new ArrayList<>(Math.min(keys.length,memoryKeys.size()));
  for (String key : keys) {
    if (!supports(key)) continue;
    V value = vertexMemory.getProperty(vertexId,key);
    if (value!=null) result.add(constructProperty(key,value));
  }
  return result.iterator();
}

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

private Iterator<RuleSet> resolveAdditionalRulesets(List<String> additionalRulesets) throws RuleSetNotFoundException {
  if (additionalRulesets == null) {
    return Collections.emptyIterator();
  }
  List<RuleSet> rulesets = new ArrayList<>();
  RuleSetFactory ruleSetFactory = new RuleSetFactory();
  for (String filename : additionalRulesets) {
    try {
      // do not take rulesets from pmd-test or pmd-core
      if (!filename.contains("pmd-test") && !filename.contains("pmd-core")) {
        rulesets.add(ruleSetFactory.createRuleSet(filename));
      } else {
        LOG.fine("Ignoring ruleset " + filename);
      }
    } catch (IllegalArgumentException e) {
      // ignore rulesets, we can't read
      LOG.log(Level.WARNING, "ruleset file " + filename + " ignored (" + e.getMessage() + ")", e);
    }
  }
  return rulesets.iterator();
}

代码示例来源:origin: apache/incubator-druid

@Override
public Iterator<ServerHolder> pickServersToDrop(DataSegment toDrop, NavigableSet<ServerHolder> serverHolders)
{
 List<ListenableFuture<Pair<Double, ServerHolder>>> futures = new ArrayList<>();
 for (final ServerHolder server : serverHolders) {
  futures.add(
    exec.submit(
      () -> Pair.of(computeCost(toDrop, server, true), server)
    )
  );
 }
 final ListenableFuture<List<Pair<Double, ServerHolder>>> resultsFuture = Futures.allAsList(futures);
 try {
  // results is an un-ordered list of a pair consisting of the 'cost' of a segment being on a server and the server
  List<Pair<Double, ServerHolder>> results = resultsFuture.get();
  return results.stream()
         // Comparator.comapringDouble will order by lowest cost...
         // reverse it because we want to drop from the highest cost servers first
         .sorted(Comparator.comparingDouble((Pair<Double, ServerHolder> o) -> o.lhs).reversed())
         .map(x -> x.rhs).collect(Collectors.toList())
         .iterator();
 }
 catch (Exception e) {
  log.makeAlert(e, "Cost Balancer Multithread strategy wasn't able to complete cost computation.").emit();
 }
 return Collections.emptyIterator();
}

代码示例来源:origin: apache/incubator-druid

private void nextMessage()
{
 try {
  row = null;
  while (row == null) {
   if (!nextIterator.hasNext()) {
    if (msg != null) {
     lastOffsetPartitions.put(msg.getPartition(), msg.offset());
    }
    msg = messageQueue.take();
    final byte[] message = msg.message();
    nextIterator = message == null
            ? Collections.emptyIterator()
            : firehoseParser.parseBatch(ByteBuffer.wrap(message)).iterator();
    continue;
   }
   row = nextIterator.next();
  }
 }
 catch (InterruptedException e) {
  //Let the caller decide whether to stop or continue when thread is interrupted.
  log.warn(e, "Thread Interrupted while taking from queue, propagating the interrupt");
  Thread.currentThread().interrupt();
 }
}

代码示例来源:origin: Sable/soot

/**
 * Returns an iterator over the methods in this class.
 */
public Iterator<SootMethod> methodIterator() {
 checkLevel(SIGNATURES);
 if (methodList == null) {
  return Collections.emptyIterator();
 }
 return new Iterator<SootMethod>() {
  final Iterator<SootMethod> internalIterator = methodList.iterator();
  private SootMethod currentMethod;
  @Override
  public boolean hasNext() {
   return internalIterator.hasNext();
  }
  @Override
  public SootMethod next() {
   currentMethod = internalIterator.next();
   return currentMethod;
  }
  @Override
  public void remove() {
   internalIterator.remove();
   subSigToMethods.put(currentMethod.getNumberedSubSignature(), null);
   currentMethod.setDeclared(false);
  }
 };
}

相关文章

Collections类方法