/** * Merges the specified date/value point into this builder. * * <p>The operator is invoked if the date already exists. * * @param date the date to be added * @param value the value associated with the date * @param operator the operator to use for merging * @return this builder */ public LocalDateDoubleTimeSeriesBuilder merge( LocalDate date, double value, DoubleBinaryOperator operator) { ArgChecker.notNull(date, "date"); ArgChecker.notNull(operator, "operator"); entries.merge(date, value, (a, b) -> operator.applyAsDouble(a, b)); return this; }
/** * Reduces this matrix returning a single value. * * <p>This is used to reduce the values in this matrix to a single value. The operator is called * once for each element in the matrix. The first argument to the operator is the running total of * the reduction, starting from zero. The second argument to the operator is the element. * * <p>This instance is immutable and unaffected by this method. * * @param identity the identity value to start from * @param operator the operator used to combine the value with the current total * @return the result of the reduction */ public double reduce(double identity, DoubleBinaryOperator operator) { double result = identity; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { result = operator.applyAsDouble(result, array[i][j]); } } return result; }
/** * Returns an instance where each element is formed by some combination of the matching values in * this matrix and the other matrix. * * <p>This is used to combine two matrices, returning a new matrix. Element {@code (i,j)} in the * resulting matrix is equal to the result of the operator when applied to element {@code (i,j)} * in this array and element {@code (i,j)} in the other array. The arrays must be of the same * size. * * <p>This instance is immutable and unaffected by this method. * * @param other the other matrix * @param operator the operator used to combine each pair of values * @return a copy of this matrix combined with the specified matrix * @throws IllegalArgumentException if the matrices have different sizes */ public DoubleMatrix combine(DoubleMatrix other, DoubleBinaryOperator operator) { if (rows != other.rows || columns != other.columns) { throw new IllegalArgumentException("Arrays have different sizes"); } double[][] result = new double[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { result[i][j] = operator.applyAsDouble(array[i][j], other.array[i][j]); } } return new DoubleMatrix(result, rows, columns); }
/** * Merges the specified date/value point into this builder. * * <p>The operator is invoked if the date already exists. * * @param point the point to be added * @param operator the operator to use for merging * @return this builder */ public LocalDateDoubleTimeSeriesBuilder merge( LocalDateDoublePoint point, DoubleBinaryOperator operator) { ArgChecker.notNull(point, "point"); entries.merge(point.getDate(), point.getValue(), (a, b) -> operator.applyAsDouble(a, b)); return this; }