001: /*---------------------------------------------------------------------------*\
002: $Id: PersistentMetadataGroup.java 6547 2006-11-03 03:38:55Z bmc $
003: \*---------------------------------------------------------------------------*/
004:
005: package org.clapper.curn;
006:
007: import java.util.Collections;
008: import java.util.HashMap;
009: import java.util.Map;
010:
011: /**
012: * Contains one group of persistent metadata about a feed or an item.
013: * Persistent metadata consists of name/value pairs aggregated into namespaces.
014: * An instance of this class represents one namespace's worth of metadata for
015: * a feed or an item.
016: *
017: * @version <tt>$Revision: 6547 $</tt>
018: */
019: public class PersistentMetadataGroup {
020: /*----------------------------------------------------------------------*\
021: Private Constants
022: \*----------------------------------------------------------------------*/
023:
024: /*----------------------------------------------------------------------*\
025: Private Instance Data
026: \*----------------------------------------------------------------------*/
027:
028: private Map<String, String> nameValuePairs = new HashMap<String, String>();
029: private String namespace = null;
030:
031: /*----------------------------------------------------------------------*\
032: Constructor
033: \*----------------------------------------------------------------------*/
034:
035: /**
036: * Creates a new instance of <tt>PersistentMetadataGroup</tt>.
037: *
038: * @param namespace the namespace for this group
039: */
040: public PersistentMetadataGroup(String namespace) {
041: this .namespace = namespace;
042: }
043:
044: /*----------------------------------------------------------------------*\
045: Public Methods
046: \*----------------------------------------------------------------------*/
047:
048: /**
049: * Get the namespace for this group.
050: *
051: * @return the namespace
052: */
053: public String getNamespace() {
054: return namespace;
055: }
056:
057: /**
058: * Add a name/value pair to this metadata group.
059: *
060: * @param name the name
061: * @param value the value
062: */
063: public void addMetadataItem(String name, String value) {
064: nameValuePairs.put(name, value);
065: }
066:
067: /**
068: * Add an entire map-ful of metadata to this group.
069: *
070: * @param metadata the data
071: */
072: public void addMetadata(Map<String, String> metadata) {
073: this .nameValuePairs.putAll(metadata);
074: }
075:
076: /**
077: * Get the name/value pairs (i.e., the actual data) associated with this
078: * metadata group.
079: *
080: * @return a <tt>Map</tt> of name/value pair data
081: */
082: public Map<String, String> getMetadata() {
083: return Collections.unmodifiableMap(nameValuePairs);
084: }
085:
086: public Map<String, String> getNameValuePairs() {
087: return nameValuePairs;
088: }
089:
090: /**
091: * Get the hash code. Items of this type are hashed by namespace.
092: *
093: * @return the hash code
094: */
095: public int hashCode() {
096: return namespace.hashCode();
097: }
098:
099: /**
100: * Determine whether this object is equivalent to another. A
101: * <tt>PersistentMetadataGroup</tt> object is equivalent to another
102: * only if (a) both objects have the same namespace, and (b) both
103: * objects contain the same data.
104: *
105: * @param o the other object
106: */
107: public boolean equals(Object o) {
108: boolean eq = false;
109:
110: if (o instanceof PersistentMetadataGroup) {
111: PersistentMetadataGroup other = (PersistentMetadataGroup) o;
112:
113: eq = namespace.equals(other.namespace)
114: && nameValuePairs.equals(other.nameValuePairs);
115: }
116:
117: return eq;
118: }
119:
120: /*----------------------------------------------------------------------*\
121: Protected Methods
122: \*----------------------------------------------------------------------*/
123:
124: /*----------------------------------------------------------------------*\
125: Private Methods
126: \*----------------------------------------------------------------------*/
127: }
|