-
Notifications
You must be signed in to change notification settings - Fork 982
/
ValidationPreferences.java
144 lines (118 loc) · 4.5 KB
/
ValidationPreferences.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package org.nocrala.tools.gis.data.esri.shapefile;
import org.nocrala.tools.gis.data.esri.shapefile.shape.PartType;
import org.nocrala.tools.gis.data.esri.shapefile.shape.ShapeType;
/**
* This class allows the client to relax the level of validation when reading a
* shape file. When instantiated, all validations are turned on by default, so
* the client can specifically turn off the required ones.
*/
public class ValidationPreferences {
private static final int DEFAULT_MAX_NUMBER_OF_POINTS_PER_SHAPE = 10000;
private int expectedRecordNumber = 0;
private ShapeType forceShapeType = null;
private boolean allowBadRecordNumbers = false;
private boolean allowBadContentLength = false;
private boolean allowMultipleShapeTypes = false;
private boolean allowUnlimitedNumberOfPointsPerShape = false;
private int maxNumberOfPointsPerShape = DEFAULT_MAX_NUMBER_OF_POINTS_PER_SHAPE;
private PartType forcePartType = null;
// Logic
void advanceOneRecordNumber() {
this.expectedRecordNumber++;
}
public int getExpectedRecordNumber() {
return expectedRecordNumber;
}
// Accessors
public PartType getForcePartType() {
return forcePartType;
}
/**
* Forces the part types to a specific type, disabling its validation. Set
* this value to null to enable the validation. Defaults to null.
*
* @param forcePartType
*/
public void setForcePartType(PartType forcePartType) {
this.forcePartType = forcePartType;
}
public ShapeType getForceShapeType() {
return forceShapeType;
}
/**
* Forces the shape type to a specific type, disabling its validation. Set
* this value to null to enable the validation. Defaults to null.
*
* @param forceShapeType
*/
public void setForceShapeType(ShapeType forceShapeType) {
this.forceShapeType = forceShapeType;
}
public boolean isAllowBadRecordNumbers() {
return allowBadRecordNumbers;
}
/**
* Inhibits the validation of the record numbers; a correct shape file must
* have sequential record numbers, starting at 1. Defaults to false.
*
* @param allowBadRecordNumbers
*/
public void setAllowBadRecordNumbers(boolean allowBadRecordNumbers) {
this.allowBadRecordNumbers = allowBadRecordNumbers;
}
public boolean isAllowMultipleShapeTypes() {
return allowMultipleShapeTypes;
}
/**
* Allows shapes of multiple types in the file; in a correct shape file all
* shapes must be of a single type, specified on the header of the file.
* Defaults to false.
*
* @param allowMultipleShapeTypes
*/
public void setAllowMultipleShapeTypes(boolean allowMultipleShapeTypes) {
this.allowMultipleShapeTypes = allowMultipleShapeTypes;
}
public boolean isAllowBadContentLength() {
return allowBadContentLength;
}
/**
* Inhibits the validation of the content length of each shape. Defaults to
* false.
*
* @param allowBadContentLength
*/
public void setAllowBadContentLength(boolean allowBadContentLength) {
this.allowBadContentLength = allowBadContentLength;
}
public boolean isAllowUnlimitedNumberOfPointsPerShape() {
return allowUnlimitedNumberOfPointsPerShape;
}
/**
* Allows any (positive) number of points per shape. It's strongly advised to
* always limit the number of points per shape; otherwise, a corrupt file with
* a gigantic (garbage) number of points may crash the reader with an
* OutOfMemory error. Defaults to false, with a default limit of 10000.
*
* @param allowUnlimitedNumberOfPointsPerShape
*/
public void setAllowUnlimitedNumberOfPointsPerShape(
boolean allowUnlimitedNumberOfPointsPerShape) {
this.allowUnlimitedNumberOfPointsPerShape = allowUnlimitedNumberOfPointsPerShape;
}
public int getMaxNumberOfPointsPerShape() {
return maxNumberOfPointsPerShape;
}
/**
* Specifies the maximum number of points a shape can have. If a shape is
* found with a larger number of points a exception is thrown showing the
* number of points it has. This parameter can be adjusted for different
* files, or turned off with the method
* setAllowUnlimitedNumberOfPointsPerShape(). Defaults to 10000.
*
* @param maxItems
*/
public void setMaxNumberOfPointsPerShape(int maxItems) {
this.maxNumberOfPointsPerShape = maxItems;
}
}