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

The following examples show how to use java.util.Arrays#stream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModuleClassPaths.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NonNull
private static Stream<File> findModules(@NonNull final File modulesFolder) {
    //No project's dist folder do File.list
    File[] modules = modulesFolder.listFiles((File f) -> {
        try {
            if (f.getName().startsWith(".")) {
                return false;
            }
            return f.isFile() ?
                    FileUtil.isArchiveFile(BaseUtilities.toURI(f).toURL()) :
                    new File(f, MODULE_INFO_CLASS).exists();
        } catch (MalformedURLException e) {
            Exceptions.printStackTrace(e);
            return false;
        }
    });
    return modules == null ?
       Stream.empty():
       Arrays.stream(modules);
}
 
Example 2
Source File: DoubleSupplier.java    From latexdraw with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<PotentialAssignment> getValueSources(final ParameterSignature sig) {
	final DoubleData doubledata = sig.getAnnotation(DoubleData.class);
	DoubleStream stream = Arrays.stream(doubledata.vals());

	if(doubledata.angle()) {
		stream = DoubleStream.of(0d, Math.PI / 2d, Math.PI, 3d * Math.PI / 2d, 2d * Math.PI, -Math.PI / 2d, -Math.PI,
			-3d * Math.PI / 2d, -2d * Math.PI, 1.234, -1.234, 3d * Math.PI, -3d * Math.PI);
	}

	if(doubledata.bads()) {
		stream = DoubleStream.concat(stream, DoubleStream.of(Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY));
	}

	return stream.mapToObj(i -> PotentialAssignment.forValue("", i)).collect(Collectors.toList());
}
 
Example 3
Source File: FoxEatsDemo.java    From htm.java-examples with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a {@link Stream} constructed from the specified path
 *
 * @param path
 * @return
 */
public Stream<String> getFileStream(String path) {
    try {
        return Files.lines(new File(path).toPath());
    }catch(IOException e) {
        LOGGER.error("Failed to load indicated file: " + path);
        try {
            InputStream is = getClass().getResourceAsStream("/foxeat.csv");
            return new BufferedReader(new InputStreamReader(is)).lines();
        }catch(Exception ex) {
            LOGGER.error("Failed secondary attempt from jar.");
        }
        return Arrays.stream(new String[] { });
    }
}
 
Example 4
Source File: NullSafeCollectionStreamsUsingNullDereferenceCheckUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenCollectionHasElements_thenExpectAStreamOfExactlyTheSameElements() {
    Collection<String> collection = Arrays.asList("a", "b", "c");
    Stream<String> expResult = Arrays.stream(new String[] { "a", "b", "c" });
    Stream<String> result = instance.collectionAsStream(collection);
    assertStreamEquals(expResult, result);
}
 
Example 5
Source File: StringSupplier.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<PotentialAssignment> getValueSources(final ParameterSignature sig) {
	final StringData data = sig.getAnnotation(StringData.class);
	Stream<String> stream = Arrays.stream(data.vals());

	if(data.withNull()) {
		stream = Stream.concat(stream, Stream.of((String) null));
	}

	return stream.map(i -> PotentialAssignment.forValue("", i)).collect(Collectors.toList());
}
 
Example 6
Source File: CmFacade.java    From osgi.enroute.examples with Apache License 2.0 5 votes vote down vote up
private Stream<Configuration> getConfigurations0(String filter)
		throws IOException, InvalidSyntaxException {

	Configuration[] configurations = cm.listConfigurations(filter);
	if (configurations == null)
		configurations = EMPTY;

	return Arrays.stream(configurations);
}
 
Example 7
Source File: Methods.java    From da-streamingledger with Apache License 2.0 5 votes vote down vote up
private static Stream<Method> definedMethods(Class<?> javaClass) {
    if (javaClass == null || javaClass == Object.class) {
        return Stream.empty();
    }
    Stream<Method> selfMethods = Arrays.stream(javaClass.getDeclaredMethods());
    Stream<Method> superMethods = definedMethods(javaClass.getSuperclass());

    return Stream.concat(selfMethods, superMethods);
}
 
Example 8
Source File: NullSafeCollectionStreamsUsingNullDereferenceCheckUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenCollectionHasElements_thenExpectAStreamOfExactlyTheSameElements() {

    Collection<String> collection = Arrays.asList("a", "b", "c");
    Stream<String> expResult = Arrays.stream(new String[] { "a", "b", "c" });
    Stream<String> result = instance.collectionAsStream(collection);
    assertStreamEquals(expResult, result);
}
 
Example 9
Source File: RandomVariableFromFloatArray.java    From finmath-lib with Apache License 2.0 5 votes vote down vote up
@Override
public DoubleStream getRealizationsStream() {
	if(isDeterministic()) {
		return DoubleStream.generate(new DoubleSupplier() {
			@Override
			public double getAsDouble() {
				return valueIfNonStochastic;
			}
		});
	} else {
		return Arrays.stream(getDoubleArray(realizations));
	}
}
 
Example 10
Source File: UtilKt.java    From consulo with Apache License 2.0 4 votes vote down vote up
@SafeVarargs
@Nonnull
public static <T> Stream<T> stream(T... args) {
  return args == null ? Stream.<T>empty() : Arrays.stream(args);
}
 
Example 11
Source File: DataOnMemoryFromFile.java    From toolbox with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Stream<DataInstance> stream() {
    return Arrays.stream(this.dataInstances);
}
 
Example 12
Source File: WebTauCore.java    From webtau with Apache License 2.0 4 votes vote down vote up
public static TableData table(Object... columnNames) {
    return new TableData(Arrays.stream(columnNames));
}
 
Example 13
Source File: DoubleStream.java    From jdk1.8-source-analysis with Apache License 2.0 2 votes vote down vote up
/**
 * 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 14
Source File: SDR.java    From htm.java with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Converts a vector of {@link Cell} indexes to {@link Column} indexes.
 * 
 * @param cells             the indexes of the cells to convert
 * @param cellsPerColumn    the defined number of cells per column  
 *                          false if not.   
 * @return  the column indexes of the specified cells.
 */
public static int[] asColumnIndices(int[] cells, int cellsPerColumn) {
    IntStream op = Arrays.stream(cells);
    return op.map(cell -> cell / cellsPerColumn).distinct().toArray();
}
 
Example 15
Source File: DoubleStream.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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 16
Source File: LongStream.java    From JDKSourceCode1.8 with MIT License 2 votes vote down vote up
/**
 * 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 LongStream of(long... values) {
    return Arrays.stream(values);
}
 
Example 17
Source File: IntStream.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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
Source File: IntStream.java    From jdk1.8-source-analysis with Apache License 2.0 2 votes vote down vote up
/**
 * 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
Source File: DoubleStream.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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
Source File: PluginDefaultGroovyMethods.java    From groovy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a sequential {@link Stream} with the specified array as its
 * source.
 *
 * @param <T> The type of the array elements
 * @param self The array, assumed to be unmodified during use
 * @return a {@code Stream} for the array
 *
 * @since 2.5.0
 */
public static <T> Stream<T> stream(final T[] self) {
    return Arrays.stream(self);
}