List of usage examples for com.google.common.collect Iterators singletonIterator
public static <T> UnmodifiableIterator<T> singletonIterator(@Nullable final T value)
From source file:org.apache.fluo.recipes.core.map.CollisionFreeMap.java
private Iterator<V> concat(Iterator<V> updates, Bytes currentVal) { if (currentVal == null) { return updates; }/* w w w . ja v a 2s.co m*/ return Iterators.concat(updates, Iterators.singletonIterator(deserVal(currentVal))); }
From source file:org.gradle.api.internal.tasks.DefaultTaskOutputs.java
@Override public SortedSet<TaskOutputFilePropertySpec> getFileProperties() { if (fileProperties == null) { TaskPropertyUtils.ensurePropertiesHaveNames(filePropertiesInternal); Iterator<TaskOutputFilePropertySpec> flattenedProperties = Iterators .concat(Iterables.transform(filePropertiesInternal, new Function<TaskPropertySpec, Iterator<? extends TaskOutputFilePropertySpec>>() { @Override public Iterator<? extends TaskOutputFilePropertySpec> apply( TaskPropertySpec propertySpec) { if (propertySpec instanceof CompositeTaskOutputPropertySpec) { return ((CompositeTaskOutputPropertySpec) propertySpec) .resolveToOutputProperties(); } else { return Iterators .singletonIterator((TaskOutputFilePropertySpec) propertySpec); }/*from w ww . jav a 2s. c o m*/ } }).iterator()); fileProperties = TaskPropertyUtils.collectFileProperties("output", flattenedProperties); } return fileProperties; }
From source file:org.geogit.api.plumbing.diff.TreeDiffEntryIterator.java
public TreeDiffEntryIterator(@Nullable NodeRef oldTreeRef, @Nullable NodeRef newTreeRef, @Nullable RevTree oldTree, @Nullable RevTree newTree, final boolean reportTrees, final boolean recursive, final ObjectDatabase db) { checkArgument(oldTree != null || newTree != null); this.reportTrees = reportTrees; this.recursive = recursive; this.objectDb = db; this.strategy = resolveStrategy(); if (oldTree != null && newTree != null && oldTree.getId().equals(newTree.getId())) { delegate = Iterators.emptyIterator(); } else if (oldTree == null) { delegate = addRemoveAll(newTreeRef, newTree, ADDED); } else if (newTree == null) { delegate = addRemoveAll(oldTreeRef, oldTree, REMOVED); } else if (!oldTree.buckets().isPresent() && !newTree.buckets().isPresent()) { Strategy itStategy = recursive ? DepthTreeIterator.Strategy.CHILDREN : DepthTreeIterator.Strategy.FEATURES_ONLY; Iterator<NodeRef> left = new DepthTreeIterator(oldTreeRef.path(), oldTreeRef.getMetadataId(), oldTree, db, itStategy);/*w w w . jav a 2 s . com*/ Iterator<NodeRef> right = new DepthTreeIterator(newTreeRef.path(), newTreeRef.getMetadataId(), newTree, db, itStategy); delegate = new ChildrenChildrenDiff(left, right); } else if (oldTree.buckets().isPresent() && newTree.buckets().isPresent()) { delegate = new BucketBucketDiff(oldTreeRef, newTreeRef, oldTree.buckets().get(), newTree.buckets().get()); } else if (newTree.buckets().isPresent()) { checkState(!oldTree.buckets().isPresent()); DepthTreeIterator left = new DepthTreeIterator(oldTreeRef.path(), oldTreeRef.getMetadataId(), oldTree, objectDb, strategy); DepthTreeIterator rightIterator; rightIterator = new DepthTreeIterator(newTreeRef.path(), newTreeRef.getMetadataId(), newTree, objectDb, strategy); delegate = new ChildrenChildrenDiff(left, rightIterator); } else { checkState(oldTree.buckets().isPresent()); DepthTreeIterator right = new DepthTreeIterator(newTreeRef.path(), newTreeRef.getMetadataId(), newTree, objectDb, strategy); DepthTreeIterator leftIterator; leftIterator = new DepthTreeIterator(oldTreeRef.path(), oldTreeRef.getMetadataId(), oldTree, objectDb, strategy); delegate = new ChildrenChildrenDiff(leftIterator, right); // delegate = new BucketsChildrenDiff(left, right); } // If the tree has changed its metadata Id, it will not be reported as a diff // up to this point. // We check here that both metadata Id's are identical, and if not, we add the DiffEntry // corresponding to the tree. if (reportTrees && oldTreeRef != null && newTreeRef != null && !oldTreeRef.getMetadataId().equals(newTreeRef.getMetadataId())) { DiffEntry diffEntry = new DiffEntry(oldTreeRef, newTreeRef); UnmodifiableIterator<DiffEntry> iter = Iterators.singletonIterator(diffEntry); delegate = Iterators.concat(delegate, iter); } }
From source file:io.druid.extendedset.intset.ImmutableConciseSet.java
public static ImmutableConciseSet intersection(Iterator<ImmutableConciseSet> sets) { ImmutableConciseSet partialResults = doIntersection(Iterators.limit(sets, CHUNK_SIZE)); while (sets.hasNext()) { final UnmodifiableIterator<ImmutableConciseSet> partialIter = Iterators .singletonIterator(partialResults); partialResults = doIntersection( Iterators.<ImmutableConciseSet>concat(Iterators.limit(sets, CHUNK_SIZE), partialIter)); }/* ww w . j ava2s.c o m*/ return partialResults; }
From source file:org.apache.druid.extendedset.intset.ImmutableConciseSet.java
public static ImmutableConciseSet intersection(Iterator<ImmutableConciseSet> sets) { ImmutableConciseSet partialResults = doIntersection(Iterators.limit(sets, CHUNK_SIZE)); while (sets.hasNext()) { final UnmodifiableIterator<ImmutableConciseSet> partialIter = Iterators .singletonIterator(partialResults); partialResults = doIntersection(Iterators.concat(Iterators.limit(sets, CHUNK_SIZE), partialIter)); }//from w w w .j av a2 s .c om return partialResults; }
From source file:org.sonar.pickbasic.tree.impl.statement.ReadStatementsMultiLineTreeImpl.java
@Override public Iterator<Tree> childrenIterator() { return Iterators.concat( Iterators.forArray(readKeyword, expression, fromClausePick, settingClause, lockStatementSingleLine), thenClauseMultiLine.iterator(), Iterators.singletonIterator(semicolonToken)); }
From source file:org.sonar.pickbasic.tree.impl.statement.ReadStatementsSingleLineTreeImpl.java
@Override public Iterator<Tree> childrenIterator() { return Iterators.concat( Iterators.forArray(readKeyword, expression, fromClausePick, settingClause, lockStatementSingleLine), thenClauseSingleLine.iterator(), Iterators.singletonIterator(semicolonToken)); }
From source file:org.apache.jackrabbit.oak.plugins.index.property.strategy.ContentMirrorStoreStrategy.java
public Iterable<String> query(final Filter filter, final String indexName, final NodeState indexMeta, final String indexStorageNodeName, final Iterable<String> values) { final NodeState index = indexMeta.getChildNode(indexStorageNodeName); return new Iterable<String>() { @Override// w ww .j ava 2 s. c o m public Iterator<String> iterator() { PathIterator it = new PathIterator(filter, indexName, ""); if (values == null) { it.setPathContainsValue(true); it.enqueue(getChildNodeEntries(index).iterator()); } else { for (String p : values) { NodeState property = index.getChildNode(p); if (property.exists()) { // we have an entry for this value, so use it it.enqueue(Iterators.singletonIterator(new MemoryChildNodeEntry("", property))); } } } return it; } }; }
From source file:org.apache.flink.util.NetUtils.java
/** * Returns an iterator over available ports defined by the range definition. * * @param rangeDefinition String describing a single port, a range of ports or multiple ranges. * @return Set of ports from the range definition * @throws NumberFormatException If an invalid string is passed. *///from ww w.j av a 2 s .co m public static Iterator<Integer> getPortRangeFromString(String rangeDefinition) throws NumberFormatException { final String[] ranges = rangeDefinition.trim().split(","); List<Iterator<Integer>> iterators = new ArrayList<>(ranges.length); for (String rawRange : ranges) { Iterator<Integer> rangeIterator = null; String range = rawRange.trim(); int dashIdx = range.indexOf('-'); if (dashIdx == -1) { // only one port in range: rangeIterator = Iterators.singletonIterator(Integer.valueOf(range)); } else { // evaluate range final int start = Integer.valueOf(range.substring(0, dashIdx)); final int end = Integer.valueOf(range.substring(dashIdx + 1, range.length())); rangeIterator = new Iterator<Integer>() { int i = start; @Override public boolean hasNext() { return i <= end; } @Override public Integer next() { return i++; } @Override public void remove() { throw new UnsupportedOperationException("Remove not supported"); } }; } iterators.add(rangeIterator); } return Iterators.concat(iterators.iterator()); }
From source file:org.bitstrings.maven.plugins.portallocator.PortAllocatorMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { try {//from ww w .j a v a 2 s .c o m if (portAllocators != null) { for (PortAllocator portAllocator : portAllocators) { initPortAllocator(portAllocator); final PortAllocatorService existingPas = PORT_ALLOCATOR_SERVICE_MAP.get(portAllocator.getId()); if (portAllocator.isPermitOverride() || (existingPas == null) || (portAllocator.getId().equals(PORT_ALLOCATOR_DEFAULT_ID) && (existingPas == PORT_ALLOCATOR_SERVICE_DEFAULT))) { PORT_ALLOCATOR_SERVICE_MAP.put(portAllocator.getId(), createPortAllocatorService(portAllocator)); if (!quiet && getLog().isInfoEnabled()) { getLog().info("Registering port allocator [" + portAllocator.getId() + "]"); } } } } if (ports != null) { if ((ports.getPortAllocatorRef() != null) && (ports.getPortAllocator() != null)) { throw new MojoExecutionException( "Either use a port allocator reference or define an inner allocator but you can use both."); } PortAllocatorService pas = ports.getPortAllocator() == null ? PORT_ALLOCATOR_SERVICE_MAP .get(firstNonNull(ports.getPortAllocatorRef(), PORT_ALLOCATOR_DEFAULT_ID)) : createPortAllocatorService(initPortAllocator(ports.getPortAllocator())); if (pas == null) { throw new MojoExecutionException( "Cannot find port allocator [" + ports.getPortAllocatorRef() + "]"); } // assign final LinkedListMultimap<String, Port> portGroupMap = LinkedListMultimap.create(); for (Port port : ports) { final String offsetFrom = port.getOffsetFrom(); final String portGroupName = findGroupRoot(port, portGroupMap); portGroupMap.put(portGroupName, port); if ((offsetFrom != null) && !executionPortMap.containsKey(getPortName(portGroupName))) { throw new MojoExecutionException( "Port [" + port.getName() + "] using offset from undefined [" + offsetFrom + "]."); } Iterator<Port> portIterator = Iterators.singletonIterator(port); while (portIterator.hasNext()) { final Port portToAllocate = portIterator.next(); final Integer previousPort = executionPortMap.remove(getPortName(portToAllocate.getName())); executionPortMap.remove(getOffsetName(portToAllocate.getName())); if (!allocatePort(pas, portToAllocate)) { if (portToAllocate.getOffsetFrom() != null) { portIterator = portGroupMap.get(portGroupName).listIterator(); } } ALLOCATION_LOCK.lock(); ALLOCATED_PORTS.remove(previousPort); ALLOCATION_LOCK.unlock(); } } // log ports for (Port port : ports) { if (!quiet && getLog().isInfoEnabled()) { String name = getPortName(port.getName()); Integer value = executionPortMap.get(name); if (value != null) { getLog().info("Assigning port [" + value + "] to property [" + name + "]"); } name = getOffsetName(port.getName()); value = executionPortMap.get(name); if (value != null) { getLog().info("Assigning offset [" + value + "] " + "using preferred port [" + port.getPreferredPort() + "] " + "to property [" + name + "]"); } } } } if (writePropertiesFile != null) { final File parent = writePropertiesFile.getParentFile(); if ((parent != null) && !parent.exists()) { parent.mkdirs(); } try (final Writer out = new BufferedWriter(new FileWriter(writePropertiesFile))) { if (!quiet && getLog().isInfoEnabled()) { getLog().info("Writing ports file [" + writePropertiesFile + "]"); } final Properties outProps = new Properties(); outProps.putAll(Maps.transformValues(executionPortMap, new Function<Integer, String>() { @Override public String apply(Integer input) { return input.toString(); } })); outProps.store(out, null); } catch (Exception e) { throw new MojoExecutionException("Problem writing ports file [" + writePropertiesFile + "]", e); } } } catch (MojoExecutionException e) { throw e; } catch (Exception e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } }