001 // License: GPL. 002 package org.openstreetmap.josm.data.gpx; 003 004 import java.util.Collection; 005 import java.util.HashMap; 006 import java.util.Map; 007 008 /** 009 * Base class for various classes in the GPX model. 010 * 011 * @author Frederik Ramm <frederik@remote.org> 012 * @since 444 013 */ 014 public class WithAttributes { 015 016 /** 017 * The "attr" hash is used to store the XML payload (not only XML attributes!) 018 */ 019 public Map<String, Object> attr = new HashMap<String, Object>(0); 020 021 /** 022 * Returns the String value to which the specified key is mapped, 023 * or {@code null} if this map contains no String mapping for the key. 024 * 025 * @param key the key whose associated value is to be returned 026 * @return the String value to which the specified key is mapped, 027 * or {@code null} if this map contains no String mapping for the key 028 */ 029 public String getString(String key) { 030 Object value = attr.get(key); 031 return (value instanceof String) ? (String)value : null; 032 } 033 034 /** 035 * Returns the Collection value to which the specified key is mapped, 036 * or {@code null} if this map contains no Collection mapping for the key. 037 * 038 * @param key the key whose associated value is to be returned 039 * @return the Collection value to which the specified key is mapped, 040 * or {@code null} if this map contains no Collection mapping for the key 041 * @since 5502 042 */ 043 public Collection<?> getCollection(String key) { 044 Object value = attr.get(key); 045 return (value instanceof Collection<?>) ? (Collection<?>)value : null; 046 } 047 }