Class DividedScale<T>

java.lang.Object
org.openstreetmap.josm.gui.mappaint.DividedScale<T>
Type Parameters:
T - the type of the data objects

public class DividedScale<T> extends 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).
  • Field Details

  • Constructor Details

  • Method Details

    • 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,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.
      Parameters:
      scale - scale
      Returns:
      pair containing data object and range
    • put

      public DividedScale<T> put(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:
      AssertionError - When an invariant is broken.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object