Java Code Examples for java.util.ArrayList#stream()
The following examples show how to use
java.util.ArrayList#stream() .
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: MetadataImportBasedOnSchemasTest.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
private Stream<Arguments> getSchemaEndpoints() { ApiResponse apiResponse = schemasActions.get(); String jsonPathIdentifier = "schemas.findAll{it.relativeApiEndpoint && it.metadata && it.singular != 'externalFileResource'}"; List<String> apiEndpoints = apiResponse.extractList( jsonPathIdentifier + ".plural" ); List<String> schemaEndpoints = apiResponse.extractList( jsonPathIdentifier + ".singular" ); ArrayList<Arguments> arguments = new ArrayList<>(); for ( int i = 0; i < apiEndpoints.size(); i++ ) { arguments.add( Arguments.of( apiEndpoints.get( i ), schemaEndpoints.get( i ) ) ); } return arguments.stream(); }
Example 2
Source File: Attribute.java From geoportal-server-harvester with Apache License 2.0 | 6 votes |
/** * Scans attribute for matching sub-attributes. * @param pred predicate * @return stream of matching attributes */ default Stream<Map.Entry<String, Attribute>> scan(Predicate<Map.Entry<String, Attribute>> pred) { ArrayList<Map.Entry<String, Attribute>> attributes = new ArrayList<>(); Map.Entry<String, Attribute> thisAttribute = new ImmutablePair<>(null, this); if (pred.test(thisAttribute)) { attributes.add(thisAttribute); } Map<String, Attribute> namedAttributes = getNamedAttributes(); if (namedAttributes!=null) { attributes.addAll(namedAttributes.entrySet().stream().filter(e->pred.test(e)).collect(Collectors.toList())); attributes.addAll(namedAttributes.entrySet().stream().flatMap(e->e.getValue().scan(pred)).collect(Collectors.toList())); } Attribute[] arrAttributes = getAttributes(); if (arrAttributes!=null) { attributes.addAll(Arrays.stream(arrAttributes).map(attr->new ImmutablePair<String,Attribute>(null, attr)).filter(e->pred.test(e)).collect(Collectors.toList())); attributes.addAll(Arrays.stream(arrAttributes).flatMap(attr->attr.scan(pred)).collect(Collectors.toList())); } return attributes.stream(); }
Example 3
Source File: StreamSerializer.java From baratine with GNU General Public License v2.0 | 6 votes |
@Override public Stream<V> read(JsonReaderImpl in) { Event event = in.next(); if (event == null || event == Event.VALUE_NULL) { return null; } if (event != Event.START_ARRAY) { throw new JsonException(L.l("expected array at {0}", event)); } ArrayList<V> values = new ArrayList<>(); while ((event = in.peek()) != Event.END_ARRAY && event != null) { values.add(_ser.read(in)); } in.next(); return values.stream(); }
Example 4
Source File: ProductsToPickRowsDataFactory.java From metasfresh-webui-api-legacy with GNU General Public License v3.0 | 6 votes |
private Stream<ProductsToPickRow> createRowsAndStream(final AllocablePackageable packageable) { final ArrayList<ProductsToPickRow> rows = new ArrayList<>(); rows.addAll(createRowsFromExistingPickingCandidates(packageable)); rows.addAll(createRowsFromHUs(packageable)); if (!packageable.isAllocated()) { final QtyCalculationsBOM pickingOrderBOM = getPickingOrderBOM(packageable).orElse(null); if (pickingOrderBOM != null) { rows.add(createRowsFromPickingOrder(pickingOrderBOM, packageable)); } } if (!packageable.isAllocated()) { rows.add(createQtyNotAvailableRowForRemainingQtyToAllocate(packageable)); } return rows.stream(); }
Example 5
Source File: MCRMetadataHistoryCommands.java From mycore with GNU General Public License v3.0 | 5 votes |
private static Stream<MCRMetaHistoryItem> buildDerivateHistory(MCRObjectID derId, List<MCRMetadataVersion> versions) throws IOException { boolean exist = false; LogManager.getLogger().debug("Complete history rebuild of {} should be possible", derId); ArrayList<MCRMetaHistoryItem> items = new ArrayList<>(100); for (MCRMetadataVersion version : versions) { String user = version.getUser(); Instant revDate = version.getDate().toInstant(); if (version.getType() == MCRMetadataVersion.DELETED) { if (exist) { items.add(delete(derId, user, revDate)); exist = false; } } else { //created or updated int timeOffset = 0; if (version.getType() == MCRMetadataVersion.CREATED && !exist) { items.add(create(derId, user, revDate)); timeOffset = 1; exist = true; } try { MCRDerivate derivate = new MCRDerivate(version.retrieve().asXML()); boolean derivateIsHidden = !derivate.getDerivate().isDisplayEnabled(); if (derivateIsHidden && exist) { items.add(delete(derId, user, revDate.plusMillis(timeOffset))); exist = false; } else if (!derivateIsHidden && !exist) { items.add(create(derId, user, revDate.plusMillis(timeOffset))); exist = true; } } catch (JDOMException | SAXException e) { LogManager.getLogger() .error("Error while reading revision {} of {}", version.getRevision(), derId, e); } } } return items.stream(); }
Example 6
Source File: TraversalEngine.java From epcis with Apache License 2.0 | 5 votes |
/** * Add a GatherPipe to the end of the Pipeline. All the objects previous to this * step are aggregated in a greedy fashion and emitted as a List. * * Do not use gather twice before scattered. * * Greedy * * Pipeline: Stream -> Stream<Stream> * * @return the extended Pipeline */ public TraversalEngine gather() { // Check Invalid Input element class checkInvalidInputElementClass(List.class); // Pipeline Update List intermediate = (List) stream.collect(Collectors.toList()); ArrayList list = new ArrayList(); list.add(intermediate); if (isParallel) stream = list.parallelStream(); else stream = list.stream(); // Step Update final Class[] args = {}; final Step step = new Step(this.getClass().getName(), "gather", args); stepList.add(step); // Set Class listElementClass = elementClass; elementClass = List.class; return this; }
Example 7
Source File: ExternalTraversalEngine.java From epcis with Apache License 2.0 | 5 votes |
/** * Add a GatherPipe to the end of the Pipeline. All the objects previous to this * step are aggregated in a greedy fashion and emitted as a List. * * Do not use gather twice before scattered. * * Greedy * * Pipeline: Stream -> Stream<Stream> * * @return the extended Pipeline */ public ExternalTraversalEngine gather() { // Check Invalid Input element class checkInvalidInputElementClass(List.class); // Pipeline Update List intermediate = (List) stream.collect(Collectors.toList()); ArrayList list = new ArrayList(); list.add(intermediate); if (isParallel) stream = list.parallelStream(); else stream = list.stream(); // Step Update final Class[] args = {}; final Step step = new Step(this.getClass().getName(), "gather", args); stepList.add(step); // Set Class listElementClass = elementClass; elementClass = List.class; return this; }
Example 8
Source File: NaiveTraversalEngine.java From epcis with Apache License 2.0 | 5 votes |
/** * Add a GatherPipe to the end of the Pipeline. All the objects previous to this * step are aggregated in a greedy fashion and emitted as a List. * * Do not use gather twice before scattered. * * Greedy * * Pipeline: Stream -> Stream<Stream> * * @return the extended Pipeline */ public NaiveTraversalEngine gather() { // Check Invalid Input element class checkInvalidInputElementClass(List.class); // Pipeline Update List intermediate = (List) stream.collect(Collectors.toList()); ArrayList list = new ArrayList(); list.add(intermediate); if (isParallel) stream = list.parallelStream(); else stream = list.stream(); // Step Update final Class[] args = {}; final Step step = new Step(this.getClass().getName(), "gather", args); stepList.add(step); // Set Class listElementClass = elementClass; elementClass = List.class; return this; }
Example 9
Source File: CachedTraversalEngine.java From epcis with Apache License 2.0 | 5 votes |
/** * Add gather step to the traversal engine * * Do not use gather twice before scattered. * * Greedy * * Pipeline: Stream -> Stream<Stream> * * @return the extended Stream */ public CachedTraversalEngine gather() { // Check Invalid Input element class checkInvalidInputElementClass(List.class); // Stream Update List intermediate = (List) stream.collect(Collectors.toList()); ArrayList list = new ArrayList(); list.add(intermediate); // System.out.println(list.size()); if (isParallel) stream = list.parallelStream(); else stream = list.stream(); // Step Update final Class[] args = {}; final Step step = new Step(this.getClass().getName(), "gather", args); stepList.add(step); // Set Class listElementClass = elementClass; elementClass = List.class; return this; }
Example 10
Source File: DeclaredDependenciesTest.java From thorntail with Apache License 2.0 | 5 votes |
private Stream<ArtifactSpec> dependencyStream() { ArrayList<ArtifactSpec> list = new ArrayList<>(); list.add(createSpec("g:a:1.0", COMPILE)); list.add(createSpec("g:a:3.0", PROVIDED)); list.add(createSpec("g:a:2.0", TEST)); list.add(createSpec("g:a:5.0", TEST)); list.add(createSpec("g:a:4.0", PROVIDED)); list.add(createSpec("g:a:6.0", TEST)); list.add(createSpec("g:a:7.0", COMPILE)); list.add(createSpec("g:a:8.0", TEST)); return list.stream(); }
Example 11
Source File: MCRMetadataHistoryCommands.java From mycore with GNU General Public License v3.0 | 5 votes |
private static Stream<MCRMetaHistoryItem> buildObjectHistory(MCRObjectID objId, List<MCRMetadataVersion> versions) throws IOException { boolean exist = false; LogManager.getLogger().debug("Complete history rebuild of {} should be possible", objId); ArrayList<MCRMetaHistoryItem> items = new ArrayList<>(100); for (MCRMetadataVersion version : versions) { String user = version.getUser(); Instant revDate = version.getDate().toInstant(); if (version.getType() == MCRMetadataVersion.DELETED) { if (exist) { items.add(delete(objId, user, revDate)); exist = false; } } else { //created or updated int timeOffset = 0; if (version.getType() == MCRMetadataVersion.CREATED && !exist) { items.add(create(objId, user, revDate)); timeOffset = 1; exist = true; } try { MCRObject obj = new MCRObject(version.retrieve().asXML()); boolean objectIsHidden = MCRMetadataHistoryManager.objectIsHidden(obj); if (objectIsHidden && exist) { items.add(delete(objId, user, revDate.plusMillis(timeOffset))); exist = false; } else if (!objectIsHidden && !exist) { items.add(create(objId, user, revDate.plusMillis(timeOffset))); exist = true; } } catch (JDOMException | SAXException e) { LogManager.getLogger() .error("Error while reading revision {} of {}", version.getRevision(), objId, e); } } } return items.stream(); }
Example 12
Source File: hashToCurveTest.java From teku with Apache License 2.0 | 5 votes |
public static Stream<Arguments> getIndices() { ArrayList<Arguments> args = new ArrayList<>(); for (int i = 0; i < nTest; i++) { args.add(Arguments.of(i)); } return args.stream(); }
Example 13
Source File: ReferenceTests.java From teku with Apache License 2.0 | 5 votes |
@MustBeClosed static Stream<Arguments> hashG2TestCases() { final JSONParser parser = new JSONParser(); final ArrayList<Arguments> argumentsList = new ArrayList<>(); try { final Reader reader = new FileReader(pathToHashG2Tests.toFile(), US_ASCII); final JSONObject refTests = (JSONObject) parser.parse(reader); final Bytes dst = Bytes.wrap(((String) refTests.get("dst")).getBytes(US_ASCII)); final JSONArray tests = (JSONArray) refTests.get("vectors"); int idx = 0; for (Object o : tests) { JSONObject test = (JSONObject) o; Bytes message = Bytes.wrap(((String) test.get("msg")).getBytes(US_ASCII)); JacobianPoint p = getPoint((JSONObject) test.get("P")); JacobianPoint q0 = getPoint((JSONObject) test.get("Q0")); JacobianPoint q1 = getPoint((JSONObject) test.get("Q1")); JSONArray uArray = (JSONArray) test.get("u"); FP2Immutable[] u = { getFieldPoint((String) uArray.get(0)), getFieldPoint((String) uArray.get(1)) }; argumentsList.add( Arguments.of(pathToExpandMessageTests.toString(), idx++, dst, message, u, q0, q1, p)); } } catch (IOException | ParseException e) { throw new RuntimeException(e); } return argumentsList.stream(); }
Example 14
Source File: ReferenceTests.java From teku with Apache License 2.0 | 5 votes |
@MustBeClosed static Stream<Arguments> getExpandMessageTestCases() { final JSONParser parser = new JSONParser(); final ArrayList<Arguments> argumentsList = new ArrayList<>(); try { final Reader reader = new FileReader(pathToExpandMessageTests.toFile(), US_ASCII); final JSONObject refTests = (JSONObject) parser.parse(reader); final Bytes dst = Bytes.wrap(((String) refTests.get("DST")).getBytes(US_ASCII)); final JSONArray tests = (JSONArray) refTests.get("tests"); int idx = 0; for (Object o : tests) { JSONObject test = (JSONObject) o; Bytes message = Bytes.wrap(((String) test.get("msg")).getBytes(US_ASCII)); int length = Integer.parseInt(((String) test.get("len_in_bytes")).substring(2), 16); Bytes uniformBytes = Bytes.fromHexString((String) test.get("uniform_bytes")); argumentsList.add( Arguments.of( pathToExpandMessageTests.toString(), idx++, dst, message, length, uniformBytes)); } } catch (IOException | ParseException e) { throw new RuntimeException(e); } return argumentsList.stream(); }
Example 15
Source File: BLSPerformanceRunner.java From teku with Apache License 2.0 | 5 votes |
public static Stream<Arguments> singleAggregationCountOrder4() { ArrayList<Arguments> args = new ArrayList<>(); args.add(Arguments.of(10)); args.add(Arguments.of(100)); args.add(Arguments.of(1000)); // args.add(Arguments.of(2000)); return args.stream(); }
Example 16
Source File: BLSPerformanceRunner.java From teku with Apache License 2.0 | 5 votes |
public static Stream<Arguments> singleAggregationCount() { ArrayList<Arguments> args = new ArrayList<>(); args.add(Arguments.of(10)); args.add(Arguments.of(100)); args.add(Arguments.of(1000)); args.add(Arguments.of(10000)); // args.add(Arguments.of(100000)); // args.add(Arguments.of(1000000)); return args.stream(); }
Example 17
Source File: ResourcesHandler.java From spring-graalvm-native with Apache License 2.0 | 5 votes |
private Stream<Path> findClasses(Path path) { ArrayList<Path> classfiles = new ArrayList<>(); if (Files.isDirectory(path)) { // System.out.println("Walking dir"); walk(path, classfiles); } else { // System.out.println("Walking jar"); walkJar(path, classfiles); } return classfiles.stream(); }
Example 18
Source File: ResourcesHandler.java From spring-boot-graal-feature with Apache License 2.0 | 4 votes |
private Stream<File> findClasses(File dir) { ArrayList<File> classfiles = new ArrayList<>(); walk(dir,classfiles); return classfiles.stream(); }
Example 19
Source File: ParallelBenchmark.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void runBenchmark(IsolationLevels isolationLevel, SailRepository repository, boolean parallel, boolean mixedReadWrite, Blackhole blackhole) { ArrayList<List<Statement>> allStatements = new ArrayList<>(this.allStatements); if (mixedReadWrite) { for (int i = 0; i < this.allStatements.size() * 10; i++) { allStatements.add(Collections.emptyList()); } } Collections.shuffle(allStatements); Stream<List<Statement>> listStream; if (parallel) { listStream = allStatements.parallelStream(); } else { listStream = allStatements.stream(); } listStream.forEach(statements -> { boolean success = false; while (!success) { try (SailRepositoryConnection connection = repository.getConnection()) { connection.begin(isolationLevel); if (!statements.isEmpty()) { connection.add(statements); } else { // read operation instead of write try (Stream<Statement> stream = connection.getStatements(null, RDF.TYPE, null, false) .stream()) { long count = stream.count(); blackhole.consume(count); } } try { connection.commit(); success = true; } catch (RepositoryException ignored) { } } } }); repository.shutDown(); }