Java Code Examples for java.util.Arrays.stream()

The following are Jave code examples for showing how to use stream() of the java.util.Arrays class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lttng-scope   File: StreamFlattenerTest.java   View Source Code Vote up 6 votes
/**
 * Test flattening a tree.
 *
 * Each node has a String value, and they will be organized as:
 *
 * <pre>
 *     A
 *    / \
 *   B   C
 *  /|   |\
 * D E   F G
 * </pre>
 *
 * In-order, depth-first visiting should give the following sequence:<br>
 * A -> B -> D -> E -> C -> F -> G
 */
@Test
public void testFlattenTree() {
    /* Prepare the tree */
    TreeNode nodeD = new TreeNode(new TreeNode[0], "D");
    TreeNode nodeE = new TreeNode(new TreeNode[0], "E");
    TreeNode nodeF = new TreeNode(new TreeNode[0], "F");
    TreeNode nodeG = new TreeNode(new TreeNode[0], "G");
    TreeNode nodeB = new TreeNode(new TreeNode[] {nodeD, nodeE}, "B");
    TreeNode nodeC = new TreeNode(new TreeNode[] {nodeF, nodeG}, "C");
    TreeNode nodeA = new TreeNode(new TreeNode[] {nodeB, nodeC}, "A");

    /* Run the test */
    StreamFlattener<TreeNode> sf = new StreamFlattener<>(node -> Arrays.stream(node.getChildren()));

    List<String> expected = Arrays.asList("A", "B", "D", "E", "C", "F", "G");
    List<String> results = sf.flatten(nodeA).map(TreeNode::getValue).collect(Collectors.toList());

    assertEquals(expected, results);
}
 
Example 2
Project: Solar   File: QuadBuilder.java   View Source Code Vote up 6 votes
public QuadBuilder mirror() {
	if(facingMap.containsKey(last)) {
		Stream<Vector3> stream = Arrays.stream(facingMap.get(last).getVectors());
		switch(last) {
			case DOWN:
			case UP:
				stream.forEach(vec -> {
					vec.subtract(0.5D).rotate(EnumFacing.Axis.Y, 180).add(0.5D);
				});
				break;
			case NORTH:
			case SOUTH:
				stream.forEach(vec -> {
					vec.subtract(0.5D).rotate(EnumFacing.Axis.X, 180).add(0.5D);
				});
				break;
			case EAST:
			case WEST:
				stream.forEach(vec -> {
					vec.subtract(0.5D).rotate(EnumFacing.Axis.Z, 180).add(0.5D);
				});
				break;
		}
	}
	return this;
}
 
Example 3
Project: imagetozxspec   File: WorkManager.java   View Source Code Vote up 6 votes
/**
 * Draws a set of dithers, derived from the provided image, onto the popup
 * preview frame
 *
 * @param image   the image to apply the dithers to
 * @param dithers the dither strategies to apply
 * @throws InterruptedException if the processing is interrupted
 */
private <T extends DitherStrategy> void generatePopupPreviewDithers(Image image, @SuppressWarnings("unchecked") T... dithers) throws InterruptedException {
    Stream<T> stream = Arrays.stream(dithers);
    Runnable runnable = () -> {
        stream.forEach(dither -> {
            WorkContainer workContainer = workDispatcher.submitPopupPreview(image, dither);
            Optional<ResultImage> resultImage = ResultImage.getFinalImage(workContainer.getResultImage());
            if (!resultImage.isPresent()) {
                log.error("Unable to get final image for preview");
                return;
            }
            ImageHelper.copyImage(resultImage.get().getImage(), PopupPreviewFrame.getPreviewImage(), PopupPreviewFrame.getPoint());
            PopupPreviewFrame.repaintImage();
        });
    };
    exec.submit(runnable);
}
 
