Changeset 9649 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2016-01-27T17:02:17+01:00 (8 years ago)
Author:
bastiK
Message:

applied #12355 - add a new TagMap as Set<String, String> (patch by michael2402)

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

    r9460 r9649  
    99import java.util.Collections;
    1010import java.util.Date;
    11 import java.util.HashMap;
    1211import java.util.HashSet;
    1312import java.util.Map;
     
    391390     */
    392391    @Override
    393     public Map<String, String> getKeys() {
    394         String[] keys = this.keys;
    395         final Map<String, String> result = new HashMap<>(
    396                 Utils.hashMapInitialCapacity(keys == null ? 0 : keys.length / 2));
    397         if (keys != null) {
    398             for (int i = 0; i < keys.length; i += 2) {
    399                 result.put(keys[i], keys[i + 1]);
    400             }
    401         }
    402         return result;
     392    public TagMap getKeys() {
     393        return new TagMap(keys);
    403394    }
    404395
     
    444435        }
    445436        this.keys = newKeys;
     437        keysChangedImpl(originalKeys);
     438    }
     439
     440    /**
     441     * Copy the keys from a TagMap.
     442     * @param keys The new key map.
     443     */
     444    public void setKeys(TagMap keys) {
     445        Map<String, String> originalKeys = getKeys();
     446        String[] arr = keys.getTagsArray();
     447        if (arr.length == 0) {
     448            this.keys = null;
     449        } else {
     450            this.keys = arr;
     451        }
    446452        keysChangedImpl(originalKeys);
    447453    }
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r9552 r9649  
    919919
    920920    @Override
     921    public final void setKeys(TagMap keys) {
     922        boolean locked = writeLock();
     923        try {
     924            super.setKeys(keys);
     925        } finally {
     926            writeUnlock(locked);
     927        }
     928    }
     929
     930    @Override
    921931    public final void setKeys(Map<String, String> keys) {
    922932        boolean locked = writeLock();
  • trunk/src/org/openstreetmap/josm/data/osm/Tag.java

    r9545 r9649  
    55import java.util.Collections;
    66import java.util.Map;
     7import java.util.Map.Entry;
    78import java.util.Objects;
    89
     
    1819 * the modifying methods throw an {@link UnsupportedOperationException}.
    1920 */
    20 public class Tag implements Tagged {
     21public class Tag implements Tagged, Entry<String, String> {
    2122
    2223    private final String key;
     
    6667     * @return the key of the tag
    6768     */
     69    @Override
    6870    public String getKey() {
    6971        return key;
     
    7577     * @return the value of the tag
    7678     */
     79    @Override
    7780    public String getValue() {
    7881        return value;
     82    }
     83
     84    /**
     85     * This is not supported by this implementation.
     86     * @param value ignored
     87     * @return (Does not return)
     88     * @throws UnsupportedOperationException always
     89     */
     90    @Override
     91    public String setValue(String value) {
     92        throw new UnsupportedOperationException();
    7993    }
    8094
Note: See TracChangeset for help on using the changeset viewer.