Class StyleCache
- java.lang.Object
-
- org.openstreetmap.josm.gui.mappaint.StyleCache
-
public final class StyleCache extends java.lang.Object
Caches styles for a single primitive.This object is immutable.
-
-
Field Summary
Fields Modifier and Type Field Description static StyleCache
EMPTY_STYLECACHE
An empty style cache entryprivate static java.util.Map<StyleCache,StyleCache>
internPool
private DividedScale<StyleElementList>
plainStyle
private DividedScale<StyleElementList>
selectedStyle
-
Constructor Summary
Constructors Modifier Constructor Description private
StyleCache()
private
StyleCache(StyleCache sc)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static void
clearStyleCachePool()
Clears the style cache.boolean
equals(java.lang.Object obj)
static int
getInternPoolSize()
Get the size of the intern pool.Pair<StyleElementList,Range>
getWithRange(double scale, boolean selected)
Get the style for a specific style.int
hashCode()
private StyleCache
intern()
Like String.intern() (reduce memory consumption).StyleCache
put(StyleElementList o, Range r, boolean selected)
Creates a new copy of this style cache with a new entry added.private static DividedScale<StyleElementList>
scale(DividedScale<StyleElementList> scale)
java.lang.String
toString()
-
-
-
Field Detail
-
internPool
private static final java.util.Map<StyleCache,StyleCache> internPool
-
EMPTY_STYLECACHE
public static final StyleCache EMPTY_STYLECACHE
An empty style cache entry
-
plainStyle
private DividedScale<StyleElementList> plainStyle
-
selectedStyle
private DividedScale<StyleElementList> selectedStyle
-
-
Constructor Detail
-
StyleCache
private StyleCache(StyleCache sc)
-
StyleCache
private StyleCache()
-
-
Method Detail
-
put
public StyleCache put(StyleElementList o, Range r, boolean selected)
Creates a new copy of this style cache with a new entry added.- Parameters:
o
- The style to cache.r
- The range the style is for.selected
- The style list we should use (selected/unselected)- Returns:
- The new object.
-
scale
private static DividedScale<StyleElementList> scale(DividedScale<StyleElementList> scale)
-
getWithRange
public Pair<StyleElementList,Range> getWithRange(double scale, boolean selected)
Get the style for a specific style. Returns the range as well.- Parameters:
scale
- The current scaleselected
- true to get the state for a selected element,- Returns:
- The style and the range it is valid for.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
intern
private StyleCache intern()
Like String.intern() (reduce memory consumption). StyleCache must not be changed after it has been added to the intern pool.- Returns:
- style cache
-
clearStyleCachePool
static void clearStyleCachePool()
Clears the style cache. This should only be used for testing. It may be removed some day and replaced by a WeakReference implementation that automatically forgets old entries.
-
getInternPoolSize
public static int getInternPoolSize()
Get the size of the intern pool. Only for tests!- Returns:
- size of the intern pool
-
-