use of java.util.stream.IntStream in project drools by kiegroup.
the class SubstringFunction method invoke.
public FEELFnResult<String> invoke(@ParameterName("string") String string, @ParameterName("start position") Number start, @ParameterName("length") Number length) {
if (string == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "string", "cannot be null"));
}
if (start == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "start position", "cannot be null"));
}
if (length != null && length.intValue() <= 0) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "length", "must be a positive number when specified"));
}
if (start.intValue() == 0) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "start position", "cannot be zero"));
}
int stringLength = string.codePointCount(0, string.length());
if (Math.abs(start.intValue()) > stringLength) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "parameter 'start position' inconsistent with the actual length of the parameter 'string'"));
}
int skip = start.intValue() > 0 ? start.intValue() - 1 : stringLength + start.intValue();
IntStream stream = string.codePoints().skip(skip);
if (length != null) {
stream = stream.limit(length.longValue());
}
StringBuilder result = stream.mapToObj(Character::toChars).collect(StringBuilder::new, StringBuilder::append, StringBuilder::append);
return FEELFnResult.ofResult(result.toString());
}
use of java.util.stream.IntStream in project kie-wb-common by kiegroup.
the class FormDefinitionGeneratorForBPMNWithComplexVariableTest method checkInvoiceFormDefinition.
protected void checkInvoiceFormDefinition(FormDefinition invoiceForm, Form originalForm) {
assertNotNull(invoiceForm);
Assertions.assertThat(invoiceForm.getModel()).isNotNull().isInstanceOf(DataObjectFormModel.class).hasFieldOrPropertyWithValue("className", INVOICE_MODEL);
Assertions.assertThat(invoiceForm.getFields()).isNotEmpty().hasSize(4);
IntStream indexStream = IntStream.range(0, invoiceForm.getFields().size());
LayoutTemplate formLayout = invoiceForm.getLayoutTemplate();
assertNotNull(formLayout);
Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(4);
indexStream.forEach(index -> {
FieldDefinition fieldDefinition = invoiceForm.getFields().get(index);
switch(index) {
case 0:
checkFieldDefinition(fieldDefinition, "invoice_user", "User Data:", "user", SubFormFieldDefinition.class, invoiceForm, originalForm.getField(fieldDefinition.getName()));
break;
case 1:
checkFieldDefinition(fieldDefinition, "lines", "Invoice Lines", "lines", MultipleSubFormFieldDefinition.class, invoiceForm, originalForm.getField(fieldDefinition.getName()));
break;
case 2:
checkFieldDefinition(fieldDefinition, "invoice_total", "Invoice Total:", "total", DecimalBoxFieldDefinition.class, invoiceForm, originalForm.getField(fieldDefinition.getName()));
break;
case 3:
checkFieldDefinition(fieldDefinition, "invoice_list", "List of Values:", "list", IntegerMultipleInputFieldDefinition.class, invoiceForm, 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, invoiceForm);
});
}
use of java.util.stream.IntStream in project kie-wb-common by kiegroup.
the class AbstractFormDefinitionGeneratorTest method verifyLineForm.
protected void verifyLineForm(FormMigrationSummary summary) {
Form originalForm = summary.getOriginalForm().get();
Assertions.assertThat(originalForm.getFormFields()).isNotEmpty().hasSize(4);
FormDefinition newForm = summary.getNewForm().get();
Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(4);
Assertions.assertThat(newForm.getModel()).isNotNull().hasFieldOrPropertyWithValue("className", LINE_MODEL).isInstanceOf(DataObjectFormModel.class);
IntStream indexStream = IntStream.range(0, newForm.getFields().size());
LayoutTemplate formLayout = newForm.getLayoutTemplate();
assertNotNull(formLayout);
Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(1);
LayoutRow fieldRow = formLayout.getRows().get(0);
indexStream.forEach(index -> {
FieldDefinition fieldDefinition = newForm.getFields().get(index);
switch(index) {
case 0:
checkFieldDefinition(fieldDefinition, LINE_PRODUCT, "product", "product", TextBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 1:
checkFieldDefinition(fieldDefinition, LINE_PRICE, "price", "price", DecimalBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 2:
checkFieldDefinition(fieldDefinition, LINE_QUANTITY, "quantity", "quantity", IntegerBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 3:
checkFieldDefinition(fieldDefinition, LINE_TOTAL, "total", "total", DecimalBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
}
assertNotNull(fieldRow);
Assertions.assertThat(fieldRow.getLayoutColumns()).isNotEmpty().hasSize(4);
LayoutColumn fieldColumn = fieldRow.getLayoutColumns().get(index);
assertNotNull(fieldColumn);
assertEquals("3", fieldColumn.getSpan());
Assertions.assertThat(fieldColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
checkLayoutFormField(fieldColumn.getLayoutComponents().get(0), fieldDefinition, newForm);
});
}
use of java.util.stream.IntStream in project guava by google.
the class Streams method concat.
/**
* Returns an {@link IntStream} containing the elements of the first stream, followed by the
* elements of the second stream, and so on.
*
* <p>This is equivalent to {@code Stream.of(streams).flatMapToInt(stream -> stream)}, but the
* returned stream may perform better.
*
* @see IntStream#concat(IntStream, IntStream)
*/
public static IntStream concat(IntStream... streams) {
boolean isParallel = false;
int characteristics = Spliterator.ORDERED | Spliterator.SIZED | Spliterator.NONNULL;
long estimatedSize = 0L;
ImmutableList.Builder<Spliterator.OfInt> splitrsBuilder = new ImmutableList.Builder<>(streams.length);
for (IntStream stream : streams) {
isParallel |= stream.isParallel();
Spliterator.OfInt splitr = stream.spliterator();
splitrsBuilder.add(splitr);
characteristics &= splitr.characteristics();
estimatedSize = LongMath.saturatedAdd(estimatedSize, splitr.estimateSize());
}
return StreamSupport.intStream(CollectSpliterators.flatMapToInt(splitrsBuilder.build().spliterator(), splitr -> splitr, characteristics, estimatedSize), isParallel).onClose(() -> closeAll(streams));
}
use of java.util.stream.IntStream in project chuidiang-ejemplos by chuidiang.
the class Java8RandomExample method main.
public static void main(String[] args) {
Random random = new Random();
IntStream intStream = random.ints(10, 1, 7);
Iterator iterator = intStream.iterator();
while (iterator.hasNext()) {
System.out.println("Random Number " + iterator.next());
}
intStream = random.ints(10, 1, 7);
intStream.forEach(value -> System.out.println("Random Number " + value));
}
Aggregations