added check for empty(null) values

This commit is contained in:
Miriam Baglioni 2020-11-18 11:58:00 +01:00
parent 457c07a522
commit a708652093
2 changed files with 21 additions and 7 deletions

View File

@ -3,6 +3,9 @@ package eu.dnetlib.dhp.oa.graph.clean.authorpids.constraints;
import java.io.Serializable;
import org.apache.commons.lang3.StringUtils;
@ConstraintClass("longer")
public class LongerThanConstraints implements Serializable, Selection {
@ -12,7 +15,8 @@ public class LongerThanConstraints implements Serializable, Selection {
this.param = param;
}
public LongerThanConstraints(){};
public LongerThanConstraints() {
};
public String getParam() {
return param;
@ -24,6 +28,10 @@ public class LongerThanConstraints implements Serializable, Selection {
@Override
public boolean apply(String value) {
if (StringUtils.isEmpty(value)) {
return false;
}
return value.length() > Integer.valueOf(param);
}
}

View File

@ -3,12 +3,15 @@ package eu.dnetlib.dhp.oa.graph.clean.authorpids.constraints;
import java.io.Serializable;
@ConstraintClass("shorter")
import org.apache.commons.lang3.StringUtils;
@ConstraintClass("shorterorequal")
public class ShorterThanOrEqualToConstraints implements Serializable, Selection {
private String param;
public ShorterThanOrEqualToConstraints(){};
public ShorterThanOrEqualToConstraints() {
};
public ShorterThanOrEqualToConstraints(String param) {
this.param = param;
@ -24,6 +27,9 @@ public class ShorterThanOrEqualToConstraints implements Serializable, Selection
@Override
public boolean apply(String value) {
if (StringUtils.isEmpty(value))
return true;
return value.length() <= Integer.valueOf(param);
}
}