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 java.io.Serializable;
import org.apache.commons.lang3.StringUtils;
@ConstraintClass("longer") @ConstraintClass("longer")
public class LongerThanConstraints implements Serializable, Selection { public class LongerThanConstraints implements Serializable, Selection {
@ -12,7 +15,8 @@ public class LongerThanConstraints implements Serializable, Selection {
this.param = param; this.param = param;
} }
public LongerThanConstraints(){}; public LongerThanConstraints() {
};
public String getParam() { public String getParam() {
return param; return param;
@ -24,6 +28,10 @@ public class LongerThanConstraints implements Serializable, Selection {
@Override @Override
public boolean apply(String value) { public boolean apply(String value) {
if (StringUtils.isEmpty(value)) {
return false;
}
return value.length() > Integer.valueOf(param); 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; import java.io.Serializable;
@ConstraintClass("shorter") import org.apache.commons.lang3.StringUtils;
@ConstraintClass("shorterorequal")
public class ShorterThanOrEqualToConstraints implements Serializable, Selection { public class ShorterThanOrEqualToConstraints implements Serializable, Selection {
private String param; private String param;
public ShorterThanOrEqualToConstraints(){}; public ShorterThanOrEqualToConstraints() {
};
public ShorterThanOrEqualToConstraints(String param) { public ShorterThanOrEqualToConstraints(String param) {
this.param = param; this.param = param;
@ -24,6 +27,9 @@ public class ShorterThanOrEqualToConstraints implements Serializable, Selection
@Override @Override
public boolean apply(String value) { public boolean apply(String value) {
if (StringUtils.isEmpty(value))
return true;
return value.length() <= Integer.valueOf(param); return value.length() <= Integer.valueOf(param);
} }
} }