source: osm/applications/editors/josm/plugins/opendata/includes/org/geotools/feature/type/PropertyDescriptorImpl.java@ 28000

Last change on this file since 28000 was 28000, checked in by donvip, 12 years ago

Import new "opendata" JOSM plugin

File size: 3.9 KB
Line 
1/*
2 * GeoTools - The Open Source Java GIS Toolkit
3 * http://geotools.org
4 *
5 * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation;
10 * version 2.1 of the License.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 */
17package org.geotools.feature.type;
18
19import java.util.HashMap;
20import java.util.Map;
21
22import org.geotools.resources.Classes;
23import org.geotools.util.Utilities;
24import org.opengis.feature.type.Name;
25import org.opengis.feature.type.PropertyDescriptor;
26import org.opengis.feature.type.PropertyType;
27
28public class PropertyDescriptorImpl implements PropertyDescriptor {
29
30 final protected PropertyType type;
31 final protected Name name;
32 final protected int minOccurs;
33 final protected int maxOccurs;
34 final protected boolean isNillable;
35 final Map<Object, Object> userData;
36
37 protected PropertyDescriptorImpl(PropertyType type, Name name, int min, int max, boolean isNillable) {
38 this.type = type;
39 this.name = name;
40 this.minOccurs = min;
41 this.maxOccurs = max;
42 this.isNillable = isNillable;
43 userData = new HashMap();
44
45 if ( type == null ) {
46 throw new NullPointerException("type");
47 }
48
49 if ( name == null ) {
50 throw new NullPointerException("name");
51 }
52
53 if (max > 0 && (max < min) ) {
54 throw new IllegalArgumentException("max must be -1, or < min");
55 }
56 }
57
58 public PropertyType getType() {
59 return type;
60 }
61
62 public Name getName() {
63 return name;
64 }
65
66 public int getMinOccurs() {
67 return minOccurs;
68 }
69
70 public int getMaxOccurs() {
71 return maxOccurs;
72 }
73
74 public boolean isNillable() {
75 return isNillable;
76 }
77
78 public Map<Object, Object> getUserData() {
79 return userData;
80 }
81
82 public boolean equals(Object obj) {
83 if (!(obj instanceof PropertyDescriptorImpl)) {
84 return false;
85 }
86
87 PropertyDescriptorImpl other = (PropertyDescriptorImpl) obj;
88 return Utilities.equals(type,other.type) &&
89 Utilities.equals(name,other.name) &&
90 (minOccurs == other.minOccurs) && (maxOccurs == other.maxOccurs) &&
91 (isNillable == other.isNillable);
92 }
93
94 public int hashCode() {
95 return (37 * minOccurs + 37 * maxOccurs ) ^ type.hashCode() ^ name.hashCode();
96 }
97
98 public String toString() {
99 StringBuffer sb = new StringBuffer(Classes.getShortClassName(this));
100 sb.append(" ");
101 sb.append( getName() );
102 if( type != null ){
103 sb.append( " <" );
104 sb.append( type.getName().getLocalPart() );
105 sb.append(":");
106 sb.append( Classes.getShortName( type.getBinding() ));
107 sb.append( ">" );
108 }
109 if( isNillable ){
110 sb.append( " nillable" );
111 }
112 if( minOccurs == 1 && maxOccurs == 1 ){
113 // ignore the 1:1
114 }
115 else {
116 sb.append( " " );
117 sb.append( minOccurs );
118 sb.append( ":" );
119 sb.append( maxOccurs );
120 }
121 if( userData != null && !userData.isEmpty() ){
122 sb.append("\nuserData=(");
123 for( Map.Entry entry : userData.entrySet() ){
124 sb.append("\n\t");
125 sb.append( entry.getKey() );
126 sb.append( " ==> " );
127 sb.append( entry.getValue() );
128 }
129 sb.append(")");
130 }
131 return sb.toString();
132 }
133
134}
Note: See TracBrowser for help on using the repository browser.