Example usage for java.util.stream IntStream range

List of usage examples for java.util.stream IntStream range

Introduction

In this page you can find the example usage for java.util.stream IntStream range.

Prototype

public static IntStream range(int startInclusive, int endExclusive) 

Source Link

Document

Returns a sequential ordered IntStream from startInclusive (inclusive) to endExclusive (exclusive) by an incremental step of 1 .

Usage

From source file:eu.amidst.core.exponentialfamily.EF_Normal_NormalParents2.java

/**
 * {@inheritDoc}// w ww  .j av  a  2s .  c  o  m
 */
@Override
public double getExpectedLogNormalizer(Map<Variable, MomentParameters> momentParents) {
    CompoundVector globalNaturalParameters = (CompoundVector) this.naturalParameters;
    double logNorm = -0.5 * Math.log(-2 * globalNaturalParameters.getTheta_Minus1());

    double[] Yarray = new double[nOfParents];
    double[] YYarray = new double[nOfParents];

    for (int i = 0; i < nOfParents; i++) {
        Yarray[i] = momentParents.get(this.getConditioningVariables().get(i)).get(0);
        YYarray[i] = momentParents.get(this.getConditioningVariables().get(i)).get(1);
    }
    RealVector Y = new ArrayRealVector(Yarray);

    logNorm -= globalNaturalParameters.getTheta_beta0BetaRV().dotProduct(new ArrayRealVector(Y));

    RealMatrix YY = Y.outerProduct(Y);
    for (int i = 0; i < nOfParents; i++) {
        YY.setEntry(i, i, YYarray[i]);
    }

    logNorm -= IntStream.range(0, nOfParents).mapToDouble(p -> {
        return globalNaturalParameters.getTheta_BetaBetaRM().getRowVector(p).dotProduct(YY.getRowVector(p));
    }).sum();

    logNorm -= Math.pow(globalNaturalParameters.getTheta_beta0(), 2)
            / (4 * globalNaturalParameters.getTheta_Minus1());

    return logNorm;
}

From source file:com.netflix.imfutility.itunes.audio.ChannelsMapper.java

