Class DistanceValue

java.lang.Object
yearreview.app.util.value.Value
yearreview.app.util.value.DistanceValue
All Implemented Interfaces:
Comparable<Value>

public class DistanceValue extends Value
A Value that represents a Distance, internally using the Length-Datatype.
Author:
ColdStone37
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final io.jenetics.jpx.Length
    Internal representation of the Distance.
    private static final int
    Precision to use in the toString()-function.
    (package private) Map<io.jenetics.jpx.Length.Unit,String>
    Mapping from all units to their abbreviations.
  • Constructor Summary

    Constructors
    Constructor
    Description
    DistanceValue(double distance, io.jenetics.jpx.Length.Unit unit)
    Constructs a DistanceValue from a distance in a certain unit.
    DistanceValue(io.jenetics.jpx.Length distance)
    Constructs a DistanceValue from a Length.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Compares to another Value-object.
    Gets the Type of this Value.
    protected Object
    Gets the internally used Value to measure the distance.
    plus(Value other)
    Gets a DistanceValue that has to sum of this object and the other-object.
    Formats the Distance to a String.
    toString(io.jenetics.jpx.Length.Unit unit)
    Formats the Distance to a String in a certain unit.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • DISTANCE_PRECISION

      private static final int DISTANCE_PRECISION
      Precision to use in the toString()-function.
      See Also:
    • distance

      private final io.jenetics.jpx.Length distance
      Internal representation of the Distance.
    • lengthUnitShort

      Map<io.jenetics.jpx.Length.Unit,String> lengthUnitShort
      Mapping from all units to their abbreviations.
  • Constructor Details

    • DistanceValue

      public DistanceValue(io.jenetics.jpx.Length distance)
      Constructs a DistanceValue from a Length.
      Parameters:
      distance - distance to initialize the DistanceValue with
    • DistanceValue

      public DistanceValue(double distance, io.jenetics.jpx.Length.Unit unit)
      Constructs a DistanceValue from a distance in a certain unit.
      Parameters:
      distance - distance to initialize the DistanceValue with
      unit - unit of the value in the distance argument
  • Method Details

    • getType

      public ValueType getType()
      Gets the Type of this Value.
      Specified by:
      getType in class Value
      Returns:
      ValueType.DISTANCE
    • toString

      public String toString()
      Formats the Distance to a String.
      Specified by:
      toString in class Value
      Returns:
      formatted distance (e.g. "42.34 m")
    • toString

      public String toString(io.jenetics.jpx.Length.Unit unit)
      Formats the Distance to a String in a certain unit.
      Parameters:
      unit - unit to format the distance to
      Returns:
      formatted distance (e.g. 123.45 ft)
    • plus

      public Value plus(Value other)
      Gets a DistanceValue that has to sum of this object and the other-object.
      Specified by:
      plus in class Value
      Parameters:
      other - Value to add
      Returns:
      DistanceValue or null if the other Value is not of the same type
    • getValue

      protected Object getValue()
      Gets the internally used Value to measure the distance.
      Specified by:
      getValue in class Value
      Returns:
      Length-object
    • compareTo

      public int compareTo(Value other)
      Compares to another Value-object.
      Parameters:
      other - Value-object to compare against
      Returns:
      comparison of distances or Integer.MAX_VALUE if the other Value isn't a DistanceValue