Ignore:
Timestamp:
2020-03-01T23:35:53+01:00 (4 years ago)
Author:
simon04
Message:

see #18802 - MapCSSTagChecker.TagCheck: use unmodifiable collections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r15909 r15982  
    4848import java.util.List;
    4949import java.util.Locale;
     50import java.util.Map;
    5051import java.util.Optional;
    5152import java.util.concurrent.ExecutionException;
     
    6970import javax.script.ScriptEngineManager;
    7071
     72import com.kitfox.svg.xml.XMLParseUtil;
    7173import org.openstreetmap.josm.spi.preferences.Config;
    7274
     
    766768            return (List<T>) Arrays.asList(collection.toArray());
    767769        }
     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);
    768785    }
    769786
Note: See TracChangeset for help on using the changeset viewer.