Example 4
Project: java-logging   File: ReformLoggingLayout.java   View Source Code Vote up 6 votes
private void appendStackTrace(StringBuilder log, ThrowableProxy proxy) {
    if (proxy != null) {
        Stream<StackTraceElementProxy> trace = Arrays.stream(proxy.getStackTraceElementProxyArray());

        trace.forEach(step -> {
            String string = step.toString();

            log.append(CoreConstants.TAB).append(string);

            ThrowableProxyUtil.subjoinPackagingData(log, step);

            log.append(CoreConstants.LINE_SEPARATOR);
        });

        trace.close();
    }
}
 
Example 5
Project: incubator-netbeans   File: JShellTool.java   View Source Code Vote up 5 votes
private String format(EditorSetting ed) {
    if (ed == BUILT_IN_EDITOR) {
        return "-default";
    } else {
        Stream<String> elems = Arrays.stream(ed.cmd);
        if (ed.wait) {
            elems = Stream.concat(Stream.of("-wait"), elems);
        }
        return elems.collect(joining(" "));
    }
}
 
Example 6
Project: Spring-5.0-Cookbook   File: EmployeeStreamService.java   View Source Code Vote up 5 votes
public void getArrayData(){
	int[] ages = {24, 33, 21, 22, 45};
	IntStream ageStream = Arrays.stream(ages);
	
	double[] salaries = {33000.50, 23100.20, 45000.50};
	DoubleStream salStream = Arrays.stream(salaries);
	
	long[] longDates = {23434432342L, 11123343435L, 34343342343L};
	LongStream dateStream = Arrays.stream(longDates);
}
 
Example 7
Project: openjdk-jdk10   File: JShellTool.java   View Source Code Vote up 5 votes
private String format(EditorSetting ed) {
    if (ed == BUILT_IN_EDITOR) {
        return "-default";
    } else {
        Stream<String> elems = Arrays.stream(ed.cmd);
        if (ed.wait) {
            elems = Stream.concat(Stream.of("-wait"), elems);
        }
        return elems.collect(joining(" "));
    }
}
 
Example 8
Project: libtrails   File: CircumferenceSupplier.java   View Source Code Vote up 5 votes
@Override
public Stream<SuppliedParticle> supply(int tick) {
    if (tick % appearingInterval == 0) {
        return Arrays.stream(particles);
    } else {
        return Stream.of();
    }
}
 
Example 9
Project: FreeCol   File: CollectionUtils.java   View Source Code Vote up 5 votes
/**
 * Create a stream of files from a directory.
 *
 * @param dir The {@code File} that hopefully is a directory.
 * @return A stream of {@code File}s.
 */
public static Stream<File> fileStream(File dir) {
    File[] files;
    return (dir == null || !dir.isDirectory()
        || (files = dir.listFiles()) == null)
        ? Stream.<File>empty()
        : Arrays.stream(files);
}
 
Example 10
Project: libtrails   File: BitmapSupplier.java   View Source Code Vote up 5 votes
@Override
public Stream<SuppliedParticle> supply(int tick) {
    if (tick % appearingInterval == 0) {
        return Arrays.stream(particles, 0, allocatedPixels);
    } else {
        return Stream.of();
    }
}
 
Example 11
Project: libtrails   File: StarSupplier.java   View Source Code Vote up 5 votes
@Override
public Stream<SuppliedParticle> supply(int tick) {
    if (tick % appearingInterval == 0) {
        return Arrays.stream(particles);
    } else {
        return Stream.of();
    }
}
 
Example 12
Project: skript-mirror   File: Util.java   View Source Code Vote up 4 votes
public static Stream<Constructor> constructor(Class<?> cls) {
  return Arrays.stream(cls.getDeclaredConstructors());
}
 
Example 13
Project: spring2ts   File: AnnotationUtils.java   View Source Code Vote up 4 votes
private static List<Method> getAnnotationAttributes(Class<? extends Annotation> type) {
    Stream<Method> methods = Arrays.stream(type.getDeclaredMethods());
    List<Method> results = methods.filter(AnnotationUtils::isAttributeMethod).collect(Collectors.toList());
    results.forEach(r -> r.setAccessible(true));
    return results;
}
 
