Last change
on this file since 9284 was 9284, checked in by bastiK, 8 years ago |
refactor some code from StyleCache into separate classes (see #9891)
|
-
Property svn:eol-style
set to
native
|
File size:
1.4 KB
|
Line | |
---|
1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.data.osm.Storage;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * Caches styles for a single primitive.
|
---|
8 | */
|
---|
9 | public final class StyleCache extends DividedScale<StyleElementList> {
|
---|
10 |
|
---|
11 | // TODO: clean up the intern pool from time to time (after purge or layer removal)
|
---|
12 | private static final Storage<StyleCache> internPool = new Storage<>();
|
---|
13 |
|
---|
14 | public static final StyleCache EMPTY_STYLECACHE = (new StyleCache()).intern();
|
---|
15 |
|
---|
16 | private StyleCache(StyleCache sc) {
|
---|
17 | super(sc);
|
---|
18 | }
|
---|
19 |
|
---|
20 | private StyleCache() {
|
---|
21 | super();
|
---|
22 | }
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Add data object which is valid for the given range.
|
---|
26 | *
|
---|
27 | * This is only possible, if there is no data for the given range yet.
|
---|
28 | *
|
---|
29 | * @param o data object
|
---|
30 | * @param r the valid range
|
---|
31 | * @return a new, updated, <code>DividedScale</code> object
|
---|
32 | */
|
---|
33 | @Override
|
---|
34 | public StyleCache put(StyleElementList o, Range r) {
|
---|
35 | StyleCache s = new StyleCache(this);
|
---|
36 | s.putImpl(o, r.getLower(), r.getUpper());
|
---|
37 | s.consistencyTest();
|
---|
38 | s.intern();
|
---|
39 | return s;
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Like String.intern() (reduce memory consumption).
|
---|
44 | * StyleCache must not be changed after it has been added to the intern pool.
|
---|
45 | * @return style cache
|
---|
46 | */
|
---|
47 | private StyleCache intern() {
|
---|
48 | return internPool.putUnique(this);
|
---|
49 | }
|
---|
50 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.