private static void verifyIncidentTraversal(FulgoraElementTraversal<Vertex,Edge> traversal) { //First step must be TitanVertexStep List<Step> steps = traversal.getSteps(); Step<Vertex,?> startStep = steps.get(0); Preconditions.checkArgument(startStep instanceof TitanVertexStep && TitanTraversalUtil.isEdgeReturnStep((TitanVertexStep) startStep),"Expected first step to be an edge step but found: %s",startStep); Optional<Step> violatingStep = steps.stream().filter(s -> !(s instanceof TitanVertexStep || s instanceof OrderGlobalStep || s instanceof OrderLocalStep || s instanceof IdentityStep || s instanceof FilterStep)).findAny(); if (violatingStep.isPresent()) throw new IllegalArgumentException("Encountered unsupported step in incident traversal: " + violatingStep.get()); }
Partition partition = iterator.next(); partitionDetailsMap.entrySet().stream() .filter(entry -> entry.getValue().fullSpec.equals(partition.getSpec())) .findAny().ifPresent(entry -> { entry.getValue().partition = partition; entry.getValue().hasOldPartition = true; try { futures = executor.invokeAll(tasks); LOG.debug("Number of partitionsToAdd to be added is " + futures.size()); for (Future<Partition> future : futures) { Partition partition = future.get(); partitionDetailsMap.entrySet() .stream() .filter(entry -> !entry.getValue().hasOldPartition) .map(entry -> entry.getValue().partition) .collect(Collectors.toList()), throw e; } finally { LOG.debug("Cancelling " + futures.size() + " dynamic loading tasks"); executor.shutdownNow();
private static void testFindFirstSkipCount() { Collection<String> collection = Arrays.asList("a1", "a2", "a3", "a1"); System.out.println("Test findFirst and skip start"); // get first element of collection String first = collection.stream().findFirst().orElse("1"); System.out.println("first = " + first); // print first = a1 // get last element of collection String last = collection.stream().skip(collection.size() - 1).findAny().orElse("1"); System.out.println("last = " + last ); // print last = a1 // find element in collection String find = collection.stream().filter("a3"::equals).findFirst().get(); System.out.println("find = " + find); // print find = a3 // find 3 element in collection String third = collection.stream().skip(2).findFirst().get(); System.out.println("third = " + third); // print third = a3 System.out.println(); System.out.println("Test collect start"); // get all element according pattern List<String> select = collection.stream().filter((s) -> s.contains("1")).collect(Collectors.toList()); System.out.println("select = " + select); // print select = [a1, a1] }
@BeforeClass public static void init() throws Exception { server.start().get(); httpPort = server.activePorts().values().stream() .filter(ServerPort::hasHttp).findAny().get() .localAddress().getPort(); httpsPort = server.activePorts().values().stream() .filter(ServerPort::hasHttps).findAny().get() .localAddress().getPort(); }
private void closeWorker() throws Exception { int nodeCount = getNodeCount(); DistributedQueryRunner queryRunner = (DistributedQueryRunner) getQueryRunner(); TestingPrestoServer worker = queryRunner.getServers().stream() .filter(server -> !server.isCoordinator()) .findAny() .orElseThrow(() -> new IllegalStateException("No worker nodes")); worker.close(); waitForNodes(nodeCount - 1); }
Stream<Integer> quickSort(List<Integer> ints) { // Using a stream to access the data, instead of the simpler ints.isEmpty() if (!ints.stream().findAny().isPresent()) { return Stream.of(); } // treating the ints as a data collection, just like the C# final Integer pivot = ints.get(0); // Using streams to get the two partitions List<Integer> lt = ints.stream().filter(i -> i < pivot).collect(Collectors.toList()); List<Integer> gt = ints.stream().filter(i -> i > pivot).collect(Collectors.toList()); return Stream.concat(Stream.concat(quickSort(lt), Stream.of(pivot)),quickSort(gt)); }
@Test void streamFilesRecursiveRenameMustCanonicaliseTargetFile() throws Exception { // File 'b' should canonicalise from 'b/poke/..' to 'b', which is a file that doesn't exists. // Thus, this should not throw a NoSuchFileException for the 'poke' directory. File a = existingFile( "a" ); File b = new File( new File( new File( path, "b" ), "poke" ), ".." ); FileHandle handle = fsa.streamFilesRecursive( a ).findAny().get(); handle.rename( b ); }
private static ReplicationSourceManager getManagerFromCluster() { // TestReplicationSourceManagerZkImpl won't start the mini hbase cluster. if (utility.getMiniHBaseCluster() == null) { return null; } return utility.getMiniHBaseCluster().getRegionServerThreads() .stream().map(JVMClusterUtil.RegionServerThread::getRegionServer) .findAny() .map(HRegionServer::getReplicationSourceService) .map(r -> (Replication)r) .map(Replication::getReplicationManager) .get(); }
/** * Locates the {@link Transform} that corresponds to the specified model * and uses it to generate a <code>String</code>. If no view is associated * with the model type, an empty <code>Optional</code> will be returned. * * @param model the model * @return the generated text if any */ default Optional<String> on(Object model) { final Object m; if (model instanceof Optional) { final Optional<?> result = (Optional<?>) model; if (result.isPresent()) { m = result.get(); } else { return Optional.empty(); } } else { m = model; } return metaOn(m).map(Meta::getResult).findAny(); }
/** * The simple broker produces {@code SimpMessageType.CONNECT_ACK} that's not STOMP * specific and needs to be turned into a STOMP CONNECTED frame. */ private StompHeaderAccessor convertConnectAcktoStompConnected(StompHeaderAccessor connectAckHeaders) { String name = StompHeaderAccessor.CONNECT_MESSAGE_HEADER; Message<?> message = (Message<?>) connectAckHeaders.getHeader(name); if (message == null) { throw new IllegalStateException("Original STOMP CONNECT not found in " + connectAckHeaders); } StompHeaderAccessor connectHeaders = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); StompHeaderAccessor connectedHeaders = StompHeaderAccessor.create(StompCommand.CONNECTED); if (connectHeaders != null) { Set<String> acceptVersions = connectHeaders.getAcceptVersion(); connectedHeaders.setVersion( Arrays.stream(SUPPORTED_VERSIONS) .filter(acceptVersions::contains) .findAny() .orElseThrow(() -> new IllegalArgumentException( "Unsupported STOMP version '" + acceptVersions + "'"))); } long[] heartbeat = (long[]) connectAckHeaders.getHeader(SimpMessageHeaderAccessor.HEART_BEAT_HEADER); if (heartbeat != null) { connectedHeaders.setHeartbeat(heartbeat[0], heartbeat[1]); } else { connectedHeaders.setHeartbeat(0, 0); } return connectedHeaders; }
/** * Verifies that all entries in the Collection satisfy the predicate. If any do not, throw an * IllegalArgumentException with the specified message for the first invalid entry. */ @VisibleForTesting protected static <T> List<T> validateArgument(List<T> list, Predicate<T> predicate, Function<T, String> msgFn) { final Optional<T> firstInvalid = list.stream() .filter(predicate.negate()) .findAny(); if (firstInvalid.isPresent()) { throw new IllegalArgumentException(firstInvalid.map(msgFn).get()); } return list; }