1
2
3
4
5
6
7
8
9
10
11 package org.csveed.bean;
12
13 import java.beans.PropertyDescriptor;
14 import java.lang.reflect.Field;
15
16 import org.csveed.bean.conversion.Converter;
17
18
19
20
21 public class BeanProperty {
22
23
24 private PropertyDescriptor propertyDescriptor;
25
26
27 private Field field;
28
29
30 private Converter converter;
31
32
33 private String columnName;
34
35
36 private int columnIndex = -1;
37
38
39 private boolean required;
40
41
42 private boolean dynamicColumnProperty;
43
44
45
46
47
48
49 @SuppressWarnings("unchecked")
50 public Class<? extends Number> getNumberClass() {
51 if (Number.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
52 return (Class<? extends Number>) propertyDescriptor.getPropertyType();
53 }
54 return null;
55 }
56
57
58
59
60
61
62 public PropertyDescriptor getPropertyDescriptor() {
63 return propertyDescriptor;
64 }
65
66
67
68
69
70
71
72 public void setPropertyDescriptor(PropertyDescriptor propertyDescriptor) {
73 this.propertyDescriptor = propertyDescriptor;
74 }
75
76
77
78
79
80
81 public Converter getConverter() {
82 return converter;
83 }
84
85
86
87
88
89
90
91 public void setConverter(Converter converter) {
92 this.converter = converter;
93 }
94
95
96
97
98
99
100 public String getColumnName() {
101 return columnName;
102 }
103
104
105
106
107
108
109
110 public void setColumnName(String columnName) {
111 this.columnName = columnName;
112 }
113
114
115
116
117
118
119 public boolean isRequired() {
120 return required;
121 }
122
123
124
125
126
127
128
129 public void setRequired(boolean required) {
130 this.required = required;
131 }
132
133
134
135
136
137
138 public int getColumnIndex() {
139 return columnIndex;
140 }
141
142
143
144
145
146
147
148 public void setColumnIndex(int columnIndex) {
149 this.columnIndex = columnIndex;
150 }
151
152
153
154
155
156
157 public Field getField() {
158 return field;
159 }
160
161
162
163
164
165
166
167 public void setField(Field field) {
168 this.field = field;
169 }
170
171
172
173
174
175
176 public String getPropertyName() {
177 return propertyDescriptor.getName();
178 }
179
180
181
182
183
184
185
186 public void setDynamicColumnProperty(boolean dynamicColumnProperty) {
187 this.dynamicColumnProperty = dynamicColumnProperty;
188 }
189
190
191
192
193
194
195 public boolean isDynamicColumnProperty() {
196 return this.dynamicColumnProperty;
197 }
198
199 @Override
200 public int hashCode() {
201 return getPropertyName().hashCode();
202 }
203
204 @Override
205 public boolean equals(Object obj) {
206 if (!(obj instanceof BeanProperty)) {
207 return false;
208 }
209 BeanProperty other = (BeanProperty) obj;
210 return getPropertyName().equals(other.getPropertyName());
211 }
212
213
214
215
216
217
218 public String getPropertyType() {
219 return getConverter() != null ? getConverter().infoOnType()
220 : getPropertyDescriptor().getPropertyType().getName();
221 }
222
223 }