Class Age

java.lang.Object
org.ka2ddo.yaac.ax25.Age
All Implemented Interfaces:
Comparable<Age>

public class Age extends Object implements Comparable<Age>
This class represents a message parameter (in milliseconds) in a form that can be rendered easily on a GUI widget.
Author:
Andrew Pavlin, KA2DDO
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Convenience constant for the number of milliseconds in a half hour.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Age(long millisecondsOfAge)
    Create an Age object with the specified number of milliseconds in its age.
    Age(String val)
    Create an Age object from a string in the format that Ages are presented in.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Test if this Age is older than another Age.
    static Age[]
    createAgeArray(long startInterval, long maxDelta)
    Create an array of Age objects covering the specified span of time in human-like spacings.
    static Age[]
    createAgeArray(long startInterval, long maxDelta, int padToString)
    Create an array of Age objects covering the specified span of time in human-like spacings.
    boolean
    Indicates whether some other object is "equal to" this one.
    long
    Get the delta time of this Age in milliseconds.
    int
    Obtain the minimum number of characters to render an Age.
    int
    Returns a hash code value for the object.
    static long
    Parse an Age value from a String in the format that Ages are presented in.
    void
    setPadToString(int padToString)
    Set the minimum number of characters to render an Age.
    Display a human-friendly representation of this Age's time interval.
    toString(boolean showBackwardsTime)
    Display a human-friendly representation of this Age's time interval.
    static String
    toString(long age)
    Display a delta time (in milliseconds) in a human friendly String.
    static String
    toString(long age, boolean showBackwardsTime)
    Display a delta time (in milliseconds) in a human friendly String.
    static String
    toString(long age, boolean showBackwardsTime, boolean spellOutUnits)
    Display a delta time (in milliseconds) in a human friendly String.
    static String
    toString(long age, boolean showBackwardsTime, boolean spellOutUnits, int padToString)
    Display a delta time (in milliseconds) in a human friendly String.

    Methods inherited from class java.lang.Object

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

    • HALF_HOUR_IN_MSEC

      public static final long HALF_HOUR_IN_MSEC
      Convenience constant for the number of milliseconds in a half hour.
      See Also:
  • Constructor Details

    • Age

      public Age(long millisecondsOfAge)
      Create an Age object with the specified number of milliseconds in its age.
      Parameters:
      millisecondsOfAge - milliseconds of age
    • Age

      public Age(String val) throws IllegalArgumentException
      Create an Age object from a string in the format that Ages are presented in.
      Parameters:
      val - String to parse
      Throws:
      IllegalArgumentException - if val can't be parsed
  • Method Details

    • parseAge

      public static long parseAge(String val)
      Parse an Age value from a String in the format that Ages are presented in.
      Parameters:
      val - String to parse
      Returns:
      parsed age in milliseconds
      Throws:
      IllegalArgumentException - if val can't be parsed
    • createAgeArray

      public static Age[] createAgeArray(long startInterval, long maxDelta)
      Create an array of Age objects covering the specified span of time in human-like spacings.
      Parameters:
      startInterval - the smallest time interval in milliseconds
      maxDelta - the largest time interval in milliseconds
      Returns:
      Age array of intervals in the requested span
    • createAgeArray

      public static Age[] createAgeArray(long startInterval, long maxDelta, int padToString)
      Create an array of Age objects covering the specified span of time in human-like spacings.
      Parameters:
      startInterval - the smallest time interval in milliseconds
      maxDelta - the largest time interval in milliseconds
      padToString - int minimum number of characters in string formatting
      Returns:
      Age array of intervals in the requested span
    • toString

      public String toString()
      Display a human-friendly representation of this Age's time interval.
      Overrides:
      toString in class Object
      Returns:
      the Age in days, hours, minutes, and seconds.
    • toString

      public String toString(boolean showBackwardsTime)
      Display a human-friendly representation of this Age's time interval.
      Parameters:
      showBackwardsTime - if boolean true and age is negative, show it as absolute, otherwise report "???"
      Returns:
      the Age in days, hours, minutes, and seconds.
    • toString

      public static String toString(long age)
      Display a delta time (in milliseconds) in a human friendly String.
      Parameters:
      age - the delta time in milliseconds
      Returns:
      the age in days, hours, minutes, and seconds.
    • toString

      public static String toString(long age, boolean showBackwardsTime)
      Display a delta time (in milliseconds) in a human friendly String.
      Parameters:
      age - the delta time in milliseconds
      showBackwardsTime - if boolean true and age is negative, show it as absolute, otherwise report "???"
      Returns:
      the age in days, hours, minutes, and seconds.
    • toString

      public static String toString(long age, boolean showBackwardsTime, boolean spellOutUnits)
      Display a delta time (in milliseconds) in a human friendly String.
      Parameters:
      age - the delta time in milliseconds
      showBackwardsTime - if boolean true and age is negative, show it as absolute, otherwise report "???"
      spellOutUnits - boolean true if spelled-out localized words for time units should be used instead of single English-unit letters
      Returns:
      the age in days, hours, minutes, and seconds.
    • toString

      public static String toString(long age, boolean showBackwardsTime, boolean spellOutUnits, int padToString)
      Display a delta time (in milliseconds) in a human friendly String.
      Parameters:
      age - the delta time in milliseconds
      showBackwardsTime - if boolean true and age is negative, show it as absolute, otherwise report "???"
      spellOutUnits - boolean true if spelled-out localized words for time units should be used instead of single English-unit letters
      padToString - int minimum number of characters in formatted age
      Returns:
      the age in days, hours, minutes, and seconds.
    • equals

      public boolean equals(Object obj)
      Indicates whether some other object is "equal to" this one.
      Overrides:
      equals in class Object
      Parameters:
      obj - the reference object with which to compare.
      Returns:
      true if this object is the same as the obj argument; false otherwise.
      See Also:
    • hashCode

      public int hashCode()
      Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for this object.
      See Also:
    • compareTo

      public int compareTo(Age o)
      Test if this Age is older than another Age. Note that "permanent" Ages are older than non-permanent ages.
      Specified by:
      compareTo in interface Comparable<Age>
      Parameters:
      o - other Age object to compare to this one
      Returns:
      -1 if this Age is older than the other Age, 0 if their ages are the same, or +1 if this Age is newer than the other Age
    • getAge

      public long getAge()
      Get the delta time of this Age in milliseconds.
      Returns:
      millisecond delta time of this Age
    • getPadToString

      public int getPadToString()
      Obtain the minimum number of characters to render an Age. Note that some Ages may render longer than this if they have more characters.
      Returns:
      int minimum character count
    • setPadToString

      public void setPadToString(int padToString)
      Set the minimum number of characters to render an Age. Note that some Ages may render longer than this if they have more characters.
      Parameters:
      padToString - int minimum character count