Util { public static Stream<List<Object>> partitionSubList(List<Object> data, int partitions) { return partitionSubList(data,partitions,null); }  static String labelString(List<String> labelNames); static String labelString(Node n); static String joinLabels(Iterable<Label> labels, String s); static List<String> labelStrings(Node n); static Label[] labels(Object labelNames); static RelationshipType type(Object type); @SuppressWarnings("unchecked") static LongStream ids(Object ids); static Stream<Object> stream(Object values); static Stream<Node> nodeStream(Transaction tx, Object ids); static Node node(Transaction tx, Object id); static Stream<Relationship> relsStream(Transaction tx, Object ids); static Relationship relationship(Transaction tx, Object id); static double doubleValue(Entity pc, String prop, Number defaultValue); static double doubleValue(Entity pc, String prop); static Direction parseDirection(String direction); static RelationshipType[] toRelTypes(List<String> relTypeStrings); static T retryInTx(Log log, GraphDatabaseService db, Function<Transaction, T> function, long retry, long maxRetries, Consumer<Long> callbackForRetry); static Future<T> inTxFuture(Log log,
                                           ExecutorService pool,
                                           GraphDatabaseService db,
                                           Function<Transaction, T> function,
                                           long maxRetries,
                                           Consumer<Long> callbackForRetry,
                                           Consumer<Void> callbackAction); static Future<T> inTxFuture(ExecutorService pool, GraphDatabaseService db, Function<Transaction, T> function); static T inTx(GraphDatabaseService db, Pools pools, Function<Transaction, T> function); static T inThread(Pools pools, Callable<T> callable); static Future<T> inFuture(Pools pools, Callable<T> callable); static Double toDouble(Object value); static Map<String, Object> subMap(Map<String, ?> params, String prefix); static Long toLong(Object value); static Integer toInteger(Object value); static URLConnection openUrlConnection(String url, Map<String, Object> headers); static boolean isRedirect(HttpURLConnection con); static CountingInputStream openInputStream(String urlAddress, Map<String, Object> headers, String payload); static boolean toBoolean(Object value); static String encodeUrlComponent(String value); static String toJson(Object value); static T fromJson(String value, Class<T> type); static Stream<List<Object>> partitionSubList(List<Object> data, int partitions); static Stream<List<Object>> partitionSubList(List<Object> data, int partitions, List<Object> tombstone); static Long runNumericQuery(Transaction tx, String query, Map<String, Object> params); static long nodeCount(Transaction tx); static long relCount(Transaction tx); static LongStream toLongStream(LongIterator it); static String readResourceFile(String name); @SuppressWarnings("unchecked") static Map<String,Object> readMap(String value); static List<T> take(Iterator<T> iterator, int batchsize); static Map<String, Object> merge(Map<String, Object> first, Map<String, Object> second); static Map<String, T> map(T ... values); static Map<String, T> map(List<T> pairs); static List<R> map(Stream<T> stream, Function<T,R> mapper); static List<R> map(Collection<T> collection, Function<T,R> mapper); static Map<String, Object> mapFromLists(List<String> keys, List<Object> values); static Map<String, Object> mapFromPairs(List<List<Object>> pairs); static String cleanUrl(String url); static T getFuture(Future<T> f, Map<String, Long> errorMessages, AtomicInteger errors, T errorValue); static T getFutureOrCancel(Future<T> f, Map<String, Long> errorMessages, AtomicInteger errors, T errorValue); static boolean isSumOutOfRange(long... numbers); static BigInteger sumLongs(long... numbers); static void logErrors(String message, Map<String, Long> errors, Log log); static void checkAdmin(SecurityContext securityContext, String procedureName); static void sleep(int millis); static String quote(String var); static String sanitizeAndQuote(String var); static String param(String var); static String withMapping(Stream<String> columns, Function<String, String> withMapping); static boolean isWriteableInstance(GraphDatabaseAPI db); static boolean transactionIsTerminated(TerminationGuard db); static void waitForFutures(List<Future> futures); static void removeFinished(List<Future> futures); static void close(Closeable closeable); static boolean isNotNullOrEmpty(String s); static boolean isNullOrEmpty(String s); static Map<String, String> getRequestParameter(String parameters); static boolean classExists(String className); static T createInstanceOrNull(String className); static Optional<String> getLoadUrlByConfigFile(String loadType, String key, String suffix); static String dateFormat(TemporalAccessor value, String format); static Duration durationParse(String value); static DateTimeFormatter getFormat(String format); static char parseCharFromConfig(Map<String, Object> config, String key, char defaultValue); static Map<String, Object> flattenMap(Map<String, Object> map); static Map<String, Object> flattenMap(Map<String, Object> map, String prefix); static Node rebind(Transaction tx, Node node); static Relationship rebind(Transaction tx, Relationship rel); static Entity rebind(Transaction tx, Entity e); static Node mergeNode(Transaction tx, Label primaryLabel, Label addtionalLabel,
                                 Pair<String, Object>... pairs ); static Set<T> intersection(Collection<T> a, Collection<T> b); static void validateQuery(GraphDatabaseService db, String statement); static Thread newDaemonThread(Runnable target); static final Label[] NO_LABELS; static final String NODE_COUNT; static final String REL_COUNT; static final String COMPILED; }
@Test public void testPartitionList() throws Exception { List list = asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); assertEquals(1,Util.partitionSubList(list,0).count()); assertEquals(1,Util.partitionSubList(list,1).count()); assertEquals(2,Util.partitionSubList(list,2).count()); assertEquals(3,Util.partitionSubList(list,3).count()); assertEquals(4,Util.partitionSubList(list,4).count()); assertEquals(5,Util.partitionSubList(list,5).count()); assertEquals(5,Util.partitionSubList(list,6).count()); assertEquals(5,Util.partitionSubList(list,7).count()); assertEquals(5,Util.partitionSubList(list,8).count()); assertEquals(5,Util.partitionSubList(list,9).count()); assertEquals(10,Util.partitionSubList(list,10).count()); assertEquals(10,Util.partitionSubList(list,11).count()); assertEquals(10,Util.partitionSubList(list,20).count()); }