List of usage examples for java.util.stream Stream toArray
Object[] toArray();
From source file:Main.java
public static void main(String[] args) { List<Integer> numberList = Arrays.asList(1, 2, 3, 4, 5); Stream<Integer> listStream = numberList.stream(); System.out.println(Arrays.toString(listStream.toArray())); }
From source file:Main.java
public static void main(String[] args) { Integer[] numbers = { 1, 2, 3, 4 }; Stream<Integer> arrayStreams1 = Stream.of(numbers); System.out.println(Arrays.toString(arrayStreams1.toArray())); }
From source file:Main.java
public static void main(String[] args) { Integer[] numbers = { 1, 2, 3, 4 }; Stream<Integer> arrayStreams2 = Arrays.stream(numbers); System.out.println(Arrays.toString(arrayStreams2.toArray())); }
From source file:Main.java
public static void main(String[] args) { Set<Integer> numberSet = new HashSet<Integer>() { {//from ww w . ja v a2s. c om add(1); add(2); add(3); } }; Stream<Integer> collectionStream = numberSet.stream(); System.out.println(Arrays.toString(collectionStream.toArray())); }
From source file:com.shenit.commons.utils.CollectionUtils.java
/** * Cast stream as list// ww w . ja v a2 s . c o m * @param stream * @return */ public static List<?> asList(Stream<?> stream) { return stream == null ? null : Arrays.asList(stream.toArray()); }
From source file:freemarker.GoodsController.java
@RequestMapping(value = "/goods", method = RequestMethod.GET) @ResponseBody/*w ww .j av a2 s . c om*/ public List get(final Good good) { final Stream<Good> goodStream = goods.stream().filter(new Predicate<Good>() { public boolean test(Good g) { boolean isOK = true; if (good.getName() != null && good.getName() != "") { if (!g.getName().equals(good.getName())) isOK = false; } if (good.getPrice() != null && good.getPrice() != "") { if (!g.getPrice().equals(good.getPrice())) isOK = false; } if (good.getRecommend() != null && good.getRecommend() != "") { if (!g.getRecommend().equals(good.getRecommend())) isOK = false; } return isOK; } }); return Arrays.asList(goodStream.toArray()); }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
private void ensureUniqueAndIndexingBlocking(String id, JsonObject data, Boolean isNew, AsyncResultHandler<String> resultHandler) { Async.waterfall().<String>task(t -> { RBatch batch = redissonOther.createBatch(); ArrayList<String> pList = new ArrayList(); try {/*from ww w . j a va2 s . c om*/ prepareEnsureUnique(id, data, batch, pList, null); } catch (RepositoryException ex) { t.handle(Future.failedFuture(ex)); return; } if (pList.isEmpty()) { t.handle(Future.succeededFuture()); return; } batch.executeAsync().addListener(future -> { if (future.isSuccess() && future.get() != null) { List<String> result = (List<String>) future.get(); Stream<String> filter = pList.stream().filter( p -> result.get(pList.indexOf(p)) != null && !result.get(pList.indexOf(p)).equals(id));//uniques are ensured by using putIfAbsent and all results should be null or itself to indicate no violation. Object[] filterArray = filter.toArray(); if (filterArray.length != 0) { t.handle(Future.succeededFuture( new JsonObject().put("uniqueViolation", Json.encode(filterArray)).encode())); //now undo these things. ArrayList<String> undoList = pList.stream() .filter(p -> result.get(pList.indexOf(p)) == null || result.get(pList.indexOf(p)).equals(id)) .collect(Collectors.toCollection(ArrayList::new)); Async.<Void>waterfall().<Void>task(task -> { RBatch b = redissonOther.createBatch(); try { prepareUndoUnique(id, data, b, undoList, null); } catch (RepositoryException ex) { task.handle(Future.failedFuture(ex)); } b.executeAsync().addListener(fu -> { task.handle(fu.isSuccess() ? Future.succeededFuture((Void) fu.get()) : Future.failedFuture(fu.cause())); }); }).run(run -> { logger.debug("Parallel undo indexing [id: " + id + "] " + (run.succeeded() ? "successed." : "failed.")); }); } else { t.handle(Future.succeededFuture()); } } else { t.handle(Future.failedFuture(!future.isSuccess() ? future.cause().fillInStackTrace() : new RepositoryException("No unique check result returned"))); } }); }).<String>task((violations, t) -> { if (violations != null) { t.handle(Future.failedFuture(violations)); return; } else { t.handle(Future.succeededFuture()); } //parallel indexing Async.<Void>waterfall().<T>task(task -> { if (!isNew) { fetch(id, Boolean.TRUE, task); } else { task.handle(Future.succeededFuture(null)); } }).<Void>task((r, task) -> { reIndex(id, r, data, isNew, ri -> { task.handle( ri.succeeded() ? Future.succeededFuture(ri.result()) : Future.failedFuture(ri.cause())); }); }).run(run -> { logger.debug("Parallel Indexing [id: " + id + "] " + (run.succeeded() ? "successed." : "failed."), run.cause()); }); }).run(resultHandler); }