Class KindOfQuantity<U extends TypedUnit<U>>

    • Method Detail

      • format

        public static <U extends TypedUnit<U>> String format​(Number number,
                                                             IUnit unit)
        Convenience method (possibly temporary) until type parameters has settled.
        Type Parameters:
        U - Unit type. Inferred from the unit argument.
        number - numerical quantity value
        unit - quantity unit
        a string representing a formatted version of the number with unit
      • getDefaultUnit

        public abstract U getDefaultUnit()
      • addUnit

        protected void addUnit​(U unit)
        Add a common unit (displayed to the user when selecting a unit).
      • getCommonUnits

        public Collection<? extends U> getCommonUnits()
        the most common units, suitable to display a unit selection to the user.
        See Also:
      • getAllUnits

        public Collection<? extends U> getAllUnits()
        all units, suitable for parsing, content assist and similar.
        See Also:
      • getUnit

        public U getUnit​(String id)
      • combine

        public IConstraint<IQuantity> combine​(IConstraint<?> other)
        Description copied from interface: IConstraint
        Return a constraint that honors both this constraint and other, if such a constraint would accept anything except null. Otherwise, return null.
        Specified by:
        combine in interface IConstraint<U extends TypedUnit<U>>
        a constraint or null
      • validate

        public boolean validate​(IQuantity value)
        Description copied from interface: IConstraint
        Fundamentally, check that value satisfies this constraint and throw an exception otherwise. As long as the method returns normally, value is a valid value, regardless of the return value. However, when wrapping a persister in a constraint, it is possible that the persister treats some magic values differently. If the constraint isn't aware of these magical values it should typically not try to validate them. This is signaled by the persister by returning true from this method.
        Specified by:
        validate in interface IConstraint<U extends TypedUnit<U>>
        Specified by:
        validate in interface IPersister<U extends TypedUnit<U>>
        true if this value is considered magical and further validation should be skipped, false otherwise. Any return value mean that the value is valid.
      • getPreferredUnit

        public abstract U getPreferredUnit​(IQuantity quantity,
                                           double minNumericalValue,
                                           double maxNumericalValue)
      • getLargestExactUnit

        public abstract U getLargestExactUnit​(IQuantity quantity)
        Get the largest unit, if any, in which this quantity can be expressed exactly, typically with an integer. If the quantity has zero magnitude (quantity.doubleValue() == 0.0), quantity.getUnit() will be returned. Thus, if you want to find out a maximum common unit for a set of quantities (not recommended), only use the non-zero quantities.

        Note that this may be a fairly expensive operation, and isn't intended to be used excessively. The only valid use case is for guessing the original unit in which a quantity was expressed, after it has been stored or transmitted using a legacy mechanism with a fixed unit.

        a unit or null
      • getFirstBucket

        public final IRange<IQuantity> getFirstBucket​(IQuantity start,
                                                      IQuantity end,
                                                      double maxBuckets)
        Divide the given range into at most maxBuckets "naturally" aligned buckets, and return the first one. This can be used to create tick marks in charts or buckets for histograms. The number of buckets will typically be between maxBuckets/2 and maxBuckets, but this should be better specified.

        Note that start is included in the first bucket.

        start - range start value
        end - range end value
        maxBuckets - maximum number of buckets to divide range into
        the first bucket, as described above
      • getFormatterResolving

        public abstract IFormatter<IQuantity> getFormatterResolving​(IRange<IQuantity> range)
        Get a formatter with sufficient resolution to produce unique strings for both ends of range, and consecutive equally spaced quantities. The returned formatter might implement IIncrementalFormatter, in which case its method can be used to reduce redundant information between adjacent quantities.
      • getAccessorKeys

        public Map<IAccessorKey<?>,​? extends IDescribable> getAccessorKeys()
        Description copied from interface: IType
        Get keys for the accessors that this type knows of. Note that the returned accessors does not necessarily cover all possible data from the items of this type, and that it is always possible to define additional accessors that get or calculate values from the items in non-standard ways.

        Should only be used for low level type inspection. Iterators etc. should use a collection of predefined attributes.

        Specified by:
        getAccessorKeys in interface IType<U extends TypedUnit<U>>
        getAccessorKeys in class ContentType<IQuantity>
        keys for the accessors defined for this type