Example 14
Project: Hydrograph   File: RadioButtonsWidget.java   View Source Code Vote up 4 votes
@Override
public void attachToPropertySubGroup(AbstractELTContainerWidget container) {
	ELTDefaultSubgroupComposite defaultSubgroupComposite = new ELTDefaultSubgroupComposite(
			container.getContainerControl());
	buttonText = radioButtonConfig.getWidgetDisplayNames();
	buttons = new Button[buttonText.length];
	defaultSubgroupComposite.createContainerWidget();
	defaultSubgroupComposite.numberOfBasicWidgets(buttonText.length + 1);

	AbstractELTWidget defaultLabel = new ELTDefaultLable(radioButtonConfig.getPropertyName());
	defaultSubgroupComposite.attachWidget(defaultLabel);

	setPropertyHelpWidget((Control) defaultLabel.getSWTWidgetControl());
	
	SelectionListener selectionListener = new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent event) {
			Button button = ((Button) event.widget);

			matchValue.setMatchValue(button.getText());
			matchValue.setRadioButtonSelected(true);
			propertyDialogButtonBar.enableApplyButton(true);
		}
	};

	
	for (int i = 0; i < buttonText.length; i++) {
		ELTRadioButton eltRadioButton = new ELTRadioButton(buttonText[i]);
		defaultSubgroupComposite.attachWidget(eltRadioButton);
		buttons[i] = ((Button) eltRadioButton.getSWTWidgetControl());
		((Button) eltRadioButton.getSWTWidgetControl()).addSelectionListener(selectionListener);
	}
	buttons[0].setSelection(true);
	
	if(!radioButtonConfig.getRadioButtonListners().isEmpty()){
		Stream<Button> stream = Arrays.stream(buttons);
		stream.forEach(button -> {
		Listners radioListners = radioButtonConfig.getRadioButtonListners().get(0);
		IELTListener listener = radioListners.getListener();
		Listener listnr = listener.getListener(propertyDialogButtonBar, null, button);
		button.addListener(SWT.Selection, listnr);});
	}
	 populateWidget();
}
 
Example 15
Project: guava-mock   File: ImmutableIntArray.java   View Source Code Vote up 4 votes
/** Returns a stream over the values in this array, in order. */
public IntStream stream() {
  return Arrays.stream(array, start, end);
}
 
Example 16
Project: gw4e.project   File: ModelSearchPage.java   View Source Code Vote up 4 votes
private void packCriteriaTable() {
	Stream<TableColumn> stream = Arrays.stream(tableCriteria.getColumns());
	stream.forEach(tc -> tc.pack());
}
 
Example 17
Project: OpenJSharp   File: IntStream.java   View Source Code Vote up 2 votes
/**
 * Returns a sequential ordered stream whose elements are the specified values.
 *
 * @param values the elements of the new stream
 * @return the new stream
 */
public static IntStream of(int... values) {
    return Arrays.stream(values);
}
 
Example 18
Project: openjdk-jdk10   File: IntStream.java   View Source Code Vote up 2 votes
/**
 * Returns a sequential ordered stream whose elements are the specified values.
 *
 * @param values the elements of the new stream
 * @return the new stream
 */
public static IntStream of(int... values) {
    return Arrays.stream(values);
}
 
Example 19
Project: OpenJSharp   File: DoubleStream.java   View Source Code Vote up 2 votes
/**
 * Returns a sequential ordered stream whose elements are the specified values.
 *
 * @param values the elements of the new stream
 * @return the new stream
 */
public static DoubleStream of(double... values) {
    return Arrays.stream(values);
}
 
Example 20
Project: openjdk-jdk10   File: DoubleStream.java   View Source Code Vote up 2 votes
/**
 * Returns a sequential ordered stream whose elements are the specified values.
 *
 * @param values the elements of the new stream
 * @return the new stream
 */
public static DoubleStream of(double... values) {
    return Arrays.stream(values);
}