List of usage examples for java.util.stream IntStream range
public static IntStream range(int startInclusive, int endExclusive)
From source file:org.apache.hadoop.hive.metastore.tools.HMSBenchmarks.java
private static void createManyTables(HMSClient client, int howMany, String dbName, String format) { List<FieldSchema> columns = createSchema(new ArrayList<>(Arrays.asList("name", "string"))); List<FieldSchema> partitions = createSchema(new ArrayList<>(Arrays.asList("date", "string"))); IntStream.range(0, howMany) .forEach(i -> throwingSupplierWrapper(() -> client.createTable( new Util.TableBuilder(dbName, String.format(format, i)).withType(TableType.MANAGED_TABLE) .withColumns(columns).withPartitionKeys(partitions).build()))); }
From source file:org.lightjason.agentspeak.action.builtin.TestCActionMath.java
/** * test hypot/*from w w w.j ava 2 s . c om*/ */ @Test public final void hypot() { final Random l_random = new Random(); final List<Double> l_input = IntStream.range(0, 100).mapToDouble(i -> l_random.nextGaussian()).boxed() .collect(Collectors.toList()); final List<ITerm> l_return = new ArrayList<>(); new CHypot().execute(false, IContext.EMPTYPLAN, l_input.stream().map(CRawTerm::from).collect(Collectors.toList()), l_return); Assert.assertArrayEquals(l_return.stream().map(ITerm::<Number>raw).toArray(), StreamUtils.windowed(l_input.stream(), 2, 2).mapToDouble(i -> Math.hypot(i.get(0), i.get(1))) .boxed().toArray()); }
From source file:com.uber.hoodie.common.util.TestCompactionUtils.java
/** * Validates if generated compaction plan matches with input file-slices * * @param input File Slices with partition-path * @param plan Compaction Plan//from w ww . j av a2 s . c om */ private void testFileSlicesCompactionPlanEquality(List<Pair<String, FileSlice>> input, HoodieCompactionPlan plan) { Assert.assertEquals("All file-slices present", input.size(), plan.getOperations().size()); IntStream.range(0, input.size()).boxed() .forEach(idx -> testFileSliceCompactionOpEquality(input.get(idx).getValue(), plan.getOperations().get(idx), input.get(idx).getKey())); }
From source file:com.ikanow.aleph2.graph.titan.services.TitanGraphBuilderEnrichmentService.java
protected void tryRecoverableTransaction(final Consumer<TitanTransaction> transaction, final Runnable on_success) { final Random random_generator = new Random(java.util.UUID.randomUUID().getMostSignificantBits()); IntStream.range(0, 1 + _MAX_ATTEMPT_NUM).boxed().filter(i -> { //(at most 5 attempts) try {//from w w w. ja v a 2s . c o m // Create transaction /**/ //TRACE System.err.println(new java.util.Date().toString() + ": GRABBING TRANS " + i); final TitanTransaction mutable_tx = _titan.get().newTransaction(); /**/ //TRACE System.err.println( new java.util.Date().toString() + ": GRABBED TRANS " + i + " toS=" + mutable_tx.toString()); try { transaction.accept(mutable_tx); } catch (Exception e) { //(close the transaction without saving) /**/ //TRACE System.err.println(new java.util.Date().toString() + ": (ERROR) ROLLING BACK TRANS " + i); mutable_tx.rollback(); throw e; } /**/ //TRACE System.err.println(new java.util.Date().toString() + ": COMMITTING TRANS " + i + " tx=" + mutable_tx.hasModifications() + " open=" + mutable_tx.isOpen() + " toS=" + mutable_tx.toString()); // Attempt to commit mutable_tx.commit(); /**/ //TRACE System.err.println(new java.util.Date().toString() + ": COMMITTED TRANS " + i); on_success.run(); return true; // (ie ends the loop) } catch (TitanException e) { if ((i >= _MAX_ATTEMPT_NUM) || !isRecoverableError(e)) { /**/ //DEBUG System.err.println(new java.util.Date().toString() + ": HERE2 NON_RECOV: " + i + " vs " + _MAX_ATTEMPT_NUM + ErrorUtils.getLongForm(" error={0}", e)); //e.printStackTrace(); _logger.optional().ifPresent(logger -> { logger.log(Level.ERROR, ErrorUtils.lazyBuildMessage(false, () -> "GraphBuilderEnrichmentService", () -> "system.onStageComplete", () -> null, () -> ErrorUtils.getLongForm( "Failed to commit transaction due to local conflicts, attempt_num={1} error={0} (uuid={2})", e, i, UUID), () -> null)); }); throw e; } // If we're here, we're going to retry the transaction /**/ //DEBUG System.err.println(new java.util.Date().toString() + ": HERE3 RECOVERABLE" + ErrorUtils.getLongForm(" error={0}", e)); final int min_sleep_time = _BACKOFF_TIMES_MS[i] / 2; final int sleep_time = min_sleep_time + random_generator.nextInt(min_sleep_time); _logger.optional().ifPresent(logger -> { logger.log(Level.DEBUG, ErrorUtils.lazyBuildMessage(false, () -> "GraphBuilderEnrichmentService", () -> "system.onStageComplete", () -> null, () -> ErrorUtils.get( "Failed to commit transaction due to local conflicts, attempt_num={0} (uuid={1} sleep_ms={2})", i, UUID, sleep_time), () -> null)); }); try { Thread.sleep(sleep_time); } catch (Exception interrupted) { } return false; // (If it's a versioning conflict then try again) } /**/ //TRACE: catch (Throwable x) { System.err.println(new java.util.Date().toString() + ": HERE1 OTHER ERR" + ErrorUtils.getLongForm(" error={0}", x)); //x.printStackTrace(); throw x; } }).findFirst() // ie stop as soon as we have successfully transacted ; }
From source file:org.lightjason.agentspeak.action.builtin.TestCActionMathStatistics.java
/** * test exponential selection with strict parameter *//* w w w. j a v a 2s . co m*/ @Test public final void exponentialselectionstrict() { final List<ITerm> l_return = Collections.synchronizedList(new ArrayList<>()); IntStream.range(0, 5000).parallel() .forEach(i -> new CExponentialSelection().execute(false, IContext.EMPTYPLAN, Stream.of(Stream.of("a", "b").collect(Collectors.toList()), Stream.of(4.5, 3.5).collect(Collectors.toList()), 1).map(CRawTerm::from) .collect(Collectors.toList()), l_return)); Assert.assertEquals( (double) Collections.frequency(l_return.stream().map(ITerm::raw).collect(Collectors.toList()), "a") / l_return.size(), 0.73, 0.02); Assert.assertEquals( (double) Collections.frequency(l_return.stream().map(ITerm::raw).collect(Collectors.toList()), "b") / l_return.size(), 0.27, 0.02); }
From source file:org.apache.hadoop.hive.metastore.tools.HMSBenchmarks.java
private static void dropManyTables(HMSClient client, int howMany, String dbName, String format) { IntStream.range(0, howMany) .forEach(i -> throwingSupplierWrapper(() -> client.dropTable(dbName, String.format(format, i)))); }
From source file:org.apache.sysml.runtime.instructions.spark.SpoofSPInstruction.java
private static int getMainInputIndex(CPOperand[] inputs, boolean[] bcVect) { return IntStream.range(0, bcVect.length).filter(i -> inputs[i].isMatrix() && !bcVect[i]).min().orElse(0); }
From source file:org.ballerinalang.langserver.command.testgen.ValueSpaceGenerator.java
/** * Populates defined space into the templates. Random value generator will be used for the spare values. * * @param definedSpace defined value space * @param template templates set//from w ww .ja v a 2 s . c o m * @param random random value generator */ public static void populateValueSpace(String[] definedSpace, String[] template, Supplier<String> random) { // Populate defined values int min = Math.min(definedSpace.length, template.length); IntStream.range(0, min).forEach(i -> template[i] = template[i].replace(PLACE_HOLDER, definedSpace[i])); // Populate random values int max = Math.max(min, template.length); IntStream.range(0, max) .forEach(index -> template[index] = template[index].replace(PLACE_HOLDER, random.get())); }
From source file:org.apache.zeppelin.service.NotebookServiceTest.java
@Test public void testNormalizeNotePath() throws IOException { assertEquals("/Untitled Note", notebookService.normalizeNotePath(" ")); assertEquals("/Untitled Note", notebookService.normalizeNotePath(null)); assertEquals("/my_note", notebookService.normalizeNotePath("my_note")); assertEquals("/my note", notebookService.normalizeNotePath("my\r\nnote")); try {/*from www . jav a 2 s . c o m*/ String longNoteName = StringUtils.join(IntStream.range(0, 256).boxed().collect(Collectors.toList()), ""); notebookService.normalizeNotePath(longNoteName); fail("Should fail"); } catch (IOException e) { assertEquals("Note name must be less than 255", e.getMessage()); } try { notebookService.normalizeNotePath("my..note"); fail("Should fail"); } catch (IOException e) { assertEquals("Note name can not contain '..'", e.getMessage()); } }
From source file:com.simiacryptus.mindseye.lang.Tensor.java
/** * Get pixel double [ ].// ww w . j a va 2s . co m * * @param tensor the tensor * @param x the x * @param y the y * @param bands the bands * @return the double [ ] */ public static double[] getPixel(final Tensor tensor, final int x, final int y, final int bands) { return IntStream.range(0, bands).mapToDouble(band -> tensor.get(x, y, band)).toArray(); }