java.util.function.DoubleFunction#apply ( )源码实例Demo

下面列出了java.util.function.DoubleFunction#apply ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk1.8-source-analysis   文件: DoublePipeline.java
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
源代码2 项目: JDKSourceCode1.8   文件: DoublePipeline.java
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
源代码3 项目: Algorithms   文件: BinarySearch.java
public static double binarySearch(
    double lo, double hi, double target, DoubleFunction<Double> function) {

  if (hi <= lo) throw new IllegalArgumentException("hi should be greater than lo");

  double mid;
  do {

    // Find the middle point
    mid = (hi + lo) / 2.0;

    // Compute the value of our function for the middle point
    // Note that f can be any function not just the square root function
    double value = function.apply(mid);

    if (value > target) {
      hi = mid;
    } else {
      lo = mid;
    }

  } while ((hi - lo) > EPS);

  return mid;
}
 
源代码4 项目: desugar_jdk_libs   文件: DoublePipeline.java
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: DoublePipeline.java
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
源代码6 项目: openjdk-jdk9   文件: DoublePipeline.java
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
源代码7 项目: jdk8u-jdk   文件: DoublePipeline.java
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
源代码8 项目: Flink-CEPplus   文件: OrcBatchReader.java
private static <T> void readDoubleColumn(Object[] vals, int fieldIdx, DoubleColumnVector vector,
											int childCount, DoubleFunction<T> reader) {

	if (vector.isRepeating) { // fill complete column with first value
		if (vector.isNull[0]) {
			// fill vals with null values
			fillColumnWithRepeatingValue(vals, fieldIdx, null, childCount);
		} else {
			// read repeating non-null value by forwarding call
			readNonNullDoubleColumn(vals, fieldIdx, vector, childCount, reader);
		}
	} else {
		boolean[] isNullVector = vector.isNull;
		if (fieldIdx == -1) { // set as an object
			for (int i = 0; i < childCount; i++) {
				if (isNullVector[i]) {
					vals[i] = null;
				} else {
					vals[i] = reader.apply(vector.vector[i]);
				}
			}
		} else { // set as a field of Row
			Row[] rows = (Row[]) vals;
			for (int i = 0; i < childCount; i++) {
				if (isNullVector[i]) {
					rows[i].setField(fieldIdx, null);
				} else {
					rows[i].setField(fieldIdx, reader.apply(vector.vector[i]));
				}
			}
		}
	}
}
 
源代码9 项目: mzmine3   文件: HistogramChartFactory.java
private static void addDPToSeries(XYSeries series, int[] bins, int i, double binwidth, double min,
    double max, DoubleFunction<Double> function) {
  // adds a data point to the series
  double x = min + (binwidth / 2.0) + i * binwidth;
  if (function != null)
    x = function.apply(x);
  series.add(x, bins[i]);
}
 
源代码10 项目: mzmine3   文件: HistogramChartFactory.java
private static void addDPToList(List<DataPoint> list, int[] bins, int i, double binwidth,
    double min, double max, DoubleFunction<Double> function) {
  // adds a data point to the series
  double x = min + (binwidth / 2.0) + i * binwidth;
  if (function != null)
    x = function.apply(x);
  list.add(new SimpleDataPoint(x, bins[i]));
}
 
源代码11 项目: morpheus-core   文件: Printer.java
/**
 * Creates an DOUBLE Printer that wraps the function provided
 * @param function  the function to wrap
 * @return          the newly created function Printer
 */
public static Printer<Double> forDouble(DoubleFunction<String> function) {
    return new Printer<Double>(FunctionStyle.DOUBLE, DEFAULT_NULL) {
        @Override
        public final String apply(double input) {
            return function.apply(input);
        }
    };
}
 
