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,StyleElementand its subclasses).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDividedScale.RangeViolatedErrorThis exception type is for debugging #8997 and can later be replaced by AssertionError
-
Constructor Summary
Constructors Modifier Constructor Description protectedDividedScale()protectedDividedScale(DividedScale<T> s)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconsistencyTest()Runs a consistency test.booleanequals(java.lang.Object obj)Tget(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.inthashCode()DividedScale<T>put(T o, Range r)Add data object which is valid for the given range.private voidputImpl(T o, double lower, double upper)Implementation of theputoperation.java.lang.StringtoString()
-
-
-
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,
DividedScaleobject
-
putImpl
private void putImpl(T o, double lower, double upper)
Implementation of theputoperation. 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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-