Revision 44262 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureType.java

View differences:

FeatureType.java
23 23
 */
24 24
package org.gvsig.fmap.dal.feature;
25 25

  
26
import java.util.Comparator;
26 27
import java.util.Iterator;
27 28
import java.util.List;
29
import java.util.function.Predicate;
30
import org.apache.commons.lang3.StringUtils;
28 31

  
29 32
import org.cresques.cts.IProjection;
30 33

  
31 34
import org.gvsig.fmap.geom.Geometry;
35
import org.gvsig.tools.dataTypes.DataType;
36
import org.gvsig.tools.dataTypes.DataTypes;
32 37
import org.gvsig.tools.dynobject.DynClass;
33 38
import org.gvsig.tools.dynobject.DynStruct_v2;
34 39
import org.gvsig.tools.evaluator.Evaluator;
......
36 41

  
37 42
/**
38 43
 * <p>
39
 * This interface provides all the information that describes the structure of
40
 * a type of feature, methods for managing it and also offers a variety of utility
44
 * This interface provides all the information that describes the structure of a
45
 * type of feature, methods for managing it and also offers a variety of utility
41 46
 * methods for simplicity's sake.
42 47
 * </p>
43 48
 *
......
45 50
 * The relevant information that compounds a FeatureType includes:
46 51
 * </p>
47 52
 *
48
 *  <ul>
49
 *  <li> {@link FeatureAttributeDescriptor}(s)
50
 *  <li> {@link FeatureRule}(s)
51
 *  <li> Its size
52
 *  <li> Its SRS(s)
53
 *  <li> Its identifier
54
 *  <li> Whether features of this type have an OID or not (identifier assigned by the store).
53
 * <ul>
54
 * <li> {@link FeatureAttributeDescriptor}(s)
55
 * <li> {@link FeatureRule}(s)
56
 * <li> Its size
57
 * <li> Its SRS(s)
58
 * <li> Its identifier
59
 * <li> Whether features of this type have an OID or not (identifier assigned by
60
 * the store).
55 61
 * </ul>
56 62
 *
57 63
 * <p>
58 64
 * Methods for management include:
59 65
 * </p>
60 66
 *
61
 *  <ul>
62
 *  <li>Obtaining its editable instance.
63
 *  <li>Obtaining an iterator over its attributes.
64
 *  <li>Knowing whether this FeatureType has any associated evaluator for calculated attributes.
65
 *  </ul>
67
 * <ul>
68
 * <li>Obtaining its editable instance.
69
 * <li>Obtaining an iterator over its attributes.
70
 * <li>Knowing whether this FeatureType has any associated evaluator for
71
 * calculated attributes.
72
 * </ul>
66 73
 *
67 74
 * <p>
68 75
 * Utility methods include:
......
76 83
 */
