2016-02-02 03:20:14 +01:00
|
|
|
/*
|
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
|
2019-10-22 23:19:51 +02:00
|
|
|
Copyright (c) 2015-2019 javafx.ninja <info@javafx.ninja>
|
2016-02-02 03:20:14 +01:00
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
2016-09-12 04:48:22 +02:00
|
|
|
package ninja.javafx.smartcsv.validation.configuration;
|
2016-02-02 03:20:14 +01:00
|
|
|
|
|
|
|
|
import com.google.gson.annotations.SerializedName;
|
|
|
|
|
|
2016-09-01 00:01:13 +02:00
|
|
|
import java.util.ArrayList;
|
2016-02-02 03:20:14 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
2016-09-18 14:17:39 +02:00
|
|
|
* Configuration based on JSON Table Schema
|
|
|
|
|
* @see <a href="http://specs.frictionlessdata.io/json-table-schema/">JSON Table Schema</a>
|
2016-02-02 03:20:14 +01:00
|
|
|
*/
|
|
|
|
|
public class ValidationConfiguration {
|
|
|
|
|
|
2016-09-01 00:01:13 +02:00
|
|
|
@SerializedName("fields")
|
2016-09-18 14:17:39 +02:00
|
|
|
private Field[] fields;
|
2016-02-02 03:20:14 +01:00
|
|
|
|
2016-09-18 14:17:39 +02:00
|
|
|
public Field[] getFields() {
|
|
|
|
|
return fields;
|
2016-02-05 08:00:32 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-18 14:17:39 +02:00
|
|
|
public void setFields(Field[] fields) {
|
|
|
|
|
this.fields = fields;
|
2016-02-05 08:00:32 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-18 14:17:39 +02:00
|
|
|
public Field getFieldConfiguration(String column) {
|
|
|
|
|
for (Field field : fields) {
|
|
|
|
|
if (field.getName().equals(column)) {
|
|
|
|
|
return field;
|
2016-09-01 22:05:31 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-01 00:01:13 +02:00
|
|
|
public String[] headerNames() {
|
2016-09-18 14:17:39 +02:00
|
|
|
if (fields != null) {
|
2016-09-01 00:01:13 +02:00
|
|
|
List<String> headerNames = new ArrayList<>();
|
2016-09-18 14:17:39 +02:00
|
|
|
for (Field field : fields) {
|
|
|
|
|
headerNames.add(field.getName());
|
2016-08-06 21:41:14 +02:00
|
|
|
}
|
2016-09-01 00:01:13 +02:00
|
|
|
return headerNames.toArray(new String[headerNames.size()]);
|
2016-08-06 21:41:14 +02:00
|
|
|
}
|
2016-02-02 03:20:14 +01:00
|
|
|
|
2016-09-01 00:01:13 +02:00
|
|
|
return null;
|
2016-02-02 03:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-01 00:01:13 +02:00
|
|
|
public void setHeaderNames(String[] header) {
|
2016-09-18 14:17:39 +02:00
|
|
|
fields = new Field[header.length];
|
2016-09-01 00:01:13 +02:00
|
|
|
int i = 0;
|
|
|
|
|
for (String headerName: header) {
|
2016-09-18 14:17:39 +02:00
|
|
|
fields[i] = new Field();
|
|
|
|
|
fields[i].setName(headerName);
|
2016-09-01 00:01:13 +02:00
|
|
|
i++;
|
|
|
|
|
}
|
2016-02-02 03:20:14 +01:00
|
|
|
}
|
|
|
|
|
}
|