All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.graph_builder.module.shapefile.NullBooleanConverter Maven / Gradle / Ivy

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 - 2024 Weber Informatics LLC | Privacy Policy