Ignore:
Timestamp:
2016-01-19T10:52:33+01:00 (8 years ago)
Author:
simon04
Message:

Refactoring (make Tag implement the Tagged interface)

File:
1 edited

Legend:

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

    r9371 r9536  
    22package org.openstreetmap.josm.data.osm;
    33
     4import java.util.Collection;
     5import java.util.Collections;
     6import java.util.Map;
    47import java.util.Objects;
    58
     
    1114 * be empty, but not null.
    1215 *
     16 * <p/>
     17 * It implements the {@link Tagged} interface. However, since instances of this class are immutable,
     18 * the modifying methods throw an {@link UnsupportedOperationException}.
    1319 */
    14 public class Tag {
     20public class Tag implements Tagged {
    1521
    16     private String key;
    17     private String value;
     22    private final String key;
     23    private final String value;
    1824
    1925    /**
     
    131137        return Utils.strip(s).replaceAll("\\s+", " ");
    132138    }
     139
     140    /**
     141     * Unsupported.
     142     * @param keys ignored
     143     * @throws UnsupportedOperationException
     144     */
     145    @Override
     146    public void setKeys(Map<String, String> keys) {
     147        throw new UnsupportedOperationException();
     148    }
     149
     150    @Override
     151    public Map<String, String> getKeys() {
     152        return Collections.singletonMap(key, value);
     153    }
     154
     155    /**
     156     * Unsupported.
     157     * @param key ignored
     158     * @param value ignored
     159     * @throws UnsupportedOperationException
     160     */
     161    @Override
     162    public void put(String key, String value) {
     163        throw new UnsupportedOperationException();
     164    }
     165
     166    @Override
     167    public String get(String k) {
     168        return key.equals(k) ? value : null;
     169    }
     170
     171    /**
     172     * Unsupported.
     173     * @param key ignored
     174     * @throws UnsupportedOperationException
     175     */
     176    @Override
     177    public void remove(String key) {
     178        throw new UnsupportedOperationException();
     179    }
     180
     181    @Override
     182    public boolean hasKeys() {
     183        return true;
     184    }
     185
     186    @Override
     187    public Collection<String> keySet() {
     188        return Collections.singleton(key);
     189    }
     190
     191    /**
     192     * Unsupported.
     193     * @throws UnsupportedOperationException
     194     */
     195    @Override
     196    public void removeAll() {
     197        throw new UnsupportedOperationException();
     198    }
    133199}
Note: See TracChangeset for help on using the changeset viewer.