- Timestamp:
- 2021-04-20T21:08:56+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/DividedScale.java
r17793 r17805 177 177 @Override 178 178 public int hashCode() { 179 return Objects.hash(ranges, data);179 return 31 * ranges.hashCode() + data.hashCode(); 180 180 } 181 181 -
trunk/src/org/openstreetmap/josm/gui/mappaint/Range.java
r16322 r17805 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.mappaint; 3 4 import java.util.Objects;5 3 6 4 /** … … 117 115 @Override 118 116 public int hashCode() { 119 return Objects.hash(lower,upper);117 return 31 * Double.hashCode(lower) + Double.hashCode(upper); 120 118 } 121 119 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleCache.java
r17101 r17805 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import java.util.Arrays;5 4 import java.util.Map; 6 import java.util.O ptional;5 import java.util.Objects; 7 6 import java.util.concurrent.ConcurrentHashMap; 8 7 import java.util.function.Function; … … 25 24 public static final StyleCache EMPTY_STYLECACHE = new StyleCache().intern(); 26 25 27 private static final int PLAIN = 0; 28 private static final int SELECTED = 1; 29 30 @SuppressWarnings("unchecked") 31 private final DividedScale<StyleElementList>[] states = new DividedScale[2]; 26 private DividedScale<StyleElementList> plainStyle; 27 private DividedScale<StyleElementList> selectedStyle; 32 28 33 29 private StyleCache(StyleCache sc) { 34 states[0] = sc.states[0];35 s tates[1] = sc.states[1];30 plainStyle = sc.plainStyle; 31 selectedStyle = sc.selectedStyle; 36 32 } 37 33 … … 49 45 StyleCache s = new StyleCache(this); 50 46 51 int idx = getIndex(selected); 52 s.states[idx] = Optional.ofNullable(s.states[idx]).orElseGet(DividedScale::new).put(o, r); 47 if (selected) { 48 if (s.selectedStyle == null) { 49 s.selectedStyle = new DividedScale<>(); 50 } 51 s.selectedStyle.put(o, r); 52 } else { 53 if (s.plainStyle == null) { 54 s.plainStyle = new DividedScale<>(); 55 } 56 s.plainStyle.put(o, r); 57 } 53 58 return s.intern(); 54 59 } … … 61 66 */ 62 67 public Pair<StyleElementList, Range> getWithRange(double scale, boolean selected) { 63 int idx = getIndex(selected); 64 if (states[idx] == null) { 65 return Pair.create(null, Range.ZERO_TO_INFINITY); 66 } 67 return states[idx].getWithRange(scale); 68 } 69 70 private static int getIndex(boolean selected) { 71 return selected ? SELECTED : PLAIN; 68 DividedScale<StyleElementList> style = selected ? selectedStyle : plainStyle; 69 return style != null ? style.getWithRange(scale) : Pair.create(null, Range.ZERO_TO_INFINITY); 72 70 } 73 71 74 72 @Override 75 73 public String toString() { 76 return "StyleCache{PLAIN: " + this.states[PLAIN] + " SELECTED: " + this.states[SELECTED]+ "}";74 return "StyleCache{PLAIN: " + plainStyle + " SELECTED: " + selectedStyle + "}"; 77 75 } 78 76 79 77 @Override 80 78 public int hashCode() { 81 return Arrays.deepHashCode(this.states);79 return 31 * Objects.hashCode(plainStyle) + Objects.hashCode(selectedStyle); 82 80 } 83 81 … … 91 89 } 92 90 final StyleCache other = (StyleCache) obj; 93 return Arrays.deepEquals(this.states, other.states);91 return Objects.equals(plainStyle, other.plainStyle) && Objects.equals(selectedStyle, other.selectedStyle); 94 92 } 95 93
Note:
See TracChangeset
for help on using the changeset viewer.