77 84
public interface FeatureType extends DynClass, DynStruct_v2, UnmodifiableBasicList<FeatureAttributeDescriptor> {
78 85

  
79
	/**
80
	 * Returns a new copy of this FeatureType
81
	 *
82
	 * @return
83
	 * 		a new copy of this FeatureType
84
	 */
85
	public FeatureType getCopy();
86
    public static final Predicate<FeatureAttributeDescriptor> BASIC_TYPES_FILTER = new Predicate<FeatureAttributeDescriptor>() {
87
        @Override
88
        public boolean test(FeatureAttributeDescriptor attrdesc) {
89
            DataType t = attrdesc.getDataType();
90
            boolean r = !(t.isContainer() || t.isDynObject() || t.isObject());
91
            return r;
92
        }
93
    };
86 94

  
87
	/**
88
	 * Returns a {@link FeatureRules} containing
89
	 * all rules applicable to features of this type.
90
	 *
91
	 * @return
92
	 * 		a {@link FeatureRules} containing all rules
93
	 * 		applicable to features of this type.
94
	 */
95
	public FeatureRules getRules();
95
    public static Predicate<FeatureAttributeDescriptor> ALL_FILTER = new Predicate<FeatureAttributeDescriptor>() {
96
        @Override
97
        public boolean test(FeatureAttributeDescriptor t) {
98
            return true;
99
        }
100
    };
101
    /**
102
     * Returns a new copy of this FeatureType
103
     *
104
     * @return a new copy of this FeatureType
105
     */
106
    public FeatureType getCopy();
96 107

  
97
	/**
98
	 * Returns an editable instance of this FeatureType.
99
	 * Any modifications on a FeatureType must be done
100
	 * through its editable instance.
101
	 *
102
	 * @return
103
	 * 		the editable instance of this FeatureType.
104
	 *
105
	 * @see EditableFeatureType
106
	 */
107
	public EditableFeatureType getEditable();
108
    /**
109
     * Returns a {@link FeatureRules} containing all rules applicable to
110
     * features of this type.
111
     *
112
     * @return a {@link FeatureRules} containing all rules applicable to
113
     * features of this type.
114
     */
115
    public FeatureRules getRules();
108 116

  
109
	/**
110
	 * Given the name of an attribute, this method returns
111
	 * its position in this FeatureType.
112
	 *
113
	 * @param name
114
	 * 			of the attribute
115
	 * @return
116
	 * 		position of the attribute
117
	 */
118
	public int getIndex(String name);
117
    /**
118
     * Returns an editable instance of this FeatureType. Any modifications on a
119
     * FeatureType must be done through its editable instance.
120
     *
121
     * @return the editable instance of this FeatureType.
122
     *
123
     * @see EditableFeatureType
124
     */
125
    public EditableFeatureType getEditable();
119 126

  
120
	/**
121
	 * Returns an attribute descriptor given its name.
122
	 *
123
	 * @param name
124
	 * 			of the attribute
125
	 * @return
126
	 * 		descriptor of the attribute, a {@link FeatureAttributeDescriptor}.
127
	 */
128
	public Object get(String name);
127
    /**
128
     * Given the name of an attribute, this method returns its position in this
129
     * FeatureType.
130
     *
131
     * @param name of the attribute
132
     * @return position of the attribute
133
     */
134
    public int getIndex(String name);
129 135

  
130
	/**
131
	 * Returns an attribute descriptor given its index
132
	 *
133
	 * @param index
134
	 * 			of the attribute
135
	 *
136
	 * @return
137
	 * 		descriptor of the attribute, a {@link FeatureAttributeDescriptor}
138
	 */
139
	public FeatureAttributeDescriptor get(int index);
136
    /**
137
     * Returns an attribute descriptor given its name.
138
     *
139
     * @param name of the attribute
140
     * @return descriptor of the attribute, a
141
     * {@link FeatureAttributeDescriptor}.
142
     */
143
    public Object get(String name);
140 144

  
141
	/**
142
	 * Returns a {@link FeatureAttributeDescriptor} given the attribute name,
143
	 * or null if an attribute with the given name does not exist.
144
	 *
145
	 * @param name
146
	 * 			of the attribute
147
	 *
148
	 * @return
149
	 * 		a {@link FeatureAttributeDescriptor}
150
	 */
151
	public FeatureAttributeDescriptor getAttributeDescriptor(String name);
145
    /**
146
     * Returns an attribute descriptor given its index
147
     *
148
     * @param index of the attribute
149
     *
150
     * @return descriptor of the attribute, a {@link FeatureAttributeDescriptor}
151
     */
152
    public FeatureAttributeDescriptor get(int index);
152 153

  
153
	/**
154
	 * Returns a {@link FeatureAttributeDescriptor} given the attribute index.
155
	 *
156
	 * @param index
157
	 * 			of the attribute
158
	 *
159
	 * @return
160
	 * 		a {@link FeatureAttributeDescriptor}
161
	 */
162
	public FeatureAttributeDescriptor getAttributeDescriptor(int index);
154
    /**
155
     * Returns a {@link FeatureAttributeDescriptor} given the attribute name, or
156
     * null if an attribute with the given name does not exist.
157
     *
158
     * @param name of the attribute
159
     *
160
     * @return a {@link FeatureAttributeDescriptor}
161
     */
162
    public FeatureAttributeDescriptor getAttributeDescriptor(String name);
163 163

  
164
	/**
165
	 * Returns an iterator over this FeatureType's attributes. Elements
166
	 * returned by this iterator are of type {@link FeatureAttributeDescriptor}.
167
	 *
168
	 * @return
169
	 * 		An iterator over this FeatureType's {@link FeatureAttributeDescriptor}s.
170
	 */
171
	public Iterator iterator();
164
    /**
165
     * Returns a {@link FeatureAttributeDescriptor} given the attribute index.
166
     *
167
     * @param index of the attribute
168
     *
169
     * @return a {@link FeatureAttributeDescriptor}
170
     */
171
    public FeatureAttributeDescriptor getAttributeDescriptor(int index);
172 172

  
173
	/**
174
	 * Returns this FeatureType size. The size of a FeatureType is determined
175
	 * by its number of attributes.
176
	 *
177
	 * @return
178
	 * 		this FeatureType size, defined as the number of attributes it is composed of.
179
	 *
180
	 */
181
	public int size();
182
        
183
        public boolean isEmpty();
173
    /**
174
     * Returns an iterator over this FeatureType's attributes. Elements returned
175
     * by this iterator are of type {@link FeatureAttributeDescriptor}.
176
     *
177
     * @return An iterator over this FeatureType's
178
     * {@link FeatureAttributeDescriptor}s.
179
     */
180
    public Iterator iterator();
184 181

  
185
	/**
186
	 * Returns this FeatureType identifier. This identifier must always be equal
187
	 * to a store.
188
	 *
189
	 * @return the identifier.
190
	 */
191
	public String getId();
182
    /**
183
     * Returns this FeatureType size. The size of a FeatureType is determined by
184
     * its number of attributes.
185
     *
186
     * @return this FeatureType size, defined as the number of attributes it is
187
     * composed of.
188
     *
189
     */
190
    public int size();
192 191

  
193
	/**
194
	 * Returns the name of the attribute that will be used as default
195
	 * geometry attribute for those processes that require a geometry (for
196
	 * instance rendering).
197
	 *
198
	 * @return
199
	 * 		name of the default geometry attribute.
200
	 */
201
	public String getDefaultGeometryAttributeName();
192
    public boolean isEmpty();
202 193

  
203
	/**
204
	 * Returns the index of the attribute that will be used as default
205
	 * geometry attribute.
206
	 *
207
	 * @return
208
	 * 		index of the default geometry attribute.
209
	 */
210
	public int getDefaultGeometryAttributeIndex();
194
    /**
195
     * Returns this FeatureType identifier. This identifier must always be equal
196
     * to a store.
197
     *
198
     * @return the identifier.
199
     */
200
    public String getId();
211 201

  
212
	/**
213
	 * Returns a list with the SRSs in which this FeatureType geometries are
214
	 * expressed. Normally there may be one SRS for each attribute of type
215
	 * {@link Geometry}.
216
	 *
217
	 * @return
218
	 * 		a list with the SRS in which this FeatureType geometries are expressed.
219
	 */
220
	public List getSRSs();
202
    /**
203
     * Returns the name of the attribute that will be used as default geometry
204
     * attribute for those processes that require a geometry (for instance
205
     * rendering).
206
     *
207
     * @return name of the default geometry attribute.
208
     */
209
    public String getDefaultGeometryAttributeName();
221 210

  
222
	/**
223
	 * Returns the SRS in which the default geometry attribute is expressed.
224
	 *
225
	 * @return
226
	 * 		the SRS in which the default geometry attribute is expressed,
227
	 *      null if not has a default geometry attribute.
228
	 */
229
	public IProjection getDefaultSRS();
211
    /**
212
     * Returns the index of the attribute that will be used as default geometry
213
     * attribute.
214
     *
215
     * @return index of the default geometry attribute.
216
     */
217
    public int getDefaultGeometryAttributeIndex();
230 218

  
231
	/**
232
	 * Indicates whether this FeatureType has any assigned {@link Evaluator}(s).
233
	 * Evaluators are used to obtain the values for calculated
234
	 * attributes.
235
	 *
236
	 * @return
237
	 * 		true if this FeatureType has any assigned {@link Evaluator}(s).
238
	 */
239
	public boolean hasEvaluators(); // FIXME: Quitar del interface y dejar en DefaultFeatureType
219
    /**
220
     * Returns a list with the SRSs in which this FeatureType geometries are
221
     * expressed. Normally there may be one SRS for each attribute of type
222
     * {@link Geometry}.
223
     *
224
     * @return a list with the SRS in which this FeatureType geometries are
225
     * expressed.
226
     */
227
    public List getSRSs();
240 228

  
241
	/**
242
	 * Indicates whether {@link Feature}(s) of this FeatureType have an OID defined.
243
	 * An OID is the Feature unique identifier.
244
	 *
245
	 * Some stores provide their own OIDs which are always unique
246
	 * (such as Postgre) while others don't support this concept and
247
	 * then it is the library who creates runtime ad-hoc OIDs as
248
	 * it see fits, but then integrity of this OIDs among different
249
	 * work sessions cannot be guaranteed (this is the case for shape
250
	 * files).
251
	 *
252
	 * @return
253
	 * 		true if this FeatureType has an OID defined, false otherwise.
254
	 *
255
	 */
256
	public boolean hasOID();
229
    /**
230
     * Returns the SRS in which the default geometry attribute is expressed.
231
     *
232
     * @return the SRS in which the default geometry attribute is expressed,
233
     * null if not has a default geometry attribute.
234
     */
235
    public IProjection getDefaultSRS();
257 236

  
258
	/**
259
	 * Incicates if attibutes with automatic values are allowed in the source
260
	 *
261
	 * @return true if source supports this feature, false otherwise
262
	 */
263
	public boolean allowAutomaticValues();
237
    /**
238
     * Indicates whether this FeatureType has any assigned {@link Evaluator}(s).
239
     * Evaluators are used to obtain the values for calculated attributes.
240
     *
241
     * @return true if this FeatureType has any assigned {@link Evaluator}(s).
242
     */
243
    public boolean hasEvaluators(); // FIXME: Quitar del interface y dejar en DefaultFeatureType
264 244

  
265
	/**
266
	 * Returns an Array of the FeatureAttributeDescriptor
267
	 *
268
	 * @return
269
	 */
270
	public FeatureAttributeDescriptor[] getAttributeDescriptors();
245
    /**
246
     * Indicates whether {@link Feature}(s) of this FeatureType have an OID
247
     * defined. An OID is the Feature unique identifier.
248
     *
249
     * Some stores provide their own OIDs which are always unique (such as
250
     * Postgre) while others don't support this concept and then it is the
251
     * library who creates runtime ad-hoc OIDs as it see fits, but then
252
     * integrity of this OIDs among different work sessions cannot be guaranteed
253
     * (this is the case for shape files).
254
     *
255
     * @return true if this FeatureType has an OID defined, false otherwise.
256
     *
257
     */
258
    public boolean hasOID();
271 259

  
272
	/**
273
	 * Returns an Array of the FeatureAttributeDescriptor that compounds the
274
	 * primary key. If not have primary keys return a empty array.
275
	 *
276
	 * @return
277
	 */
278
	public FeatureAttributeDescriptor[] getPrimaryKey();
260
    /**
261
     * Incicates if attibutes with automatic values are allowed in the source
262
     *
263
     * @return true if source supports this feature, false otherwise
264
     */
265
    public boolean allowAutomaticValues();
279 266

  
280
	/**
281
	 * Returns the default geometry FeatureAttributeDescriptor. Return null if
282
	 * it's not set
283
	 *
284
	 * @return
285
	 */
286
	public FeatureAttributeDescriptor getDefaultGeometryAttribute();
287
	
288
	/**
289
     * Returns the default time FeatureAttributeDescriptor. Return null if
290
     * it's not set.
267
    /**
268
     * Returns an Array of the FeatureAttributeDescriptor
291 269
     *
292 270
     * @return
293
     *          the default time attribute
294 271
     */
295
    public FeatureAttributeDescriptor getDefaultTimeAttribute();
272
    public FeatureAttributeDescriptor[] getAttributeDescriptors();
296 273

  
297 274
    /**
298
     * Returns the name of the attribute that will be used as default
299
     * geometry attribute for those processes that require a geometry (for
300
     * instance rendering).
275
     * Returns an Array of the FeatureAttributeDescriptor that compounds the
276
     * primary key. If not have primary keys return a empty array.
301 277
     *
302 278
     * @return
303
     * 		name of the default geometry attribute.
304 279
     */
305
    public String getDefaultTimeAttributeName();
280
    public FeatureAttributeDescriptor[] getPrimaryKey();
306 281

  
307 282
    /**
308
     * Returns the index of the attribute that will be used as default
309
     * geometry attribute.
283
     * Returns the default geometry FeatureAttributeDescriptor. Return null if
284
     * it's not set
310 285
     *
311 286
     * @return
312
     * 		index of the default geometry attribute.
313 287
     */
288
    public FeatureAttributeDescriptor getDefaultGeometryAttribute();
289

  
290
    /**
291
     * Returns the default time FeatureAttributeDescriptor. Return null if it's
292
     * not set.
293
     *
294
     * @return the default time attribute
295
     */
296
    public FeatureAttributeDescriptor getDefaultTimeAttribute();
297

  
298
    /**
299
     * Returns the name of the attribute that will be used as default geometry
300
     * attribute for those processes that require a geometry (for instance
301
     * rendering).
302
     *
303
     * @return name of the default geometry attribute.
304
     */
305
    public String getDefaultTimeAttributeName();
306

  
307
    /**
308
     * Returns the index of the attribute that will be used as default geometry
309
     * attribute.
310
     *
311
     * @return index of the default geometry attribute.
312
     */
314 313
    public int getDefaultTimeAttributeIndex();
315 314

  
316 315
    /**
317 316
     * Return the store associated to this type.
318
     * 
317
     *
319 318
     * @return the FeatureStore of the type.
320 319
     */
321
    public FeatureStore getStore();        
320
    public FeatureStore getStore();
322 321

  
322
    public List<FeatureAttributeDescriptor> getFilteredAttributes(
323
            Predicate<FeatureAttributeDescriptor> filter,
324
            int max
325
    );
326

  
327
    public List<FeatureAttributeDescriptor> getRecentUseds();
328

  
323 329
}

Also available in: Unified diff