private List<Pair<SequenceUUID, Integer>> guessChannelsByOrder(LayoutType layoutType) {
    List<Pair<SequenceUUID, Integer>> channels = channelsByOrder.stream()
            .limit(channelsByOrder.size() >= layoutType.maxSize ? layoutType.maxSize : layoutType.minSize)
            .collect(Collectors.toList());

    // not enough channels for layout
    if (channels.size() < layoutType.minSize) {
        return new ArrayList<>();
    }/*  w  w w. ja  va 2 s.com*/

    // add used channels for correct layout definition
    // for Surround -> Lt=FL, Rt=FR
    // for Stereo -> L=FC, R=FC (stereo from two monos)
    IntStream.range(0, layoutType.maxSize - channels.size()).mapToObj(channels::get).forEach(channels::add);
    return channels;
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionStorage.java

/**
 * test exists action without keys//from  w w w.  jav  a  2s.  com
 */
@Test
public final void existswithoutkeys() {
    Assume.assumeNotNull(m_context);

    final List<ITerm> l_content = IntStream.range(0, 100).mapToObj(i -> RandomStringUtils.random(25))
            .peek(i -> m_context.agent().storage().put(i, RandomStringUtils.random(5))).map(CRawTerm::from)
            .collect(Collectors.toList());

    final List<ITerm> l_return = new ArrayList<>();
    new CExists().execute(false, m_context, l_content, l_return);

    Assert.assertEquals(l_return.size(), 100);
    Assert.assertTrue(l_return.stream().allMatch(ITerm::<Boolean>raw));
}

From source file:de.fosd.jdime.artifact.file.FileArtifact.java

/**
 * Constructs a new virtual {@link FileArtifact} representing a non-existent {@link File} with a generated name. The
 * new {@link FileArtifact} will always have the number 0.
 *
 * @param revision/*  w w w  .j  a v a  2s  . c om*/
 *         the {@link Revision} the artifact belongs to
 * @param type
 *         the virtual type for the {@link FileArtifact}, must be one of {@link FileType#FILE} or
 *         {@link FileType#DIR}
 */
public FileArtifact(Revision revision, FileType type) {
    super(revision, 0);

    this.type = type;
    this.original = null;

    File tempDir = FileUtils.getTempDirectory();
    IntFunction<File> toFile;

    if (type == FileType.DIR) {
        toFile = n -> {
            synchronized (virtualNameSupplier) {
                return new File(tempDir, "VirtualDirectory_" + virtualNameSupplier.get());
            }
        };
    } else {
        toFile = n -> {
            synchronized (virtualNameSupplier) {
                return new File(tempDir, "VirtualFile_" + virtualNameSupplier.get());
            }
        };
    }

    this.file = IntStream.range(0, Integer.MAX_VALUE).mapToObj(toFile).filter(f -> !f.exists()).findFirst()
            .orElseThrow(() -> new AbortException(
                    "Could not find an available file name for the virtual file or directory."));
}

From source file:fi.hsl.parkandride.itest.AbstractReportingITest.java

protected List<String> getSheetNames(Workbook workbook) {
    return IntStream.range(0, workbook.getNumberOfSheets()).mapToObj(i -> workbook.getSheetName(i))
            .collect(toList());/*from  w ww . jav a2s  .c o m*/
}

From source file:org.ligoj.app.plugin.vm.aws.VmAwsPluginResource.java

/**
 * Build described beans from a XML result.
 *///from  www .  j  a  v  a  2  s . c o  m
private List<AwsVm> toVms(final String vmAsXml, final Function<Element, AwsVm> parser) throws Exception {
    final NodeList items = xml.getXpath(vmAsXml,
            "/DescribeInstancesResponse/reservationSet/item/instancesSet/item");
    return IntStream.range(0, items.getLength()).mapToObj(items::item).map(n -> parser.apply((Element) n))
            .collect(Collectors.toList());
}

From source file:com.hengyi.japp.print.client.controller.MdController.java

@FXML
private void handleAutoXd() {
    try {/*  w  ww .j  a  v a2  s .  co  m*/
        MdValidate.checkMdInput(md);
        md.xdsProperty().clear();
        md.setXds(FXCollections.observableArrayList(IntStream.range(0, md.getZcanmge()).mapToObj(i -> {
            Xd xd = new Xd();
            xd.zboxsnrProperty().set(i + 1);
            xd.sapYmmmachProperty().bind(md.sapYmmmachProperty());
            xd.zrolmgeProperty().bind(md.zrolmgeProperty());
            return xd;
        }).collect(Collectors.toList())));
        if (md.getZdzflg()) {
            zsgwghtColumn.setEditable(false);
            md.getXds().forEach(xd -> {
                xd.zsnwghtProperty().bind(md.zcnwghtProperty());
                xd.zsgwghtProperty().bind(new ObjectBinding<BigDecimal>() {
                    {
                        bind(xd.zsnwghtProperty(), xd.zrolmgeProperty(), md.sapYmmzhixProperty(),
                                md.sapYmmtonggProperty());
                    }

                    @Override
                    protected BigDecimal computeValue() {
                        return xd.getZsnwght().add(tareF.apply(md, xd));
                    }
                });
            });
        } else {
            zsgwghtColumn.setEditable(true);
            md.getXds().forEach(xd -> {
                xd.zsnwghtProperty().bind(new ObjectBinding<BigDecimal>() {
                    {
                        bind(xd.zsgwghtProperty(), xd.zrolmgeProperty(), md.sapYmmzhixProperty(),
                                md.sapYmmtonggProperty());
                    }

                    @Override
                    protected BigDecimal computeValue() {
                        return xd.getZsgwght().add(tareF.apply(md, xd).negate());
                    }
                });
            });
        }
        md.zsgwghtProperty().bind(new ObjectBinding<BigDecimal>() {
            {
                md.getXds().forEach(xd -> bind(xd.zsgwghtProperty()));
            }

            @Override
            protected BigDecimal computeValue() {
                BigDecimal result = BigDecimal.ZERO;
                for (Xd xd : md.getXds()) {
                    result = result.add(xd.getZsgwght());
                }
                return result;
            }
        });
        md.zsnwghtProperty().bind(new ObjectBinding<BigDecimal>() {
            {
                md.getXds().forEach(xd -> bind(xd.zsnwghtProperty()));
            }

            @Override
            protected BigDecimal computeValue() {
                BigDecimal result = BigDecimal.ZERO;
                for (Xd xd : md.getXds()) {
                    result = result.add(xd.getZsnwght());
                }
                return result;
            }
        });
    } catch (AppException e) {
        Util.alertDialog(e);
    }
}

From source file:org.apache.hadoop.hbase.client.TestAsyncTable.java

@Test
public void testCheckAndDelete() throws InterruptedException, ExecutionException {
    AsyncTableBase table = getTable.get();
    int count = 10;
    CountDownLatch putLatch = new CountDownLatch(count + 1);
    table.put(new Put(row).addColumn(FAMILY, QUALIFIER, VALUE)).thenRun(() -> putLatch.countDown());
    IntStream.range(0, count)
            .forEach(i -> table.put(new Put(row).addColumn(FAMILY, concat(QUALIFIER, i), VALUE))
                    .thenRun(() -> putLatch.countDown()));
    putLatch.await();/*w ww. j  av a2  s.c om*/

    AtomicInteger successCount = new AtomicInteger(0);
    AtomicInteger successIndex = new AtomicInteger(-1);
    CountDownLatch deleteLatch = new CountDownLatch(count);
    IntStream.range(0, count).forEach(i -> table
            .checkAndDelete(row, FAMILY, QUALIFIER, VALUE,
                    new Delete(row).addColumn(FAMILY, QUALIFIER).addColumn(FAMILY, concat(QUALIFIER, i)))
            .thenAccept(x -> {
                if (x) {
                    successCount.incrementAndGet();
                    successIndex.set(i);
                }
                deleteLatch.countDown();
            }));
    deleteLatch.await();
    assertEquals(1, successCount.get());
    Result result = table.get(new Get(row)).get();
    IntStream.range(0, count).forEach(i -> {
        if (i == successIndex.get()) {
            assertFalse(result.containsColumn(FAMILY, concat(QUALIFIER, i)));
        } else {
            assertArrayEquals(VALUE, result.getValue(FAMILY, concat(QUALIFIER, i)));
        }
    });
}

From source file:org.kie.workbench.common.forms.migration.tool.pipelines.basic.AbstractFormDefinitionGeneratorTest.java

protected void verifyInvoiceForm(FormMigrationSummary summary) {
    Form originalForm = summary.getOriginalForm().get();

    Assertions.assertThat(originalForm.getFormFields()).isNotEmpty().hasSize(3);

    FormDefinition newForm = summary.getNewForm().get();

    Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(3);

    Assertions.assertThat(newForm.getModel()).isNotNull()
            .hasFieldOrPropertyWithValue("className", INVOICE_MODEL).isInstanceOf(DataObjectFormModel.class);

    IntStream indexStream = IntStream.range(0, newForm.getFields().size());

    LayoutTemplate formLayout = newForm.getLayoutTemplate();

    assertNotNull(formLayout);/*from   ww  w .j ava2s .  c  o  m*/

    Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(newForm.getFields().size());

    indexStream.forEach(index -> {
        FieldDefinition fieldDefinition = newForm.getFields().get(index);

        switch (index) {
        case 0:
            checkFieldDefinition(fieldDefinition, INVOICE_USER, "user (invoice)", "user",
                    SubFormFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
            break;
        case 1:
            checkFieldDefinition(fieldDefinition, INVOICE_LINES, "lines (invoice)", "lines",
                    MultipleSubFormFieldDefinition.class, newForm,
                    originalForm.getField(fieldDefinition.getName()));
            break;
        case 3:
            checkFieldDefinition(fieldDefinition, INVOICE_LINES, "lines (invoice)", "lines",
                    MultipleSubFormFieldDefinition.class, newForm,
                    originalForm.getField(fieldDefinition.getName()));
            break;
        }

        LayoutRow fieldRow = formLayout.getRows().get(index);

        assertNotNull(fieldRow);

        Assertions.assertThat(fieldRow.getLayoutColumns()).isNotEmpty().hasSize(1);

        LayoutColumn fieldColumn = fieldRow.getLayoutColumns().get(0);

        assertNotNull(fieldColumn);
        assertEquals("12", fieldColumn.getSpan());

        Assertions.assertThat(fieldColumn.getLayoutComponents()).isNotEmpty().hasSize(1);

        checkLayoutFormField(fieldColumn.getLayoutComponents().get(0), fieldDefinition, newForm);
    });
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionCollectionList.java

/**
 * test range/*from w w  w  .ja v a  2 s .co m*/
 */
@Test
public final void range() {
    final List<ITerm> l_return = new ArrayList<>();

    new CRange().execute(false, IContext.EMPTYPLAN,
            Stream.of(0, 5, 7, 9).map(CRawTerm::from).collect(Collectors.toList()), l_return);

    new CRange().execute(true, null, Stream.of(1, 7).map(CRawTerm::from).collect(Collectors.toList()),
            l_return);

    Assert.assertEquals(l_return.size(), 3);

    Assert.assertArrayEquals(l_return.get(0).<List<?>>raw().toArray(), IntStream.range(0, 5).boxed().toArray());
    Assert.assertArrayEquals(l_return.get(1).<List<?>>raw().toArray(), IntStream.range(7, 9).boxed().toArray());

    Assert.assertArrayEquals(l_return.get(2).<List<?>>raw().toArray(), IntStream.range(1, 7).boxed().toArray());
    Assert.assertEquals(l_return.get(2).<List<?>>raw().getClass(),
            Collections.synchronizedList(Collections.emptyList()).getClass());
}