org.opentripplanner.graph_builder.module.shapefile.NullBooleanConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.graph_builder.module.shapefile;
import org.opengis.feature.simple.SimpleFeature;
import org.opentripplanner.graph_builder.services.shapefile.SimpleFeatureConverter;
/**
* A converter which converts null-valued attributes to either true or false (and all others to the other)
*
* @author novalis
*
*/
public class NullBooleanConverter implements SimpleFeatureConverter {
private String attributeName;
private boolean nullIsTrue = false;
public NullBooleanConverter() {
}
public NullBooleanConverter(String attributeName, boolean nullIsTrue) {
this.attributeName = attributeName;
this.nullIsTrue = nullIsTrue;
}
@Override
public Boolean convert(SimpleFeature feature) {
Object value = feature.getAttribute(attributeName);
if (value == null || value.equals("")) {
return nullIsTrue;
} else {
return !nullIsTrue;
}
}
/**
* @param attributeName the attribute name to set
*/
public void setAttributeName(String attributeName) {
this.attributeName = attributeName;
}
/**
* @return the attribute name
*/
public String getAttributeName() {
return attributeName;
}
/**
* @param nullIsTrue whether a null value for this attribue converts to false
*/
public void setNullIsTrue(boolean nullIsTrue) {
this.nullIsTrue = nullIsTrue;
}
/**
* @return whether a null value for this attribute converts to true
*/
public boolean getNullIsTrue() {
return nullIsTrue;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy