com.google.common.collect.Iterators Java Examples
The following examples show how to use
com.google.common.collect.Iterators.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PackratParserGenUtil.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public static AbstractElement findFirstWithSameConflicts(final AbstractElement element, final Grammar grammar) { final List<String> conflicting = getConflictingKeywords(element, grammar); AbstractElement result = element; Iterator<AbstractElement> iterator = Iterators.filter( Iterators.filter(EcoreUtil.getAllContents(grammar, true), AbstractElement.class), new Predicate<AbstractElement>() { @Override public boolean apply(AbstractElement param) { final List<String> otherConflicting = getConflictingKeywords(param, grammar); return otherConflicting != null && otherConflicting.equals(conflicting); } }); if (iterator.hasNext()) result = iterator.next(); return result; }
Example #2
Source File: InternalAdapterStoreImpl.java From geowave with Apache License 2.0 | 6 votes |
@Override public short[] getAdapterIds() { final MetadataReader reader = getReader(false); if (reader == null) { return new short[0]; } final CloseableIterator<GeoWaveMetadata> results = reader.query(new MetadataQuery(null, EXTERNAL_TO_INTERNAL_ID)); try (CloseableIterator<Short> it = new CloseableIteratorWrapper<>( results, Iterators.transform( results, input -> ByteArrayUtils.byteArrayToShort(input.getValue())))) { return ArrayUtils.toPrimitive(Iterators.toArray(it, Short.class)); } }
Example #3
Source File: ManageableMailQueueContract.java From james-project with Apache License 2.0 | 6 votes |
@Test default void browseShouldNotFailWhenConcurrentEnqueue() throws Exception { enQueue(defaultMail() .name("name1") .build()); enQueue(defaultMail() .name("name2") .build()); enQueue(defaultMail() .name("name3") .build()); ManageableMailQueue.MailQueueIterator items = getManageableMailQueue().browse(); enQueue(defaultMail() .name("name4") .build()); assertThatCode(() -> Iterators.consumingIterator(items)).doesNotThrowAnyException(); }
Example #4
Source File: Titan0IndexQuery.java From incubator-atlas with Apache License 2.0 | 6 votes |
@Override public Iterator<Result<Titan0Vertex, Titan0Edge>> vertices(int offset, int limit) { Preconditions.checkArgument(offset >=0, "Index offset should be greater than or equals to 0"); Preconditions.checkArgument(limit >=0, "Index limit should be greater than or equals to 0"); Iterator<TitanIndexQuery.Result<Vertex>> results = wrappedIndexQuery .offset(offset) .limit(limit) .vertices().iterator(); Function<TitanIndexQuery.Result<Vertex>, AtlasIndexQuery.Result<Titan0Vertex, Titan0Edge>> function = new Function<TitanIndexQuery.Result<Vertex>, AtlasIndexQuery.Result<Titan0Vertex, Titan0Edge>>() { @Override public AtlasIndexQuery.Result<Titan0Vertex, Titan0Edge> apply(TitanIndexQuery.Result<Vertex> source) { return new ResultImpl(source); } }; return Iterators.transform(results, function); }
Example #5
Source File: BatchInserterTests.java From azure-documentdb-java with MIT License | 6 votes |
@Test public void callbackCount() { BulkImportStoredProcedureOptions options = null; String bulkImportSproc = null; DocumentClient client = Mockito.mock(DocumentClient.class); List<List<String>> batchesToInsert = new ArrayList<>(); batchesToInsert.add(new ArrayList<>()); batchesToInsert.add(new ArrayList<>()); batchesToInsert.add(new ArrayList<>()); String partitionIndex = "0"; BatchInserter bi = new BatchInserter(partitionIndex, batchesToInsert, client, bulkImportSproc, options); Iterator<Callable<InsertMetrics>> callbackIterator = bi.miniBatchInsertExecutionCallableIterator(); List<Callable<InsertMetrics>> list = new ArrayList<>(); Iterators.addAll(list, callbackIterator); assertThat(list.size(), equalTo(3)); }
Example #6
Source File: OffsetMapTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testExpansionWithOrder() { final MutableOffsetMap<String, String> mutable = createMap().toModifiableMap(); mutable.remove("k1"); mutable.put("k3", "v3"); mutable.put("k1", "v1"); assertEquals(ImmutableMap.of("k1", "v1", "k3", "v3"), mutable.newKeys()); final Map<String, String> result = mutable.toUnmodifiableMap(); assertTrue(result instanceof ImmutableOffsetMap); assertEquals(threeEntryMap, result); assertEquals(result, threeEntryMap); assertFalse(Iterators.elementsEqual(threeEntryMap.entrySet().iterator(), result.entrySet().iterator())); }
Example #7
Source File: ReasonerQueryImpl.java From grakn with GNU Affero General Public License v3.0 | 6 votes |
@Override public Iterator<ResolutionState> innerStateIterator(AnswerPropagatorState parent, Set<ReasonerAtomicQuery> subGoals){ Iterator<AnswerState> dbIterator; Iterator<AnswerPropagatorState> subGoalIterator; if(!this.isRuleResolvable()) { Set<Type> queryTypes = new HashSet<>(this.getVarTypeMap().values()); boolean fruitless = context().ruleCache().absentTypes(queryTypes); if (fruitless) dbIterator = Collections.emptyIterator(); else { dbIterator = traversalExecutor.traverse(getPattern()) .map(ans -> new ConceptMap(ans.map(), new JoinExplanation(this.splitToPartialAnswers(ans)), this.withSubstitution(ans).getPattern())) .map(ans -> new AnswerState(ans, parent.getUnifier(), parent)) .iterator(); } subGoalIterator = Collections.emptyIterator(); } else { dbIterator = Collections.emptyIterator(); ResolutionQueryPlan queryPlan = new ResolutionQueryPlan(context().queryFactory(), this); subGoalIterator = Iterators.singletonIterator(new JoinState(queryPlan.queries(), new ConceptMap(), parent.getUnifier(), parent, subGoals)); } return Iterators.concat(dbIterator, subGoalIterator); }
Example #8
Source File: AbstractNode.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public int getOffset() { Iterator<ILeafNode> leafIter = Iterators.filter(basicIterator(), ILeafNode.class); int firstLeafOffset = -1; while(leafIter.hasNext()) { ILeafNode leaf = leafIter.next(); if (firstLeafOffset == -1) { firstLeafOffset = leaf.getTotalOffset(); } if (!leaf.isHidden()) return leaf.getTotalOffset(); } if (firstLeafOffset != -1) return firstLeafOffset; return getTotalOffset(); }
Example #9
Source File: DataStoreJerseyTest.java From emodb with Apache License 2.0 | 6 votes |
/** Test getTimeline() with timestamp start/end instead of UUIDs. */ @Test public void testGetTimelineRESTTimestampsForward() throws Exception { Date start = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2012-03-15 16:12:34.567"); Date end = new Date(); UUID startUuid = TimeUUIDs.uuidForTimestamp(start); UUID endUuid = TimeUUIDs.getPrevious(TimeUUIDs.uuidForTimeMillis(end.getTime() + 1)); when(_server.getTimeline("table-name", "row-key", true, false, startUuid, endUuid, false, 10, ReadConsistency.STRONG)) .thenReturn(Iterators.<Change>emptyIterator()); DateTimeFormatter format = DateTimeFormatter.ISO_INSTANT; URI uri = UriBuilder.fromUri("/sor/1") .segment("table-name", "row-key", "timeline") .queryParam("start", format.format(start.toInstant())) .queryParam("end", format.format(end.toInstant())) .queryParam("reversed", "false") .build(); _resourceTestRule.client().resource(uri) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, APIKEY_TABLE) .get(new GenericType<List<Change>>() { }); verify(_server).getTimeline("table-name", "row-key", true, false, startUuid, endUuid, false, 10, ReadConsistency.STRONG); verifyNoMoreInteractions(_server); }
Example #10
Source File: TezClientUtils.java From tez with Apache License 2.0 | 6 votes |
/** * Populate {@link Credentials} for the URI's to access them from their {@link FileSystem}s * @param uris URIs that need to be accessed * @param credentials Credentials object into which to add the credentials * @param conf Configuration to access the FileSystem * @throws IOException */ public static void addFileSystemCredentialsFromURIs(Collection<URI> uris, Credentials credentials, Configuration conf) throws IOException { // Obtain Credentials for any paths that the user may have configured. if (uris != null && !uris.isEmpty()) { Iterator<Path> pathIter = Iterators.transform(uris.iterator(), new Function<URI, Path>() { @Override public Path apply(URI input) { return new Path(input); } }); Path[] paths = Iterators.toArray(pathIter, Path.class); TokenCache.obtainTokensForFileSystems(credentials, paths, conf); } }
Example #11
Source File: ExceptionAnalyser.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override protected List<Diagnostic> getScriptErrors(Script script) { EcoreUtil.resolveAll(script.eResource()); List<Diagnostic> diagnostics = super.getScriptErrors(script); Iterator<TypableElement> typableASTNodes = Iterators.filter(EcoreUtil2.eAll(script), TypableElement.class); List<Diagnostic> result = Lists.<Diagnostic> newArrayList(Iterables.filter(diagnostics, ExceptionDiagnostic.class)); while (typableASTNodes.hasNext()) { TypableElement typableASTNode = typableASTNodes.next(); RuleEnvironment ruleEnvironment = RuleEnvironmentExtensions.newRuleEnvironment(typableASTNode); try { typeSystem.type(ruleEnvironment, typableASTNode); } catch (Throwable cause) { if (cause instanceof Exception) { result.add(new ExceptionDiagnostic((Exception) cause)); } else { throw new RuntimeException(cause); } } } validator.validate(script.eResource(), CheckMode.ALL, CancelIndicator.NullImpl); return result; }
Example #12
Source File: TripleStore.java From cumulusrdf with Apache License 2.0 | 6 votes |
@Override public Iterator<byte[][]> rangeDateTimeAsIDs( final Value[] query, final Literal lower, final boolean equalsLower, final Literal upper, final boolean equalsUpper, final boolean reverse, final int limit) throws DataAccessLayerException { if (query == null || query.length != 2 || isVariable(query[1])) { return Iterators.emptyIterator(); } final long lowerBound = lower == null ? Long.MIN_VALUE : Util.parseXMLSchemaDateTimeAsMSecs(lower), upperBound = upper == null ? Long.MAX_VALUE : Util.parseXMLSchemaDateTimeAsMSecs(upper); return _rdfIndexDAO.dateRangeQuery(query, lowerBound, equalsLower, upperBound, equalsUpper, reverse, limit); }
Example #13
Source File: EAScoringObserver.java From tac-kbp-eal with MIT License | 6 votes |
@Override public void writeOutput(Iterable<DocumentResult> documentResults, File outputDirectory) throws IOException { // now we compute many "samples" of possible corpora based on our existing corpus. We score each of // these samples and compute confidence intervals from them final Random rng = new Random(bootstrapSeed); final Iterator<Collection<DocumentResult>> bootstrappedResults = Iterators.limit(BootstrapIterator.forData(documentResults, rng), numBootstrapSamples); final List<Map<String, BrokenDownSummaryConfusionMatrix<Symbol>>> resultsForSamples = Lists.newArrayList(); while (bootstrappedResults.hasNext()) { resultsForSamples.add(combineBreakdowns( transform(bootstrappedResults.next(), DocumentResult.GetBreakdownMatricesFunction) .iterator())); } final ImmutableMultimap<String, BrokenDownSummaryConfusionMatrix<Symbol>> resultsByBreakdownType = combineMapsToMultimap(resultsForSamples); writeSampledBreakdownsToFiles(resultsByBreakdownType, outputDirectory); }
Example #14
Source File: StandalonePersistentRecordCache.java From lsmtree with Apache License 2.0 | 6 votes |
public Iterator<Either<Exception, P2<K,V>>> getStreaming(Iterator<K> keys, AtomicInteger progress, AtomicInteger skipped) { log.info("starting store lookups"); final List<Either<Exception, P2<K,V>>> ret = Lists.newArrayList(); int notFound = 0; while (keys.hasNext()) { final K key = keys.next(); final V value; try { value = index.get(key); } catch (IOException e) { log.error("error", e); return Iterators.singletonIterator(Left.<Exception, P2<K,V>>of(new IndexReadException(e))); } if (value != null) { ret.add(Right.<Exception, P2<K,V>>of(P.p(key, value))); } else { notFound++; } } if (progress != null) progress.addAndGet(notFound); if (skipped != null) skipped.addAndGet(notFound); log.info("store lookups complete"); return ret.iterator(); }
Example #15
Source File: DeleteStatement.java From stratio-cassandra with Apache License 2.0 | 6 votes |
protected void validateWhereClauseForConditions() throws InvalidRequestException { Iterator<ColumnDefinition> iterator = Iterators.concat(cfm.partitionKeyColumns().iterator(), cfm.clusteringColumns().iterator()); while (iterator.hasNext()) { ColumnDefinition def = iterator.next(); Restriction restriction = processedKeys.get(def.name); if (restriction == null || !(restriction.isEQ() || restriction.isIN())) { throw new InvalidRequestException( String.format("DELETE statements must restrict all PRIMARY KEY columns with equality relations in order " + "to use IF conditions, but column '%s' is not restricted", def.name)); } } }
Example #16
Source File: SubscriberRegistry.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
/** * Gets an iterator representing an immutable snapshot of all subscribers to the given event at * the time this method is called. */ Iterator<Subscriber> getSubscribers(Object event) { ImmutableSet<Class<?>> eventTypes = flattenHierarchy(event.getClass()); List<Iterator<Subscriber>> subscriberIterators = Lists.newArrayListWithCapacity(eventTypes.size()); for (Class<?> eventType : eventTypes) { CopyOnWriteArraySet<Subscriber> eventSubscribers = subscribers.get(eventType); if (eventSubscribers != null) { // eager no-copy snapshot subscriberIterators.add(eventSubscribers.iterator()); } } return Iterators.concat(subscriberIterators.iterator()); }
Example #17
Source File: UnmodifiableMergingMapView.java From xtext-lib with Eclipse Public License 2.0 | 6 votes |
@Override public Set<Entry<K, V>> entrySet() { // A call to "Sets.union(ks1, ks2)" does not work because of the equals() definition on Map.Entry. // This equality test breaks the unicity of the keys over the resulting Set. // In other words, "Sets.union(ks1, ks2)" replies all the entries that // are different on their keys or values. final Set<Entry<K, V>> diff = difference(this.left, this.right); return new AbstractEarlyFailingSet<Entry<K, V>>() { @SuppressWarnings({ "unchecked", "rawtypes", "synthetic-access" }) @Override public Iterator<Entry<K, V>> iterator() { return Iterators.unmodifiableIterator((Iterator) Iterators.concat( UnmodifiableMergingMapView.this.right.entrySet().iterator(), diff.iterator())); } @Override public int size() { return Iterators.size(iterator()); } }; }
Example #18
Source File: MutableProfile.java From glowroot with Apache License 2.0 | 6 votes |
private void merge(List<Profile.ProfileNode> flatNodes, List<ProfileNode> destinationRootNodes) { destinationStack.push(destinationRootNodes); PeekingIterator<Profile.ProfileNode> i = Iterators.peekingIterator(flatNodes.iterator()); while (i.hasNext()) { Profile.ProfileNode flatNode = i.next(); int destinationDepth = destinationStack.size() - 1; for (int j = 0; j < destinationDepth - flatNode.getDepth(); j++) { // TODO optimize: faster way to pop multiple elements at once destinationStack.pop(); } ProfileNode destinationNode = mergeOne(flatNode, destinationStack.getFirst()); if (i.hasNext() && i.peek().getDepth() > flatNode.getDepth()) { destinationStack.push(destinationNode.childNodes); } } }
Example #19
Source File: MimeMessageHeaders.java From james-project with Apache License 2.0 | 6 votes |
public MimeMessageHeaders(MimeMessage message) throws MessagingException { ImmutableList<Pair<String, String>> headsAndLines = Streams.stream(Iterators.forEnumeration(message.getAllHeaderLines())) .map(Throwing.function(this::extractHeaderLine).sneakyThrow()) .collect(Guavate.toImmutableList()); fields = headsAndLines .stream() .map(Pair::getKey) .collect(Guavate.toImmutableList()); headers = headsAndLines .stream() .collect(Guavate.toImmutableListMultimap( pair -> pair.getKey().toLowerCase(Locale.US), Pair::getValue)); }
Example #20
Source File: LogReader.java From vespa with Apache License 2.0 | 5 votes |
void writeLogs(OutputStream out, Instant from, Instant to) { double fromSeconds = from.getEpochSecond() + from.getNano() / 1e9; double toSeconds = to.getEpochSecond() + to.getNano() / 1e9; BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out)); try { for (List<Path> logs : getMatchingFiles(from, to)) { List<LogLineIterator> logLineIterators = new ArrayList<>(); try { // Logs in each sub-list contain entries covering the same time interval, so do a merge sort while reading for (Path log : logs) logLineIterators.add(new LogLineIterator(log, fromSeconds, toSeconds)); Iterator<LineWithTimestamp> lines = Iterators.mergeSorted(logLineIterators, Comparator.comparingDouble(LineWithTimestamp::timestamp)); while (lines.hasNext()) { writer.write(lines.next().line()); writer.newLine(); } } catch (IOException e) { throw new UncheckedIOException(e); } finally { for (LogLineIterator ll : logLineIterators) { try { ll.close(); } catch (IOException ignored) { } } } } } finally { Exceptions.uncheck(writer::flush); } }
Example #21
Source File: CascadeDeleteRepositoryDecorator.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void delete(Stream<Entity> entities) { if (hasCascadeDeleteAttributes()) { Iterators.partition(entities.iterator(), BATCH_SIZE) .forEachRemaining( entitiesBatch -> { entitiesBatch.forEach(this::prepareCascadeDeletes); super.delete(entitiesBatch.stream()); entitiesBatch.forEach(this::handleCascadeDeletes); }); } else { delegate().delete(entities); } }
Example #22
Source File: ITLoggingSnippets.java From google-cloud-java with Apache License 2.0 | 5 votes |
@Test public void testWriteAndListLogEntriesAsync() throws ExecutionException, InterruptedException { String logName = RemoteLoggingHelper.formatForTest("log_name"); String filter = "logName=projects/" + logging.getOptions().getProjectId() + "/logs/" + logName; loggingSnippets.write(logName); // flush all pending asynchronous writes logging.flush(); Iterator<LogEntry> iterator = loggingSnippets.listLogEntriesAsync(filter).iterateAll().iterator(); while (Iterators.size(iterator) < 2) { Thread.sleep(500); iterator = loggingSnippets.listLogEntriesAsync(filter).iterateAll().iterator(); } assertTrue(loggingSnippets.deleteLogAsync(logName)); }
Example #23
Source File: GitMapSourceFactory.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@Override public Iterator<? extends MapSource> loadNewSources() throws MapMissingException { try { git.pull() .setCredentialsProvider(credentials) .setFastForward(MergeCommand.FastForwardMode.FF) .call(); } catch (GitAPIException e) { throw new MapMissingException( git.getRepository().getDirectory().getPath(), e.getMessage(), e.getCause()); } return Iterators.emptyIterator(); }
Example #24
Source File: IndexMaintainer.java From phoenix with Apache License 2.0 | 5 votes |
public static Iterator<PTable> maintainedIndexes(Iterator<PTable> indexes) { return Iterators.filter(indexes, new Predicate<PTable>() { @Override public boolean apply(PTable index) { return sendIndexMaintainer(index); } }); }
Example #25
Source File: JcloudsLocation.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected MachineManagementMixins.MachineMetadata getMachineMetadata(ComputeMetadata node) { if (node==null) return null; return new BasicMachineMetadata(node.getId(), node.getName(), ((node instanceof NodeMetadata) ? Iterators.tryFind( ((NodeMetadata)node).getPublicAddresses().iterator(), Predicates.alwaysTrue() ).orNull() : null), ((node instanceof NodeMetadata) ? ((NodeMetadata)node).getStatus()==Status.RUNNING : null), node); }
Example #26
Source File: ParameterListTreeImpl.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
@Override public Iterator<Tree> childrenIterator() { return Iterators.concat( Iterators.singletonIterator(openParenthesis), parameters.elementsAndSeparators(Functions.<ExpressionTree>identity()), Iterators.singletonIterator(closeParenthesis)); }
Example #27
Source File: EdgeTest.java From hugegraph-client with Apache License 2.0 | 5 votes |
@Test public void testIterateEdgesByLabel() { BaseClientTest.initEdge(); Iterator<Edge> edges = graph().iterateEdges("created", 1); Assert.assertEquals(4, Iterators.size(edges)); edges = graph().iterateEdges("knows", 1); Assert.assertEquals(2, Iterators.size(edges)); }
Example #28
Source File: DateIndexDateAggregatorTest.java From datawave with Apache License 2.0 | 5 votes |
@Test public void testSingleShard() { agg.reset(); BitSet bitSet = new BitSet(20); bitSet.set(20); Value val = new Value(bitSet.toByteArray()); Value result = agg.reduce(new Key("key"), Iterators.singletonIterator(val)); assertNotNull(result); assertNotNull(result.get()); assertNotNull(val.get()); assertEquals(0, val.compareTo(result.get())); }
Example #29
Source File: MixinMultiMap.java From Hyperium with GNU Lesser General Public License v3.0 | 5 votes |
/** * @author FalseHonesty * @reason ChatTriggers */ @Overwrite public <S> Iterable<S> getByClass(final Class<S> clazz) { return () -> { List<T> list = map.get(initializeClassLookup(clazz)); if (list == null) { return (UnmodifiableListIterator<S>) Utils.EMPTY_ITERATOR; } else { Iterator<T> iterator = list.iterator(); return Iterators.filter(iterator, clazz); } }; }
Example #30
Source File: TestPartitionReplacement.java From kite with Apache License 2.0 | 5 votes |
@Test public void testUnpartitionedReplace() { // recreate temporary without a partition strategy Datasets.delete("dataset:file:/tmp/datasets/temporary"); DatasetDescriptor descriptor = new DatasetDescriptor .Builder(unpartitioned.getDescriptor()) .location((URI) null) // clear the location .build(); temporary = Datasets.create("dataset:file:/tmp/datasets/temporary", descriptor, TestRecord.class); Assert.assertTrue("Should allow replacing an unpartitioned dataset", unpartitioned.canReplace(unpartitioned)); // make sure there are multiple files writeTestRecords(unpartitioned); writeTestRecords(unpartitioned); writeTestRecords(temporary); writeTestRecords(temporary); Set<String> originalFiles = Sets.newHashSet( Iterators.transform(unpartitioned.pathIterator(), new GetFilename())); Set<String> replacementFiles = Sets.newHashSet( Iterators.transform(temporary.pathIterator(), new GetFilename())); Iterators.transform(temporary.pathIterator(), new GetFilename()); Assert.assertFalse("Sanity check", originalFiles.equals(replacementFiles)); unpartitioned.replace(unpartitioned, temporary); Set<String> replacedFiles = Sets.newHashSet( Iterators.transform(unpartitioned.pathIterator(), new GetFilename())); Assert.assertEquals("Should contain the replacement files", replacementFiles, replacedFiles); }