Revision 44844 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.dbf/src/main/java/org/gvsig/fmap/dal/store/dbf/utils/DbaseFieldDescriptor.java
DbaseFieldDescriptor.java | ||
---|---|---|
33 | 33 |
* Class for holding the information assicated with a record. |
34 | 34 |
*/ |
35 | 35 |
public class DbaseFieldDescriptor { |
36 |
|
|
36 |
|
|
37 | 37 |
private static final Logger LOGGER = LoggerFactory.getLogger(DbaseFieldDescriptor.class); |
38 | 38 |
|
39 | 39 |
public static final char DBFTYPE_STRING = 'C'; |
... | ... | |
50 | 50 |
// Field Name |
51 | 51 |
private String name; |
52 | 52 |
private String name_trim; |
53 |
|
|
53 |
|
|
54 | 54 |
// Field Type (C N L D F or M) |
55 | 55 |
private char type; |
56 | 56 |
// Field Data Address offset from the start of the record. |
... | ... | |
66 | 66 |
} |
67 | 67 |
|
68 | 68 |
public int getSize() { |
69 |
switch (this.getType()) { |
|
70 |
case DBFTYPE_FLOAT: |
|
71 |
case DBFTYPE_NUMBER: |
|
72 |
if( this.scale < 1 ) { |
|
73 |
return this.precision+1; // -XXX |
|
74 |
} else { |
|
75 |
return this.precision+3; // -0.XXX |
|
76 |
} |
|
77 |
} |
|
78 | 69 |
return this.size; |
79 | 70 |
} |
80 | 71 |
|
... | ... | |
83 | 74 |
} |
84 | 75 |
|
85 | 76 |
public int getPrecision() { |
86 |
return this.precision; |
|
77 |
switch (this.getType()) { |
|
78 |
case DBFTYPE_FLOAT: |
|
79 |
case DBFTYPE_NUMBER: |
|
80 |
if (this.scale < 1) { |
|
81 |
return this.size; // -XXX (ignoramos el signo) |
|
82 |
} else { |
|
83 |
return this.size - 2; // -0.XXX (ignoramos el signo) |
|
84 |
} |
|
85 |
} |
|
86 |
return 0; |
|
87 | 87 |
} |
88 | 88 |
|
89 | 89 |
public char getType() { |
... | ... | |
107 | 107 |
} |
108 | 108 |
|
109 | 109 |
public void setType(char type) throws AttributeFeatureTypeNotSuportedException { |
110 |
switch(type) { |
|
110 |
switch (type) {
|
|
111 | 111 |
case DBFTYPE_NUMBER: |
112 | 112 |
case DBFTYPE_FLOAT: |
113 | 113 |
case DBFTYPE_STRING: |
... | ... | |
115 | 115 |
case DBFTYPE_BOOLEAN: |
116 | 116 |
this.type = type; |
117 | 117 |
break; |
118 |
case 'c':
|
|
118 |
case 'c': |
|
119 | 119 |
this.type = DBFTYPE_STRING; |
120 | 120 |
break; |
121 |
case 'S':
|
|
122 |
case 's':
|
|
123 |
warn("Field type for " + name + " set to S which is flat out wrong people!, I am setting this to C, in the hopes you meant character.");
|
|
121 |
case 'S': |
|
122 |
case 's': |
|
123 |
warn("Field type for " + name + " set to S which is flat out wrong people!, I am setting this to C, in the hopes you meant character."); |
|
124 | 124 |
this.type = DBFTYPE_STRING; |
125 | 125 |
break; |
126 |
case 'd':
|
|
126 |
case 'd': |
|
127 | 127 |
this.type = DBFTYPE_DATE; |
128 | 128 |
break; |
129 |
case 'f':
|
|
129 |
case 'f': |
|
130 | 130 |
this.type = DBFTYPE_FLOAT; |
131 | 131 |
break; |
132 | 132 |
case 'n': |
... | ... | |
136 | 136 |
this.type = DBFTYPE_BOOLEAN; |
137 | 137 |
break; |
138 | 138 |
default: |
139 |
throw new AttributeFeatureTypeNotSuportedException(name, type, "unknown", "DBF");
|
|
139 |
throw new AttributeFeatureTypeNotSuportedException(name, type, "unknown", "DBF"); |
|
140 | 140 |
} |
141 | 141 |
} |
142 | 142 |
|
... | ... | |
145 | 145 |
} |
146 | 146 |
|
147 | 147 |
public void setSize(int size) { |
148 |
switch(this.getType()) { |
|
148 |
switch (this.getType()) {
|
|
149 | 149 |
case DBFTYPE_FLOAT: |
150 | 150 |
case DBFTYPE_NUMBER: |
151 | 151 |
this.size = size; |
152 | 152 |
break; |
153 |
|
|
153 |
|
|
154 | 154 |
case DBFTYPE_STRING: |
155 | 155 |
if (size > 254) { |
156 |
warn("Field Length for " + this.name + " set to " + size + " Which is longer than 254, not consistent with dbase III");
|
|
156 |
warn("Field Length for " + this.name + " set to " + size + " Which is longer than 254, not consistent with dbase III"); |
|
157 | 157 |
} |
158 | 158 |
this.size = size; |
159 | 159 |
break; |
... | ... | |
169 | 169 |
} |
170 | 170 |
|
171 | 171 |
public void setScale(int scale) { |
172 |
switch(this.getType()) { |
|
172 |
switch (this.getType()) {
|
|
173 | 173 |
case DBFTYPE_FLOAT: |
174 | 174 |
case DBFTYPE_NUMBER: |
175 | 175 |
this.scale = scale; |
... | ... | |
178 | 178 |
this.scale = 0; |
179 | 179 |
} |
180 | 180 |
} |
181 |
|
|
182 |
public void calculateScaleAndPrecission() { |
|
183 |
switch(this.getType()) { |
|
184 |
case DBFTYPE_FLOAT: |
|
185 |
case DBFTYPE_NUMBER: |
|
186 |
if( this.size>0 ) { |
|
187 |
if( this.scale<1 ) { |
|
188 |
this.precision = this.size -1; |
|
189 |
} else { |
|
190 |
this.precision = this.size -3; |
|
191 |
} |
|
192 |
this.size = 0; |
|
193 |
} |
|
194 |
break; |
|
195 |
default: |
|
196 |
this.scale = 0; |
|
197 |
} |
|
198 |
} |
|
199 | 181 |
|
200 |
public void setPrecision(int precision) { |
|
201 |
switch(this.getType()) { |
|
202 |
case DBFTYPE_FLOAT: |
|
203 |
case DBFTYPE_NUMBER: |
|
204 |
if( precision>250 ) { |
|
205 |
this.precision = 250; |
|
206 |
} else { |
|
207 |
this.precision = precision; |
|
208 |
} |
|
209 |
break; |
|
210 |
default: |
|
211 |
this.precision = 0; |
|
212 |
} |
|
213 |
} |
|
182 |
// public void calculateScaleAndPrecission() { |
|
183 |
// switch (this.getType()) { |
|
184 |
// case DBFTYPE_FLOAT: |
|
185 |
// case DBFTYPE_NUMBER: |
|
186 |
// if (this.size > 0) { |
|
187 |
// if (this.scale < 1) { |
|
188 |
// this.precision = this.size - 1; |
|
189 |
// } else { |
|
190 |
// this.precision = this.size - 3; |
|
191 |
// } |
|
192 |
// } |
|
193 |
// break; |
|
194 |
// default: |
|
195 |
// this.scale = 0; |
|
196 |
// } |
|
197 |
// } |
|
198 |
// |
|
199 |
// public void setPrecision(int precision) { |
|
200 |
// switch (this.getType()) { |
|
201 |
// case DBFTYPE_FLOAT: |
|
202 |
// case DBFTYPE_NUMBER: |
|
203 |
// if (precision > 250) { |
|
204 |
// this.precision = 250; |
|
205 |
// } else { |
|
206 |
// this.precision = precision; |
|
207 |
// } |
|
208 |
// break; |
|
209 |
// default: |
|
210 |
// this.precision = 0; |
|
211 |
// } |
|
212 |
// } |
|
214 | 213 |
|
215 | 214 |
private void warn(String msg) { |
216 |
LOGGER.warn(msg);
|
|
215 |
LOGGER.warn(msg); |
|
217 | 216 |
} |
218 | 217 |
} |
Also available in: Unified diff