Changeset 15909 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-02-23T00:29:53+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSRule.java
r15717 r15909 8 8 import org.openstreetmap.josm.gui.mappaint.Environment; 9 9 import org.openstreetmap.josm.gui.mappaint.StyleSource; 10 import org.openstreetmap.josm.tools.Utils; 10 11 11 12 /** … … 48 49 */ 49 50 public Declaration(List<Instruction> instructions, int idx) { 50 this.instructions = instructions;51 this.instructions = Utils.toUnmodifiableList(instructions); 51 52 this.idx = idx; 52 53 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r15730 r15909 537 537 538 538 protected AbstractSelector(List<Condition> conditions) { 539 if (conditions == null || conditions.isEmpty()) { 540 this.conds = null; 541 } else { 542 this.conds = conditions; 543 } 539 this.conds = Utils.toUnmodifiableList(conditions); 544 540 } 545 541 … … 552 548 public boolean matches(Environment env) { 553 549 CheckParameterUtil.ensureParameterNotNull(env, "env"); 554 if (conds == null) return true;555 550 for (Condition c : conds) { 556 551 try { … … 569 564 */ 570 565 public List<Condition> getConditions() { 571 if (conds == null) { 572 return Collections.emptyList(); 573 } 574 return Collections.unmodifiableList(conds); 566 return conds; 575 567 } 576 568 } -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java
r15583 r15909 89 89 public int classification; 90 90 public int favoriteIndex; 91 private final Collection<String> groups = new HashSet<>();92 private final Collection<String> names = new HashSet<>();93 private final Collection<String> tags = new HashSet<>();91 private final Collection<String> groups; 92 private final Collection<String> names; 93 private final Collection<String> tags; 94 94 95 95 PresetClassification(TaggingPreset preset) { 96 96 this.preset = preset; 97 Set<String> groups = new HashSet<>(); 98 Set<String> names = new HashSet<>(); 99 Set<String> tags = new HashSet<>(); 97 100 TaggingPreset group = preset.group; 98 101 while (group != null) { … … 119 122 } 120 123 } 124 this.groups = Utils.toUnmodifiableList(groups); 125 this.names = Utils.toUnmodifiableList(names); 126 this.tags = Utils.toUnmodifiableList(tags); 121 127 } 122 128 -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r15866 r15909 748 748 749 749 /** 750 * Returns an unmodifiable list for the given collection. 751 * Makes use of {@link Collections#emptySet()} and {@link Collections#singleton} and {@link Arrays#asList} to save memory. 752 * @param collection the collection for which an unmodifiable collection is to be returned 753 * @param <T> the class of the objects in the array 754 * @return an unmodifiable list 755 * @see <a href="https://dzone.com/articles/preventing-your-java-collections-from-wasting-memo"> 756 * How to Prevent Your Java Collections From Wasting Memory</a> 757 */ 758 @SuppressWarnings("unchecked") 759 public static <T> List<T> toUnmodifiableList(Collection<T> collection) { 760 // Java 9: use List.of(...) 761 if (collection == null || collection.isEmpty()) { 762 return Collections.emptyList(); 763 } else if (collection.size() == 1) { 764 return Collections.singletonList(collection.iterator().next()); 765 } else { 766 return (List<T>) Arrays.asList(collection.toArray()); 767 } 768 } 769 770 /** 750 771 * Returns the first not empty string in the given candidates, otherwise the default string. 751 772 * @param defaultString default string returned if all candidates would be empty if stripped
Note:
See TracChangeset
for help on using the changeset viewer.