Class TypedUnit<U extends TypedUnit<U>>

  • All Implemented Interfaces:
    IUnit
    Direct Known Subclasses:
    LinearUnit, TimestampUnit

    public abstract class TypedUnit<U extends TypedUnit<U>>
    extends Object
    implements IUnit
    Type parameterized extension of IUnit. This construction exists to reduce clutter for casual users of IUnit, while still providing type safety for internal implementations. (Proposed "self-variance" extensions to Java, in JDK 9 or beyond, may directly support this with a single interface.)
    • Constructor Detail

      • TypedUnit

        public TypedUnit()
    • Method Detail

      • getUnitClass

        protected abstract Class<U> getUnitClass()
        Get the typed Class object of the actual TypedUnit subclass U. This method is intended to simplify generic code, written in TypedUnit, to go from loosely typed arguments into stricter parameterized arguments.
      • getScaledUnit

        protected abstract U getScaledUnit​(LinearUnit deltaUnit)
        Return a unit with the same origin (if absolute) as this unit, but with the given deltaUnit as its delta unit. Linear units will return deltaUnit.
        Throws:
        IllegalArgumentException - if deltaUnit is of the wrong kind, although linear units are not guaranteed to verify this here
      • getContentType

        public abstract KindOfQuantity<U> getContentType()
        Description copied from interface: IUnit
        Get the kind of quantity of this unit.
        Specified by:
        getContentType in interface IUnit
      • quantity

        public ITypedQuantity<U> quantity​(Number value)
        Description copied from interface: IUnit
        Create a quantity expressed in this unit and with a numerical quantity value equal to numericalValue.
        Specified by:
        quantity in interface IUnit
      • quantity

        public abstract ITypedQuantity<U> quantity​(long numericalValue)
        Description copied from interface: IUnit
        Create a quantity expressed in this unit and with a numerical quantity value equal to numericalValue.
        Specified by:
        quantity in interface IUnit
      • quantity

        public abstract ITypedQuantity<U> quantity​(double numericalValue)
        Description copied from interface: IUnit
        Create a quantity expressed in this unit and with a numerical quantity value equal to numericalValue.
        Specified by:
        quantity in interface IUnit
      • valueTransformTo

        public IScalarAffineTransform valueTransformTo​(IUnit targetUnit)
        Description copied from interface: IUnit
        Get a transform for transforming numerical quantity values expressed in this unit to numerical quantity values expressed in targetUnit. This method is typically only used internally by the quantity implementations.
        Specified by:
        valueTransformTo in interface IUnit
      • valueTransformTo

        public abstract IScalarAffineTransform valueTransformTo​(U targetUnit)
        Get a transform for transforming numerical quantity values expressed in this unit to numerical quantity values expressed in targetUnit. This method is typically only used internally by the quantity implementations. Note that this method differs from valueTransformTo(IUnit) only by stricter typing.
        Throws:
        IllegalArgumentException - if targetUnit is not of the same kind of quantity
      • subtractSame

        protected abstract ITypedQuantity<LinearUnit> subtractSame​(long numericalMinuend,
                                                                   U subtrahendUnit,
                                                                   long numericalSubtrahend)
      • localizedFormatFor

        protected abstract String localizedFormatFor​(Number numericalValue,
                                                     boolean useBreakingSpace,
                                                     boolean allowCustomUnit)
      • persistableStringFor

        protected abstract String persistableStringFor​(Number numericalValue)