源代码12 项目: flink   文件: OrcBatchReader.java
private static <T> void readDoubleColumn(Object[] vals, int fieldIdx, DoubleColumnVector vector,
											int childCount, DoubleFunction<T> reader) {

	if (vector.isRepeating) { // fill complete column with first value
		if (vector.isNull[0]) {
			// fill vals with null values
			fillColumnWithRepeatingValue(vals, fieldIdx, null, childCount);
		} else {
			// read repeating non-null value by forwarding call
			readNonNullDoubleColumn(vals, fieldIdx, vector, childCount, reader);
		}
	} else {
		boolean[] isNullVector = vector.isNull;
		if (fieldIdx == -1) { // set as an object
			for (int i = 0; i < childCount; i++) {
				if (isNullVector[i]) {
					vals[i] = null;
				} else {
					vals[i] = reader.apply(vector.vector[i]);
				}
			}
		} else { // set as a field of Row
			Row[] rows = (Row[]) vals;
			for (int i = 0; i < childCount; i++) {
				if (isNullVector[i]) {
					rows[i].setField(fieldIdx, null);
				} else {
					rows[i].setField(fieldIdx, reader.apply(vector.vector[i]));
				}
			}
		}
	}
}
 
源代码13 项目: morpheus-core   文件: Function2.java
/**
 * Creates an LONG function that wraps to function provided
 * @param function  the function to wrap
 * @param <O>       the output type
 * @return          the newly created function wrapper
 */
public static <O> Function2<Double,O> fromDouble(DoubleFunction<O> function) {
    return new Function2<Double,O>(FunctionStyle.DOUBLE) {
        @Override
        public final O apply(double input) {
            return function.apply(input);
        }
    };
}
 
源代码14 项目: commons-geometry   文件: Rotation2DTest.java
/** Check a rotation transform for consistency against a variety of points and rotation angles.
 * @param factory function used to create a rotation transform from an input angle
 * @param transformFn function that accepts the transform and a point and returns
 *      the transformed point
 */
private static <T extends EuclideanTransform<Vector2D>> void checkRotate(
        DoubleFunction<T> factory, BiFunction<T, Vector2D, Vector2D> transformFn) {

    // check zero
    T transform = factory.apply(0);
    EuclideanTestUtils.assertCoordinatesEqual(Vector2D.ZERO, transformFn.apply(transform, Vector2D.ZERO), TEST_EPS);

    // check a variety of non-zero points
    EuclideanTestUtils.permuteSkipZero(-2, -2, 1, (x, y) -> {
        checkRotatePoint(Vector2D.of(x, y), factory, transformFn);
    });
}
 
源代码15 项目: commons-geometry   文件: Rotation2DTest.java
/** Check a rotation transform for consistency when transforming a single point against a
 * variety of rotation angles.
 * @param pt point to transform
 * @param factory function used to create a rotation transform from an input angle
 * @param transformFn function that accepts the transform and a point and returns
 *      the transformed point
 */
private static <T extends EuclideanTransform<Vector2D>> void checkRotatePoint(
        Vector2D pt, DoubleFunction<T> factory, BiFunction<T, Vector2D, Vector2D> transformFn) {

    // arrange
    double limit = 4 * Math.PI;
    double inc = 0.25;

    Line line = Lines.fromPointAndDirection(Vector2D.ZERO, pt, TEST_PRECISION);

    T transform;
    Vector2D resultPt;
    Line resultLine;
    for (double angle = -limit; angle < limit; angle += inc) {
        transform = factory.apply(angle);

        // act
        resultPt = transformFn.apply(transform, pt);

        // assert
        // check that the norm is unchanged
        Assert.assertEquals(pt.norm(), resultPt.norm(), TEST_EPS);

        resultLine = Lines.fromPointAndDirection(Vector2D.ZERO, resultPt, TEST_PRECISION);
        double lineAngle = line.angle(resultLine);

        // check that the angle is what we expect
        Assert.assertEquals(PlaneAngleRadians.normalizeBetweenMinusPiAndPi(angle), lineAngle, TEST_EPS);
    }
}
 
源代码16 项目: AILibs   文件: LinearlyScaledFunction.java
public LinearlyScaledFunction(final DoubleFunction<Double> baseFunction, final double x1, final double y1, final double x2, final double y2) {
	super();
	this.baseFunction = baseFunction;
	this.mapping = new AffineFunction(baseFunction.apply(x1), y1, baseFunction.apply(x2), y2);
}
 
