Class TimeSpan.Item<U>

java.lang.Object
net.time4j.engine.TimeSpan.Item<U>
Type Parameters:
U - type of time unit
All Implemented Interfaces:
Serializable
Enclosing interface:
TimeSpan<U>

public static class TimeSpan.Item<U> extends Object implements Serializable

Represents a single item of a time span which is based on only one time unit and has a non-negative amount.

See Also:
Serialized Form
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals​(Object obj)
     
    long
    Yields the non-negative amount.
    Yields the time unit.
    int
     
    static <U> TimeSpan.Item<U>
    of​(long amount, U unit)
    Creates a new time span item.
    Provides a canonical representation in the format 'P' amount '{' unit '}', for example "P4{YEARS}".

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • of

      public static <U> TimeSpan.Item<U> of(long amount, U unit)

      Creates a new time span item.

      Type Parameters:
      U - type of time unit
      Parameters:
      amount - amount in units >= 0
      unit - time unit
      Returns:
      new time span item
      Throws:
      IllegalArgumentException - if amount is negative
    • getAmount

      public long getAmount()

      Yields the non-negative amount.

      Returns:
      amount in units (>= 0)
    • getUnit

      public U getUnit()

      Yields the time unit.

      Returns:
      time unit
    • equals

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

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

      public String toString()

      Provides a canonical representation in the format 'P' amount '{' unit '}', for example "P4{YEARS}".

      Overrides:
      toString in class Object
      Returns:
      String