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 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 forStyleElementList
,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
-
Constructor Summary
Constructors Modifier Constructor Description protected
DividedScale()
protected
DividedScale(DividedScale<T> s)
-
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 theput
operation.java.lang.String
toString()
-
-
-
Constructor Detail
-
DividedScale
protected DividedScale()
-
DividedScale
protected DividedScale(DividedScale<T> s)
-
-
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,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 objectr
- the valid range- Returns:
- a new, updated,
DividedScale
object
-
putImpl
private void putImpl(T o, double lower, double upper)
Implementation of theput
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 objectlower
- lower boundupper
- 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 classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-