All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bbn.bue.common.DoubleAccumulator Maven / Gradle / Ivy

There is a newer version: 4.1.2
Show newest version
package com.bbn.bue.common;

/**
 * An {@link Accumulator} for {@code double}s.
 *
 * Based on FACTORIE's {@code DoubleAccumulator}.
 */
public final class DoubleAccumulator implements ScalableAccumulator {
  private double val = 0.0;

  private DoubleAccumulator() {

  }

  public static DoubleAccumulator create() {
    return new DoubleAccumulator();
  }

  @Override
  public void accumulate(final Double x) {
    val+=x;
  }

  @Override
  public void accumulate(final Double data, final double factor) {
    val += data * factor;
  }

  @Override
  public void accumulate(final Accumulator accumulator) {
    val+=accumulator.value();
  }

  @Override
  public void accumulate(final Accumulator accumulator, double factor) {
    val+=accumulator.value()*factor;
  }


  @Override
  public Double value() {
    return val;
  }

  @Override
  public String toString() {
    return "accumulator=" + val;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy