Class DividedScale<T>

  • Type Parameters:
    T - the type of the data objects

    public class DividedScale<T>
    extends java.lang.Object
    Splits the range of possible scale values (0 < scale < +Infinity) into multiple subranges, for each scale range it keeps a data object of a certain type T (can be null). Used for caching style information for different zoom levels. Immutable class, equals & hashCode is required (the same for StyleElementList, StyleElement and its subclasses).
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  DividedScale.RangeViolatedError
      This exception type is for debugging #8997 and can later be replaced by AssertionError
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<T> data  
      private java.util.List<Range> ranges  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void consistencyTest()
      Runs a consistency test.
      boolean equals​(java.lang.Object obj)  
      T get​(double scale)
      Looks up the data object for a certain scale value.
      Pair<T,​Range> getWithRange​(double scale)
      Looks up the data object for a certain scale value and additionally returns the scale range where the object is valid.
      int hashCode()  
      DividedScale<T> put​(T o, Range r)
      Add data object which is valid for the given range.
      private void putImpl​(T o, double lower, double upper)
      Implementation of the put operation.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • data

        private final java.util.List<T> data
    • Method Detail

      • get

        public T get​(double scale)
        Looks up the data object for a certain scale value.
        Parameters:
        scale - scale
        Returns:
        the data object at the given scale, can be null
      • getWithRange

        public Pair<T,​RangegetWithRange​(double scale)
        Looks up the data object for a certain scale value and additionally returns the scale range where the object is valid.
        Parameters:
        scale - scale
        Returns:
        pair containing data object and range
      • put

        public DividedScale<Tput​(T o,
                                   Range r)
        Add data object which is valid for the given range. This is only possible, if there is no data for the given range yet.
        Parameters:
        o - data object
        r - the valid range
        Returns:
        a new, updated, DividedScale object
      • putImpl

        private void putImpl​(T o,
                             double lower,
                             double upper)
        Implementation of the put operation. ASCII-art explanation: data[i-1] data[i] data[i+1 |--------------|------------|--------------| (--range[i-1]--] (--range[i]--] (--range[i+1]--] (--------] lower upper
        Parameters:
        o - data object
        lower - lower bound
        upper - upper bound
      • consistencyTest

        public void consistencyTest()
        Runs a consistency test.
        Throws:
        java.lang.AssertionError - When an invariant is broken.
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object