Class DefaultTickUnitSupplier

  • All Implemented Interfaces:
    TickUnitSupplier

    public final class DefaultTickUnitSupplier
    extends java.lang.Object
    implements TickUnitSupplier
    TickUnitSupplier that computes tick units as multiplications of powers of 10.

    The multipliers (factors) can be specified during the construction. They are expected to be numbers between 1 (inclusive) and 10 (exclusive). See computeTickUnit(double) for more details.

    Author:
    Grzegorz Kruk
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultTickUnitSupplier()
      Creates a new instance of DefaultTickUnitSupplier initialized with multipliers: [1, 2.5, 5].
      DefaultTickUnitSupplier​(java.util.SortedSet<? extends java.lang.Number> multipliers)
      Creates a new instance of DefaultTickUnitSupplier with specified multipliers.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double computeTickUnit​(double referenceTickUnit)
      Computes tick unit using the following formula: tickUnit = M*10^E, where M is one of the multipliers specified in the constructor and E is an exponent of 10.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultTickUnitSupplier

        public DefaultTickUnitSupplier()
        Creates a new instance of DefaultTickUnitSupplier initialized with multipliers: [1, 2.5, 5].
      • DefaultTickUnitSupplier

        public DefaultTickUnitSupplier​(java.util.SortedSet<? extends java.lang.Number> multipliers)
        Creates a new instance of DefaultTickUnitSupplier with specified multipliers.
        Parameters:
        multipliers - an array of ascending numbers, with at least one element, from 1 (inclusive) to 10 (exclusive).
    • Method Detail

      • computeTickUnit

        public double computeTickUnit​(double referenceTickUnit)
        Computes tick unit using the following formula: tickUnit = M*10^E, where M is one of the multipliers specified in the constructor and E is an exponent of 10. Both M and E are selected so that the calculated unit is the smallest (closest to the zero) value that is grater than or equal to the reference tick unit.

        For example with multipliers [1, 2, 5], the method will give the following results:

         computeTickUnit(0.01) returns 0.01
         computeTickUnit(0.42) returns 0.5
         computeTickUnit(1.73) returns 2
         computeTickUnit(5)    returns 5
         computeTickUnit(27)   returns 50
         
        Specified by:
        computeTickUnit in interface TickUnitSupplier
        Parameters:
        referenceTickUnit - the reference tick unit, must be a positive number
        Returns:
        the computed unit that is equal or grater to the specified one