Class UnmodifiableCounter


  • public final class UnmodifiableCounter
    extends Counter

    A "wrapper" class that allows retrieving values from a pre-existing Counter but prevents users from modifying it.

    Since:
    2.5.1
    Author:
    oswaldo.bapvic.jr
    See Also:
    Counter
    • Constructor Detail

      • UnmodifiableCounter

        public UnmodifiableCounter​(Counter counter)
        Creates an unmodifiable Counter.
        Parameters:
        counter - the Counter to be wrapped; not null
        Throws:
        NullPointerException - if the specified counter is null
    • Method Detail

      • getUnitsBefore

        public long getUnitsBefore()
        Description copied from class: Counter
        Returns the value of the unitsBefore field.
        Overrides:
        getUnitsBefore in class Counter
        Returns:
        the value of the unitsBefore field
      • setUnitsBefore

        public void setUnitsBefore​(long unitsBefore)
        Description copied from class: Counter
        Populates the unitsBefore field with an arbitrary value.
        Overrides:
        setUnitsBefore in class Counter
        Parameters:
        unitsBefore - the units to be set
      • getUnitsAfter

        public long getUnitsAfter()
        Description copied from class: Counter
        Returns the value of the unitsAfter field.
        Overrides:
        getUnitsAfter in class Counter
        Returns:
        the value of the unitsAfter field
      • setUnitsAfter

        public void setUnitsAfter​(long unitsAfter)
        Description copied from class: Counter
        Populates the unitsAfter field with an arbitrary value.
        Overrides:
        setUnitsAfter in class Counter
        Parameters:
        unitsAfter - the units to be set
      • elapsedTime

        public Duration elapsedTime()
        Description copied from class: Counter
        Returns the elapsed time.
        Overrides:
        elapsedTime in class Counter
        Returns:
        the difference between unitsBefore and unitsAfter, if both units are set; or the difference between unitsBefore and the current value retrieved by the counter's time source, if unitsAfter is not set.
      • elapsedTime

        public double elapsedTime​(TimeUnit timeUnit)
        Description copied from class: Counter
        Returns the elapsed time in the specified TimeUnit.
        Overrides:
        elapsedTime in class Counter
        Parameters:
        timeUnit - the time unit to which the elapsed time will be converted
        Returns:
        the difference between unitsBefore and unitsAfter, if both units are set; or the difference between unitsBefore and the current value retrieved by the counter's time source, if unitsAfter is not set. The value is converted into the specified time unit applying the default conversion mode.
      • elapsedTime

        public double elapsedTime​(TimeUnit timeUnit,
                                  ConversionMode conversionMode)
        Description copied from class: Counter
        Returns the elapsed time, in a given TimeUnit, with a custom ConversionMode.
        Overrides:
        elapsedTime in class Counter
        Parameters:
        timeUnit - the time unit to which the elapsed time will be converted
        conversionMode - the ConversionMode to be used
        Returns:
        the difference between unitsBefore and unitsAfter, if both units are set; or the difference between unitsBefore and the current value retrieved by the counter's time source, if unitsAfter is not set. The value is converted into the specified time unit applying the given conversion mode.