Class ResultsVector

Object
ResultsVector

public class ResultsVector extends Object
A vector of results of applying a feature-calculations to many entities.

Each position in the vector describes the result for a single entity. The result is either a Double or an Exception.

An Exception indicates that the feature-calculation ended in failure, producing the exception.

Author:
Owen Feehan
  • Constructor Details

    • ResultsVector

      public ResultsVector(int size)
      Creates with a particular size.
      Parameters:
      size - the number of results the vector can store.
  • Method Details

    • total

      public double total()
      The total value of all results.
      Returns:
      the sum of all results, or Double.NaN if any are errored.
    • set

      public void set(int index, double value)
      Assigns a result at a particular position.
      Parameters:
      index - the index of the position (zero-valued).
      value - the value to assign as a result.
    • set

      public void set(int startIndex, ResultsVector resultsToAssign)
      Assigns many results, starting at a particular position, and incrementing thereafter.
      Parameters:
      startIndex - the index of the initial position (zero-valued) for the first result.
      resultsToAssign - the values to assign in startIndex and subsequent positions.
    • setError

      public void setError(int index, Exception exception)
      Set an error state at a particular position.
      Parameters:
      index - the index of the position (zero-valued).
      exception - the error state.
    • setErrorAll

      public void setErrorAll(Exception exception)
      Set an error state at all positions.
      Parameters:
      exception - the error state.
    • getError

      public Exception getError(int index)
      Gets an error state at a particular position.

      This should only be called at positions which for sure are errored.

      Parameters:
      index - the position (zero-indexed).
      Returns:
      the exception for the error.
    • getResult

      public Optional<Double> getResult(int index)
      Gets a result value at a particular position.
      Parameters:
      index - the position (zero-indexed).
      Returns:
      the result-value if unerrored, or Optional.empty() if the position is errored.
    • get

      public double get(int index)
      The result of a feature-calculation stored at a particular index.
      Parameters:
      index - the index (zero-indexed). It should be >= 0 and < size().
      Returns:
      the value corresponding to the feature-calculation or Double.NaN if an exception occurred during calculation.
    • copyFrom

      public void copyFrom(int index, int length, ResultsVector source, int sourceIndex)
      Copies a contiguous subset of results from another vector.
      Parameters:
      index - start-position to start copying into (zero-indexed).
      length - number of items to copy.
      source - vector to copy from.
      sourceIndex - index in the source away to start from.
    • addTypedValuesTo

      public void addTypedValuesTo(Collection<TypedValue> addTo, int numberDecimalPlaces)
      Adds TypedValue representations of the results to a Collection.
      Parameters:
      addTo - the collection to add the representations to.
      numberDecimalPlaces - the number of decimal places to use, or -1 to visually shorten as much as possible.
    • size

      public int size()
      The number of calculations stored in the vector.
      Returns:
      the total number of calculations in the vector.
    • equals

      public boolean equals(Object... values)
      Does the instance have exactly these values?
      Parameters:
      values - the values to check for equality.
      Returns:
      true, if the results in this object are exactly the same as values.
    • equalsPrecision

      public boolean equalsPrecision(double eps, Object... values)
      Like equals(Object) but includes a tolerance for checking equality of the doubles.
      Parameters:
      eps - amount of allowed absolute error.
      values - the values to check for equality.
      Returns:
      true, if the results in this object are the same as values, within the tolerance.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object