List of usage examples for java.util.stream IntStream range
public static IntStream range(int startInclusive, int endExclusive)
From source file:Main.java
private static boolean isPrime(int number) { IntPredicate isDivisible = index -> number % index == 0; return number > 1 && IntStream.range(2, number - 1).noneMatch(isDivisible); }
From source file:Main.java
public static <T> Stream<List<T>> batches(List<T> source, int length) { if (length <= 0) throw new IllegalArgumentException("length = " + length); int size = source.size(); if (size <= 0) return Stream.empty(); int fullChunks = (size - 1) / length; return IntStream.range(0, fullChunks + 1) .mapToObj(n -> source.subList(n * length, n == fullChunks ? size : (n + 1) * length)); }
From source file:io.moquette.spi.impl.DebugUtils.java
public static IntStream intStream(byte[] array) { return IntStream.range(0, array.length).map(idx -> array[idx]); }
From source file:br.ufpr.inf.gres.utils.TestCaseUtils.java
/** * Get the test cases selected indexes in relation the test case set * * @param testCasesSelected The test cases that I want discovery the indexes * @param testCases The test cases set//from w w w . j a va 2s. com * @return * @throws TestCaseSetSelectionException */ public static List<Integer> getVariables(List<String> testCasesSelected, List<TestCase> testCases) throws TestCaseSetSelectionException { return Arrays.asList(ArrayUtils.toObject(IntStream.range(0, testCases.size()) .filter(i -> testCasesSelected.contains(testCases.get(i).getDescription())).toArray())); }
From source file:org.kie.server.services.prometheus.PrometheusMetrics.java
private static double[] rangeNano(int start, int end) { return IntStream.range(start, end).mapToDouble(l -> toNano((long) l)).toArray(); }
From source file:org.kie.server.services.prometheus.PrometheusMetrics.java
private static double[] rangeMicro(int start, int end) { return IntStream.range(start, end).mapToDouble(l -> toMicro((long) l)).toArray(); }
From source file:com.simiacryptus.mindseye.test.PCAUtil.java
/** * Forked from Apache Commons Math// w w w .j av a 2 s .c o m * * @param stream the stream * @return covariance covariance */ @Nonnull public static RealMatrix getCovariance(@Nonnull final Supplier<Stream<double[]>> stream) { final int dimension = stream.get().findAny().get().length; final List<DoubleStatistics> statList = IntStream.range(0, dimension * dimension) .mapToObj(i -> new DoubleStatistics()).collect(Collectors.toList()); stream.get().forEach(array -> { for (int i = 0; i < dimension; i++) { for (int j = 0; j <= i; j++) { statList.get(i * dimension + j).accept(array[i] * array[j]); } } RecycleBin.DOUBLES.recycle(array, array.length); }); @Nonnull final RealMatrix covariance = new BlockRealMatrix(dimension, dimension); for (int i = 0; i < dimension; i++) { for (int j = 0; j <= i; j++) { final double v = statList.get(i + dimension * j).getAverage(); covariance.setEntry(i, j, v); covariance.setEntry(j, i, v); } } return covariance; }
From source file:notaql.engines.json.datamodel.ValueConverter.java
public static Value convertToNotaQL(Object o) { // Atom values if (o == null) return new NullValue(); if (o.equals(JSONObject.NULL)) return new NullValue(); if (o instanceof String) return new StringValue((String) o); if (o instanceof Number) return new NumberValue((Number) o); if (o instanceof Boolean) return new BooleanValue((Boolean) o); // complex values if (o instanceof JSONArray) { final JSONArray array = (JSONArray) o; final ListValue result = new ListValue(); IntStream.range(0, array.length()).forEach(i -> result.add(convertToNotaQL(array.get(i)))); return result; }/*ww w . ja v a 2 s . c o m*/ if (o instanceof JSONObject) { final JSONObject jsonObject = (JSONObject) o; final ObjectValue result = new ObjectValue(); final Iterator<String> keyIterator = jsonObject.keys(); while (keyIterator.hasNext()) { final String key = keyIterator.next(); final Step<String> step = new Step<>(key); final Value value = convertToNotaQL(jsonObject.get(key)); result.put(step, value); } return result; } throw new EvaluationException("Unsupported type read: " + o.getClass() + ": " + o.toString()); }
From source file:org.apache.samza.sql.testutil.ReflectionUtils.java
/** * Create an instance of the specified class with constuctor * matching the argument array.//www . j a v a 2 s .com * @param clazz name of the class * @param args argument array * @param <T> type fo the class * @return instance of the class, or null if anything went wrong */ @SuppressWarnings("unchecked") public static <T> T createInstance(String clazz, Object... args) { Validate.notNull(clazz, "null class name"); try { Class<T> classObj = (Class<T>) Class.forName(clazz); Class<?>[] argTypes = new Class<?>[args.length]; IntStream.range(0, args.length).forEach(i -> argTypes[i] = args[i].getClass()); Constructor<T> ctor = classObj.getDeclaredConstructor(argTypes); return ctor.newInstance(args); } catch (Exception e) { LOG.warn("Failed to create instance for: " + clazz, e); return null; } }
From source file:org.apache.bookkeeper.tools.framework.CommandUtils.java
private static void printIndent(PrintStream printer, int indent) { IntStream.range(0, indent).forEach(ignored -> printer.print(" ")); }