001: package org.geotools.feature.iso.type;
002:
003: import java.util.Collections;
004: import java.util.HashMap;
005: import java.util.Map;
006: import java.util.Set;
007:
008: import org.geotools.resources.Utilities;
009: import org.opengis.feature.type.Name;
010: import org.opengis.feature.type.PropertyType;
011: import org.opengis.util.InternationalString;
012:
013: public class PropertyTypeImpl implements PropertyType {
014:
015: protected final Name name;
016: protected final boolean isAbstract;
017: protected final Set restrictions;
018: protected final InternationalString description;
019: protected final Map userData;
020:
021: public PropertyTypeImpl(Name name, boolean isAbstract,
022: Set restrictions, InternationalString description) {
023: if (name == null) {
024: throw new NullPointerException("name");
025: }
026: this .name = name;
027: this .isAbstract = isAbstract;
028: if (restrictions == null) {
029: this .restrictions = restrictions;
030: } else {
031: this .restrictions = Collections
032: .unmodifiableSet(restrictions);
033: }
034: this .description = description;
035: this .userData = new HashMap();
036: }
037:
038: public Name getName() {
039: return name;
040: }
041:
042: public boolean isAbstract() {
043: return isAbstract;
044: }
045:
046: public Set getRestrictions() {
047: return restrictions;
048: }
049:
050: public InternationalString getDescription() {
051: return description;
052: }
053:
054: public String toString() {
055: StringBuffer sb = new StringBuffer(getClass().getName());
056: sb.append("[name=").append(name).append(", abstrsct=, ")
057: .append(isAbstract).append(", restrictions=").append(
058: restrictions).append(", description=").append(
059: description);
060:
061: return sb.toString();
062: }
063:
064: public int hashCode() {
065: return getName().hashCode()
066: ^ (getDescription() != null ? getDescription()
067: .hashCode() : 17);
068: }
069:
070: public boolean equals(Object other) {
071: if (!(other instanceof PropertyType)) {
072: return false;
073: }
074:
075: PropertyType prop = (PropertyType) other;
076: if (!Utilities.equals(name, prop.getName())) {
077: return false;
078: }
079:
080: if (isAbstract != prop.isAbstract()) {
081: return false;
082: }
083:
084: if (!Utilities.equals(restrictions, prop.getRestrictions())) {
085: return false;
086: }
087:
088: if (!Utilities.equals(description, prop.getDescription())) {
089: return false;
090: }
091:
092: return true;
093:
094: }
095:
096: public Object getUserData(Object key) {
097: return userData.get(key);
098: }
099:
100: public void putUserData(Object key, Object value) {
101: if (value == null && userData.containsKey(key)) {
102: userData.remove(key);
103: } else if (value != null) {
104: userData.put(key, value);
105: }
106: }
107: }
|