org.simpleflatmapper.map.context.impl.NullChecker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-map Show documentation
Show all versions of sfm-map Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.simpleflatmapper.map.context.impl;
import org.simpleflatmapper.map.context.KeyAndPredicate;
import org.simpleflatmapper.map.context.KeySourceGetter;
import org.simpleflatmapper.util.ErrorHelper;
import org.simpleflatmapper.util.Predicate;
import java.util.List;
public class NullChecker implements Predicate {
private final List> keys;
private final KeySourceGetter keySourceGetter;
public NullChecker(List> keys, KeySourceGetter keySourceGetter) {
this.keys = keys;
this.keySourceGetter = keySourceGetter;
}
@Override
public boolean test(S s) {
try {
boolean empty = true;
for (KeyAndPredicate keyAndPredicate : keys) {
if (keyAndPredicate.test(s)) {
empty = false;
if (keySourceGetter.getValue(keyAndPredicate.key, s) != null) {
return false;
}
}
}
return !empty;
} catch (Exception e) {
ErrorHelper.rethrow(e);
throw new IllegalStateException();
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NullChecker, ?> that = (NullChecker, ?>) o;
if (keys != null ? !keys.equals(that.keys) : that.keys != null) return false;
return keySourceGetter != null ? keySourceGetter.equals(that.keySourceGetter) : that.keySourceGetter == null;
}
@Override
public int hashCode() {
int result = keys != null ? keys.hashCode() : 0;
result = 31 * result + (keySourceGetter != null ? keySourceGetter.hashCode() : 0);
return result;
}
}