Changeset 16188 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-03-21T22:09:31+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/util/LruCache.java
r16082 r16188 4 4 import java.util.LinkedHashMap; 5 5 import java.util.Map; 6 import java.util.Objects; 6 7 7 8 /** 8 * LRU cache 9 * LRU cache (least recently used) 10 * @param <K> the type of keys maintained by this map 11 * @param <V> the type of mapped values 9 12 * @see <a href="http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html"> 10 13 * Java Planet: How to set up a simple LRU cache using LinkedHashMap</a> … … 14 17 private final int capacity; 15 18 19 /** 20 * Constructs an empty {@code LruCache} instance with the given capacity 21 * @param capacity the capacity 22 */ 16 23 public LruCache(int capacity) { 17 24 super(capacity + 1, 1.1f, true); … … 23 30 return size() > capacity; 24 31 } 32 33 @Override 34 public boolean equals(Object o) { 35 if (this == o) return true; 36 if (o == null || getClass() != o.getClass()) return false; 37 if (!super.equals(o)) return false; 38 LruCache<?, ?> lruCache = (LruCache<?, ?>) o; 39 return capacity == lruCache.capacity; 40 } 41 42 @Override 43 public int hashCode() { 44 return Objects.hash(super.hashCode(), capacity); 45 } 25 46 } -
trunk/src/org/openstreetmap/josm/tools/GenericParser.java
r16184 r16188 10 10 * Utility class to parse various types from other values. 11 11 * 12 * @param <U> the type of the objects to parse 12 13 * @since 16184 13 14 */ … … 16 17 protected final Map<Class<?>, Function<U, ?>> parsers; 17 18 19 /** 20 * Creates an empty {@code GenericParser} 21 */ 18 22 public GenericParser() { 19 23 this(new LinkedHashMap<>()); … … 29 33 } 30 34 35 /** 36 * Creates a new {@code GenericParser} with the same parsers as the specified map 37 * 38 * @param parsers the parsers 39 */ 31 40 protected GenericParser(Map<Class<?>, Function<U, ?>> parsers) { 32 41 this.parsers = parsers; … … 80 89 * or {@code Optional.empty()} (if parsing fails, or the type is not {@linkplain #supports supported}) 81 90 */ 82 public <T> Optional< ?> tryParse(Class<?> type, U value) {91 public <T> Optional<T> tryParse(Class<T> type, U value) { 83 92 try { 84 93 return Optional.ofNullable(parse(type, value)); -
trunk/src/org/openstreetmap/josm/tools/StringParser.java
r16184 r16188 36 36 .parsers)); 37 37 38 /** 39 * Creates an empty {@code StringParser} 40 */ 38 41 public StringParser() { 39 42 super(); … … 49 52 } 50 53 51 pr otectedStringParser(Map<Class<?>, Function<String, ?>> parsers) {54 private StringParser(Map<Class<?>, Function<String, ?>> parsers) { 52 55 super(parsers); 53 56 } -
trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java
r16181 r16188 126 126 } 127 127 128 private void setValue(Entry entry, String fieldName, String value) throws SAXException { 129 if (value != null) { 130 value = value.intern(); 131 } 128 private void setValue(Entry entry, String fieldName, String value0) throws SAXException { 129 final String value = value0 != null ? value0.intern() : null; 132 130 CheckParameterUtil.ensureParameterNotNull(entry, "entry"); 133 131 if ("class".equals(fieldName) || "default".equals(fieldName) || "throw".equals(fieldName) || … … 142 140 f = entry.getField("locale_" + fieldName.substring(lang.length())); 143 141 } 144 Optional<?> parsed; 145 if (f != null && Modifier.isPublic(f.getModifiers()) && (parsed = primitiveParsers.tryParse(f.getType(), value)).isPresent()) { 142 Optional<?> parsed = Optional.ofNullable(f) 143 .filter(field -> Modifier.isPublic(field.getModifiers())) 144 .flatMap(field -> primitiveParsers.tryParse(field.getType(), value)); 145 if (parsed.isPresent()) { 146 146 f.set(c, parsed.get()); 147 147 } else {
Note:
See TracChangeset
for help on using the changeset viewer.