下面列出了java.util.stream.DoubleStream#of ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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());
}
public static Object arrayToStream(final Object array) {
if (array instanceof int[]) {
return IntStream.of((int[])array);
} else if (array instanceof long[]) {
return LongStream.of((long[])array);
} else if (array instanceof double[]) {
return DoubleStream.of((double[])array);
} else if (array instanceof Object[]) {
return Stream.of((Object[])array);
} else {
throw new IllegalArgumentException();
}
}
/**
* If a value is present in the {@link OptionalDouble}, returns a {@link DoubleStream}
* with the value as its source or else an empty stream.
*
* @since 3.0.0
*/
public static DoubleStream stream(final OptionalDouble self) {
if (!self.isPresent()) {
return DoubleStream.empty();
}
return DoubleStream.of(self.getAsDouble());
}
public DoubleStream getTextureLocation(int iPoint){
if(width==0 || height==0){
return DoubleStream.of(0f,0f);
}
int y = iPoint/width;
int x = iPoint-width*y;
// add 0.5 to interpolate colors from the middle of the pixel
return DoubleStream.of((((float)x+0.5f)/((float)width)),(((float)y+0.5f)/((float)height)));
}
static DoubleStream doubleProvider() {
return DoubleStream.of(2d, 3d);
}
static DoubleStream doubleProvider() {
return DoubleStream.of(2d, 3d);
}
@Override
public DoubleIterator getUidxVs(int uidx) {
return new StreamDoubleIterator(DoubleStream.of(1.0, 2.0, 3.0, 4.0, 5.0, 6.0));
}
@Override
public DoubleIterator getIidxVs(int iidx) {
return new StreamDoubleIterator(DoubleStream.of(6.0, 5.0, 4.0, 3.0, 2.0));
}
@Test
public void ofAllStream() {
DoubleStream stream = DoubleStream.of(1, 2, 9, 0);
DoubleColumn column = DoubleColumn.ofAll(ID, stream);
assertMultipleValues(column);
}
@Override
@SuppressWarnings("unchecked")
public DoubleStream convertFrom(R in) {
double[] value = DoubleArraySimpledCoder.instance.convertFrom(in);
return value == null ? null : DoubleStream.of(value);
}
public DoubleStream toDoubleStream() {
return DoubleStream.of(var);
}
@Override
public DoubleStream values() {
return DoubleStream.of(values);
}
public static DoubleStream okDoubles() {
return DoubleStream.of(-0.00001, -1.34, -83.12, 0d, 0.00001, 1.34, 83.12);
}
public static DoubleStream toDoubleStream(double[] numbers)
{
return DoubleStream.of(numbers);
}
/**
* If a value is present, returns a sequential {@link DoubleStream}
* containing only that value, otherwise returns an empty
* {@code DoubleStream}.
*
* @apiNote
* This method can be used to transform a {@code Stream} of optional doubles
* to a {@code DoubleStream} of present doubles:
* <pre>{@code
* Stream<OptionalDouble> os = ..
* DoubleStream s = os.flatMapToDouble(OptionalDouble::stream)
* }</pre>
*
* @return the optional value as a {@code DoubleStream}
* @since 9
*/
public DoubleStream stream() {
if (isPresent) {
return DoubleStream.of(value);
} else {
return DoubleStream.empty();
}
}
/**
* If a value is present, returns a sequential {@link DoubleStream}
* containing only that value, otherwise returns an empty
* {@code DoubleStream}.
*
* @apiNote
* This method can be used to transform a {@code Stream} of optional doubles
* to a {@code DoubleStream} of present doubles:
* <pre>{@code
* Stream<OptionalDouble> os = ..
* DoubleStream s = os.flatMapToDouble(OptionalDouble::stream)
* }</pre>
*
* @return the optional value as a {@code DoubleStream}
* @since 9
*/
public DoubleStream stream() {
if (isPresent) {
return DoubleStream.of(value);
} else {
return DoubleStream.empty();
}
}
@Test
public void join_doublestream_stream() {
DoubleStream doubleStream1 = DoubleStream.of(9, 10);
DoubleStream doubleStream2 = DoubleStream.of(11, 12);
DoubleStream.concat(doubleStream1, doubleStream2).forEach(
e -> System.out.println(e));
}
/**
* Returns a stream over the array values.
*
* @return a stream over the values in the array
*/
public DoubleStream stream() {
return DoubleStream.of(array);
}
/**
* Return a DoubleStream of this time discretization.
*
* @return The time discretization as <code>DoubleStream</code>
*/
default DoubleStream doubleStream() {
return DoubleStream.of(getAsDoubleArray());
}
public DoubleStream getCoordinates(float factor) { return DoubleStream.of(factor*x,factor*y,factor*z); }