Revision 2088 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/DefaultDataType.java

View differences:

DefaultDataType.java
66 66
    }
67 67
  }
68 68

  
69
  public static final int NO_SUPPORT_SCALE = -1;
70
  public static final int NO_SUPPORT_PRECISION = -1;
71
  
72
  private static final NumberPrecisionAndScale EMPTY_PRECISION_AND_SCALE = new DefaultNumberPrecisionAndScale(0, 0);
69
  private static final NumberPrecisionAndScale EMPTY_PRECISION_AND_SCALE = new DefaultNumberPrecisionAndScale(PRECISION_NONE, SCALE_NONE);
73 70

  
74 71
  private Coercion coercion;
75 72
  private Class defaultClass;
......
80 77
  private int max_precision;
81 78
  private int default_precision;
82 79
  private int default_scale;
83
  private boolean predefinedPrecision;
80
  private int flags;
84 81

  
85 82
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion) {
86 83
    this(type, subtype, name, defaultClass, coercion, "datatype-any");
87 84
  }
88 85

  
89 86
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName) {
90
    this(type, subtype, name, defaultClass, coercion, "datatype-any", false, NO_SUPPORT_PRECISION, NO_SUPPORT_PRECISION, NO_SUPPORT_SCALE);
87
    this(type, subtype, name, defaultClass, coercion, "datatype-any", 0, PRECISION_NONE, PRECISION_NONE, SCALE_NONE);
91 88
  }
92 89

  
93
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName, boolean isFixedPrecision, int max_precision, int default_precision) {
94
    this(type, subtype, name, defaultClass, coercion, "datatype-any", isFixedPrecision, max_precision, default_precision, NO_SUPPORT_SCALE);
90
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName, int psflag, int max_precision, int default_precision) {
91
    this(type, subtype, name, defaultClass, coercion, "datatype-any", psflag, max_precision, default_precision, SCALE_NONE);
95 92
  }
96 93

  
97
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName, boolean isFixedPrecision, int max_precision, int default_precision, int default_scale) {
94
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName, int flags, int max_precision, int default_precision, int default_scale) {
98 95

  
99 96
    if (name == null) {
100 97
      LOG.trace("Can't register null type name for type {}.", new Object[]{Integer.toHexString(type).toUpperCase()});
......
106 103
    this.defaultClass = defaultClass;
107 104
    this.coercion = coercion;
108 105
    this.iconName = iconName == null ? "datatype-any" : iconName;
109
    this.max_precision = max_precision;
110
    this.default_precision = default_precision;
111
    this.default_scale = default_scale;
112
    this.predefinedPrecision = isFixedPrecision;
106
    
107
    this.flags = flags;
108
    if( (this.flags&FLAG_FLOATING_POINT)==FLAG_FLOATING_POINT ) {
109
      this.flags |= FLAG_NUMBER;
110
    }
111
    if( (this.flags&FLAG_SUPPORT_PRECISION)==FLAG_SUPPORT_PRECISION ) {
112
      this.max_precision = max_precision;
113
      if( this.default_precision>max_precision ) {
114
        this.default_precision = max_precision;
115
      } else {
116
        this.default_precision = default_precision;
117
      }
118
      if( (this.flags&FLAG_SUPPORT_SCALE)==FLAG_SUPPORT_SCALE ) {
119
        if( this.default_scale>this.max_precision ) {
120
          this.default_scale = this.max_precision -1;
121
        } else {
122
          this.default_scale = default_scale;
123
        }
124
      } else {
125
        this.default_scale = SCALE_NONE;
126
      }
127
    } else {
128
      this.max_precision = PRECISION_NONE;
129
      this.default_precision = PRECISION_NONE;
130
      this.default_scale = SCALE_NONE;
131
    }
113 132
  }
114 133

  
115 134
  @Override
......
247 266

  
248 267
  @Override
249 268
  public boolean isNumeric() {
250
    if (type == DataTypes.DOUBLE
251
            || type == DataTypes.FLOAT
252
            || type == DataTypes.BYTE
253
            || type == DataTypes.INT
254
            || type == DataTypes.LONG
255
            || type == DataTypes.DECIMAL) {
256
      return true;
257
    }
258
    return false;
269
    return (this.flags&FLAG_NUMBER) == FLAG_NUMBER;
259 270
  }
260 271

  
261 272
  @Override
262 273
  public boolean supportSize() {
263
    switch (this.type) {
264
      case DataTypes.STRING:
265
      case DataTypes.BYTEARRAY:
266
        return true;
267
      default:
268
        return false;
269
    }
274
    return (this.flags&FLAG_SUPPORT_SIZE) == FLAG_SUPPORT_SIZE;
270 275
  }
271 276

  
272 277
  @Override
273 278
  public boolean supportPrecision() {
274
    return this.max_precision!=NO_SUPPORT_PRECISION;
279
    return (this.flags&FLAG_SUPPORT_PRECISION) == FLAG_SUPPORT_PRECISION;
275 280
  }
276 281

  
277 282
  @Override
278 283
  public boolean supportScale() {
279
    return this.default_scale!=NO_SUPPORT_SCALE;
284
    return (this.flags&FLAG_SUPPORT_SCALE) == FLAG_SUPPORT_SCALE;
280 285
  }
281 286

  
282 287
  @Override
288
  public boolean isPredefinedPrecision() {
289
    return (this.flags&FLAG_PREDEFINED_PRECISION) == FLAG_PREDEFINED_PRECISION ;
290
  }
291

  
292
  @Override
293
  public boolean isFloatingPoint() {
294
    return (this.flags&FLAG_FLOATING_POINT) == FLAG_FLOATING_POINT ;
295
  }
296
  
297
  @Override
298
  public int getFlags() {
299
    return this.flags;
300
  }
301

  
302
  @Override
283 303
  public NumberPrecisionAndScale fixPrecisionAndScale(int precision, int scale) {
284
    if( this.max_precision==NO_SUPPORT_PRECISION ) {
304
    if( (this.flags&FLAG_SUPPORT_PRECISION) != FLAG_SUPPORT_PRECISION ) {
285 305
       return EMPTY_PRECISION_AND_SCALE;
286 306
    }
287 307
    DefaultNumberPrecisionAndScale r = new DefaultNumberPrecisionAndScale(
288 308
            precision, 
289 309
            scale
290 310
    );
291
    if( this.predefinedPrecision ) {
311
    if( (this.flags&FLAG_PREDEFINED_PRECISION) == FLAG_PREDEFINED_PRECISION ) {
292 312
      r.precision = max_precision;
293 313
    }
294
    if( this.default_scale==NO_SUPPORT_SCALE ) {
314
    if( (this.flags&FLAG_SUPPORT_SCALE) != FLAG_SUPPORT_SCALE ) {
295 315
      // Soporta precision y no escala (byte, int, long... enteros)
296 316
      r.scale = 0;
297 317
      if( r.precision > max_precision ) {
298 318
        r.precision = max_precision;
319
      } else if( r.precision < 1 ) {
320
        r.precision = default_precision;
299 321
      }
300 322
    } else {
323
      if( r.scale == SCALE_NONE ) {
324
        r.scale = default_scale;
325
      }
301 326
      // Soporta precision y escala.
302 327
      if (r.precision < 1) {
303 328
        // Sin precision
......
385 410
  public int getDefaultScale() {
386 411
    return this.default_scale;
387 412
  }
388

  
389
  @Override
390
  public boolean isPredefinedPrecision() {
391
    return this.predefinedPrecision;
392
  }
393 413
}

Also available in: Unified diff