源代码17 项目: dragonwell8_jdk   文件: DoublePipeline.java
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                // true if cancellationRequested() has been called
                boolean cancellationRequestedCalled;

                // cache the consumer to avoid creation on every accepted element
                DoubleConsumer downstreamAsDouble = downstream::accept;

                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream result = mapper.apply(t)) {
                        if (result != null) {
                            if (!cancellationRequestedCalled) {
                                result.sequential().forEach(downstreamAsDouble);
                            }
                            else {
                                Spliterator.OfDouble s = result.sequential().spliterator();
                                do { } while (!downstream.cancellationRequested() && s.tryAdvance(downstreamAsDouble));
                            }
                        }
                    }
                }

                @Override
                public boolean cancellationRequested() {
                    // If this method is called then an operation within the stream
                    // pipeline is short-circuiting (see AbstractPipeline.copyInto).
                    // Note that we cannot differentiate between an upstream or
                    // downstream operation
                    cancellationRequestedCalled = true;
                    return downstream.cancellationRequested();
                }
            };
        }
    };
}
 
源代码18 项目: TencentKona-8   文件: DoublePipeline.java
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                // true if cancellationRequested() has been called
                boolean cancellationRequestedCalled;

                // cache the consumer to avoid creation on every accepted element
                DoubleConsumer downstreamAsDouble = downstream::accept;

                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream result = mapper.apply(t)) {
                        if (result != null) {
                            if (!cancellationRequestedCalled) {
                                result.sequential().forEach(downstreamAsDouble);
                            }
                            else {
                                Spliterator.OfDouble s = result.sequential().spliterator();
                                do { } while (!downstream.cancellationRequested() && s.tryAdvance(downstreamAsDouble));
                            }
                        }
                    }
                }

                @Override
                public boolean cancellationRequested() {
                    // If this method is called then an operation within the stream
                    // pipeline is short-circuiting (see AbstractPipeline.copyInto).
                    // Note that we cannot differentiate between an upstream or
                    // downstream operation
                    cancellationRequestedCalled = true;
                    return downstream.cancellationRequested();
                }
            };
        }
    };
}
 
源代码19 项目: openjdk-jdk8u   文件: DoublePipeline.java
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                // true if cancellationRequested() has been called
                boolean cancellationRequestedCalled;

                // cache the consumer to avoid creation on every accepted element
                DoubleConsumer downstreamAsDouble = downstream::accept;

                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream result = mapper.apply(t)) {
                        if (result != null) {
                            if (!cancellationRequestedCalled) {
                                result.sequential().forEach(downstreamAsDouble);
                            }
                            else {
                                Spliterator.OfDouble s = result.sequential().spliterator();
                                do { } while (!downstream.cancellationRequested() && s.tryAdvance(downstreamAsDouble));
                            }
                        }
                    }
                }

                @Override
                public boolean cancellationRequested() {
                    // If this method is called then an operation within the stream
                    // pipeline is short-circuiting (see AbstractPipeline.copyInto).
                    // Note that we cannot differentiate between an upstream or
                    // downstream operation
                    cancellationRequestedCalled = true;
                    return downstream.cancellationRequested();
                }
            };
        }
    };
}
 
源代码20 项目: Bytecoder   文件: DoublePipeline.java
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                // true if cancellationRequested() has been called
                boolean cancellationRequestedCalled;

                // cache the consumer to avoid creation on every accepted element
                DoubleConsumer downstreamAsDouble = downstream::accept;

                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    try (DoubleStream result = mapper.apply(t)) {
                        if (result != null) {
                            if (!cancellationRequestedCalled) {
                                result.sequential().forEach(downstreamAsDouble);
                            }
                            else {
                                var s = result.sequential().spliterator();
                                do { } while (!downstream.cancellationRequested() && s.tryAdvance(downstreamAsDouble));
                            }
                        }
                    }
                }

                @Override
                public boolean cancellationRequested() {
                    // If this method is called then an operation within the stream
                    // pipeline is short-circuiting (see AbstractPipeline.copyInto).
                    // Note that we cannot differentiate between an upstream or
                    // downstream operation
                    cancellationRequestedCalled = true;
                    return downstream.cancellationRequested();
                }
            };
        }
    };
}
 
 同类方法