mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 13:38:23 +02:00
30 lines
824 B
Java
30 lines
824 B
Java
|
|
package ninja.javafx.smartcsv.validation;
|
||
|
|
|
||
|
|
import java.util.HashMap;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Created by abi on 07.08.2016.
|
||
|
|
*/
|
||
|
|
public class UniqueValidation implements Validation {
|
||
|
|
|
||
|
|
private HashMap<String, Integer> columnValueMap = new HashMap<>();
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void check(int row, String value, ValidationError error) {
|
||
|
|
Integer valueInLineNumber = columnValueMap.get(value);
|
||
|
|
if (valueInLineNumber != null) {
|
||
|
|
if (!valueInLineNumber.equals(row)) {
|
||
|
|
valueInLineNumber += 1; // show not 0 based line numbers to user
|
||
|
|
error.add("validation.message.uniqueness", value, valueInLineNumber.toString());
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
columnValueMap.put(value, row);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public Type getType() {
|
||
|
|
return Type.UNIQUE;
|
||
|
|
}
|
||
|
|
}
|