use of java.util.stream.Stream in project buck by facebook.
the class IjModuleGraph method createModules.
/**
* Create all the modules we are capable of representing in IntelliJ from the supplied graph.
*
* @param targetGraph graph whose nodes will be converted to {@link IjModule}s.
* @return map which for every BuildTarget points to the corresponding IjModule. Multiple
* BuildTarget can point to one IjModule (many:one mapping), the BuildTargets which
* can't be prepresented in IntelliJ are missing from this mapping.
*/
private static ImmutableMap<BuildTarget, IjModule> createModules(IjProjectConfig projectConfig, TargetGraph targetGraph, IjModuleFactory moduleFactory, final int minimumPathDepth) {
final BlockedPathNode blockedPathTree = createAggregationHaltPoints(projectConfig, targetGraph);
ImmutableListMultimap<Path, TargetNode<?, ?>> baseTargetPathMultimap = targetGraph.getNodes().stream().filter(input -> IjModuleFactory.SUPPORTED_MODULE_DESCRIPTION_CLASSES.contains(input.getDescription().getClass())).collect(MoreCollectors.toImmutableListMultimap(targetNode -> {
Path path;
Path basePath = targetNode.getBuildTarget().getBasePath();
if (targetNode.getConstructorArg() instanceof AndroidResourceDescription.Arg) {
path = basePath;
} else {
path = simplifyPath(basePath, minimumPathDepth, blockedPathTree);
}
return path;
}, targetNode -> targetNode));
ImmutableMap.Builder<BuildTarget, IjModule> moduleMapBuilder = new ImmutableMap.Builder<>();
for (Path baseTargetPath : baseTargetPathMultimap.keySet()) {
ImmutableSet<TargetNode<?, ?>> targets = ImmutableSet.copyOf(baseTargetPathMultimap.get(baseTargetPath));
IjModule module = moduleFactory.createModule(baseTargetPath, targets);
for (TargetNode<?, ?> target : targets) {
moduleMapBuilder.put(target.getBuildTarget(), module);
}
}
return moduleMapBuilder.build();
}
use of java.util.stream.Stream in project elasticsearch by elastic.
the class UnicastZenPing method sendPings.
protected void sendPings(final TimeValue timeout, final PingingRound pingingRound) {
final UnicastPingRequest pingRequest = new UnicastPingRequest();
pingRequest.id = pingingRound.id();
pingRequest.timeout = timeout;
DiscoveryNodes discoNodes = contextProvider.nodes();
pingRequest.pingResponse = createPingResponse(discoNodes);
Set<DiscoveryNode> nodesFromResponses = temporalResponses.stream().map(pingResponse -> {
assert clusterName.equals(pingResponse.clusterName()) : "got a ping request from a different cluster. expected " + clusterName + " got " + pingResponse.clusterName();
return pingResponse.node();
}).collect(Collectors.toSet());
// dedup by address
final Map<TransportAddress, DiscoveryNode> uniqueNodesByAddress = Stream.concat(pingingRound.getSeedNodes().stream(), nodesFromResponses.stream()).collect(Collectors.toMap(DiscoveryNode::getAddress, Function.identity(), (n1, n2) -> n1));
// resolve what we can via the latest cluster state
final Set<DiscoveryNode> nodesToPing = uniqueNodesByAddress.values().stream().map(node -> {
DiscoveryNode foundNode = discoNodes.findByAddress(node.getAddress());
if (foundNode == null) {
return node;
} else {
return foundNode;
}
}).collect(Collectors.toSet());
nodesToPing.forEach(node -> sendPingRequestToNode(node, timeout, pingingRound, pingRequest));
}
use of java.util.stream.Stream in project useful-java-links by Vedenin.
the class BuildTests method testBuildStream.
// All way to create Stream
private static void testBuildStream() throws Exception {
System.out.println("Test buildStream start");
// Create Stream from values
Stream<String> streamFromValues = Stream.of("a1", "a2", "a3");
// print streamFromValues = [a1, a2, a3]
System.out.println("streamFromValues = " + streamFromValues.collect(Collectors.toList()));
// Create Stream from array
String[] array = { "a1", "a2", "a3" };
Stream<String> streamFromArrays = Arrays.stream(array);
// print streamFromArrays = [a1, a2, a3]
System.out.println("streamFromArrays = " + streamFromArrays.collect(Collectors.toList()));
Stream<String> streamFromArrays1 = Stream.of(array);
// print streamFromArrays = [a1, a2, a3]
System.out.println("streamFromArrays1 = " + streamFromArrays1.collect(Collectors.toList()));
// Create Stream from file
File file = new File("1.tmp");
file.deleteOnExit();
PrintWriter out = new PrintWriter(file);
out.println("a1");
out.println("a2");
out.println("a3");
out.close();
Stream<String> streamFromFiles = Files.lines(Paths.get(file.getAbsolutePath()));
// print streamFromFiles = [a1, a2, a3]
System.out.println("streamFromFiles = " + streamFromFiles.collect(Collectors.toList()));
// Create Stream from collection
Collection<String> collection = Arrays.asList("a1", "a2", "a3");
Stream<String> streamFromCollection = collection.stream();
// print streamFromCollection = [a1, a2, a3]
System.out.println("streamFromCollection = " + streamFromCollection.collect(Collectors.toList()));
// Create Stream from string
IntStream streamFromString = "123".chars();
System.out.print("streamFromString = ");
// print streamFromString = 49 , 50 , 51 ,
streamFromString.forEach((e) -> System.out.print(e + " , "));
System.out.println();
// Using Stream.builder
Stream.Builder<String> builder = Stream.builder();
Stream<String> streamFromBuilder = builder.add("a1").add("a2").add("a3").build();
// print streamFromFiles = [a1, a2, a3]
System.out.println("streamFromBuilder = " + streamFromBuilder.collect((Collectors.toList())));
// Create infinite stream
// Using Stream.iterate
Stream<Integer> streamFromIterate = Stream.iterate(1, n -> n + 2);
// print streamFromIterate = [1, 3, 5]
System.out.println("streamFromIterate = " + streamFromIterate.limit(3).collect(Collectors.toList()));
// Using Stream.generate
Stream<String> streamFromGenerate = Stream.generate(() -> "a1");
// print streamFromGenerate = [a1, a1, a1]
System.out.println("streamFromGenerate = " + streamFromGenerate.limit(3).collect(Collectors.toList()));
// Create empty stream
Stream<String> streamEmpty = Stream.empty();
// print streamEmpty = []
System.out.println("streamEmpty = " + streamEmpty.collect(Collectors.toList()));
// Create parallel Stream from collection
Stream<String> parallelStream = collection.parallelStream();
// print parallelStream = [a1, a2, a3]
System.out.println("parallelStream = " + parallelStream.collect(Collectors.toList()));
// Create stream from path
Stream<Path> streamFromPath = Files.list(Paths.get(""));
// print list of files
System.out.println("streamFromPath = " + streamFromPath.collect(Collectors.toList()));
// Create stream from finding files
Stream<Path> streamFromFind = Files.find(Paths.get(""), 10, (p, a) -> true);
// print list of files
System.out.println("streamFromFind = " + streamFromFind.collect(Collectors.toList()));
// Create stream from files tree
Stream<Path> streamFromFileTree = Files.walk(Paths.get(""));
// print list of files
System.out.println("streamFromFileTree = " + streamFromFileTree.collect(Collectors.toList()));
// Create stream from Pattern
Stream<String> streamFromPattern = Pattern.compile(":").splitAsStream("a1:a2:a3");
// print a1,a2,a3
System.out.println("streamFromPattern = " + streamFromPattern.collect(Collectors.joining(",")));
// Create stream from BufferedReader
// create temp file
Path path = Files.write(Paths.get("./test.txt"), "test 1\ntest 2".getBytes());
try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
Stream<String> streamFromBufferedReader = reader.lines();
// print [test 1, test 2]
System.out.println("streamFromBufferedReader = " + streamFromBufferedReader.collect(Collectors.toList()));
}
}
use of java.util.stream.Stream in project failsafe by jhalterman.
the class Java8Example method main.
@SuppressWarnings("unused")
public static void main(String... args) {
ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
RetryPolicy retryPolicy = new RetryPolicy();
// Create a retryable functional interface
Function<String, String> bar = value -> Failsafe.with(retryPolicy).get(() -> value + "bar");
// Create a retryable runnable Stream
Failsafe.with(retryPolicy).run(() -> Stream.of("foo").map(value -> value + "bar").forEach(System.out::println));
// Create a retryable callable Stream
Failsafe.with(retryPolicy).get(() -> Stream.of("foo").map(value -> Failsafe.with(retryPolicy).get(() -> value + "bar")).collect(Collectors.toList()));
// Create a individual retryable Stream operation
Stream.of("foo").map(value -> Failsafe.with(retryPolicy).get(() -> value + "bar")).forEach(System.out::println);
// Create a retryable CompletableFuture
Failsafe.with(retryPolicy).with(executor).future(() -> CompletableFuture.supplyAsync(() -> "foo").thenApplyAsync(value -> value + "bar").thenAccept(System.out::println));
// Create an individual retryable CompletableFuture stages
CompletableFuture.supplyAsync(() -> Failsafe.with(retryPolicy).get(() -> "foo")).thenApplyAsync(value -> Failsafe.with(retryPolicy).get(() -> value + "bar")).thenAccept(System.out::println);
}
use of java.util.stream.Stream in project hibernate-orm by hibernate.
the class CorrectnessTestCase method beforeClass.
@BeforeClassOnce
public void beforeClass() {
TestResourceTracker.testStarted(getClass().getSimpleName());
Arrays.asList(new File(System.getProperty("java.io.tmpdir")).listFiles((dir, name) -> name.startsWith("family_") || name.startsWith("invalidations-"))).stream().forEach(f -> f.delete());
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true").applySetting(Environment.USE_QUERY_CACHE, "true").applySetting(Environment.DRIVER, "org.h2.Driver").applySetting(Environment.URL, "jdbc:h2:mem:" + getDbName() + ";TRACE_LEVEL_FILE=4").applySetting(Environment.DIALECT, H2Dialect.class.getName()).applySetting(Environment.HBM2DDL_AUTO, "create-drop").applySetting(Environment.CACHE_REGION_FACTORY, FailingInfinispanRegionFactory.class.getName()).applySetting(TestInfinispanRegionFactory.CACHE_MODE, cacheMode).applySetting(Environment.USE_MINIMAL_PUTS, "false").applySetting(Environment.GENERATE_STATISTICS, "false");
applySettings(ssrb);
sessionFactories = new SessionFactory[NUM_NODES];
for (int i = 0; i < NUM_NODES; ++i) {
StandardServiceRegistry registry = ssrb.build();
Metadata metadata = buildMetadata(registry);
sessionFactories[i] = metadata.buildSessionFactory();
}
}
Aggregations