Changeset 15982 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r15981 r15982 283 283 protected final GroupedMapCSSRule rule; 284 284 /** Commands to apply in order to fix a matching primitive */ 285 protected final List<FixCommand> fixCommands = new ArrayList<>();285 protected final List<FixCommand> fixCommands; 286 286 /** Tags (or arbitrary strings) of alternatives to be presented to the user */ 287 protected final List<String> alternatives = new ArrayList<>();287 protected final List<String> alternatives; 288 288 /** An {@link org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.AssignmentInstruction}-{@link Severity} pair. 289 289 * Is evaluated on the matching primitive to give the error message. Map is checked to contain exactly one element. */ 290 protected final Map<Instruction.AssignmentInstruction, Severity> errors = new HashMap<>();290 protected final Map<Instruction.AssignmentInstruction, Severity> errors; 291 291 /** MapCSS Classes to set on matching primitives */ 292 protected final Set<String> setClassExpressions= new HashSet<>();292 protected final Collection<String> setClassExpressions; 293 293 /** Denotes whether the object should be deleted for fixing it */ 294 294 protected boolean deletion; … … 298 298 TagCheck(GroupedMapCSSRule rule) { 299 299 this.rule = rule; 300 this.fixCommands = new ArrayList<>(); 301 this.alternatives = new ArrayList<>(); 302 this.errors = new HashMap<>(); 303 this.setClassExpressions = new HashSet<>(); 304 } 305 306 TagCheck(TagCheck check) { 307 this.rule = check.rule; 308 this.fixCommands = Utils.toUnmodifiableList(check.fixCommands); 309 this.alternatives = Utils.toUnmodifiableList(check.alternatives); 310 this.errors = Utils.toUnmodifiableMap(check.errors); 311 this.setClassExpressions = Utils.toUnmodifiableList(check.setClassExpressions); 312 this.deletion = check.deletion; 313 this.group = check.group; 314 } 315 316 TagCheck toImmutable() { 317 return new TagCheck(this); 300 318 } 301 319 … … 372 390 MapCSSTagCheckerAsserts.checkAsserts(check, assertions, assertionConsumer); 373 391 } 374 return check; 392 return check.toImmutable(); 375 393 } 376 394 -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r15909 r15982 48 48 import java.util.List; 49 49 import java.util.Locale; 50 import java.util.Map; 50 51 import java.util.Optional; 51 52 import java.util.concurrent.ExecutionException; … … 69 70 import javax.script.ScriptEngineManager; 70 71 72 import com.kitfox.svg.xml.XMLParseUtil; 71 73 import org.openstreetmap.josm.spi.preferences.Config; 72 74 … … 766 768 return (List<T>) Arrays.asList(collection.toArray()); 767 769 } 770 } 771 772 /** 773 * Returns an unmodifiable map for the given map. 774 * Makes use of {@link Collections#emptyMap()} and {@link Collections#singletonMap} and {@link Map#ofEntries(Map.Entry[])} to save memory. 775 * 776 * @param map the map for which an unmodifiable map is to be returned 777 * @param <K> the type of keys maintained by this map 778 * @param <V> the type of mapped values 779 * @return an unmodifiable map 780 * @see <a href="https://dzone.com/articles/preventing-your-java-collections-from-wasting-memo"> 781 * How to Prevent Your Java Collections From Wasting Memory</a> 782 */ 783 public static <K, V> Map<K, V> toUnmodifiableMap(Map<K, V> map) { 784 return XMLParseUtil.toUnmodifiableMap(map); 768 785 } 769 786 -
trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
r15909 r15982 14 14 import java.util.Arrays; 15 15 import java.util.Collections; 16 import java.util.HashMap; 16 17 import java.util.LinkedList; 17 18 import java.util.List; 18 19 import java.util.Locale; 20 import java.util.Map; 21 import java.util.TreeMap; 19 22 import java.util.regex.Pattern; 20 23 … … 574 577 assertEquals(Arrays.asList("foo", "bar", "baz"), Utils.toUnmodifiableList(new LinkedList<>(Arrays.asList("foo", "bar", "baz")))); 575 578 } 579 580 /** 581 * Test of {@link Utils#toUnmodifiableMap} 582 */ 583 @Test 584 public void testToUnmodifiableMap() { 585 assertSame(Collections.emptyMap(), Utils.toUnmodifiableMap(null)); 586 assertSame(Collections.emptyMap(), Utils.toUnmodifiableMap(Collections.emptyMap())); 587 assertSame(Collections.emptyMap(), Utils.toUnmodifiableMap(new HashMap<>())); 588 assertSame(Collections.emptyMap(), Utils.toUnmodifiableMap(new TreeMap<>())); 589 assertEquals(Collections.singletonMap("foo", "bar"), Utils.toUnmodifiableMap(new HashMap<>(Collections.singletonMap("foo", "bar")))); 590 assertEquals(Collections.singletonMap("foo", "bar"), Utils.toUnmodifiableMap(new TreeMap<>(Collections.singletonMap("foo", "bar")))); 591 final Map<String, String> map4 = new HashMap<>(); 592 map4.put("jjj", "foo"); 593 map4.put("ooo", "bar"); 594 map4.put("sss", "baz"); 595 map4.put("mmm", ":-)"); 596 assertEquals(map4, Utils.toUnmodifiableMap(map4)); 597 } 576 598 }
Note:
See TracChangeset
for help on using the changeset viewer.