view geo-backend/src/main/java/de/intevation/gnv/geobackend/base/DefaultResult.java @ 891:a277ebde74e4

Added more JavaDoc geo-backend/trunk@917 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 13 Apr 2010 11:28:47 +0000
parents e5e30090c37c
children ebeb56428409
line wrap: on
line source
package de.intevation.gnv.geobackend.base;

import java.util.Date;
import java.util.GregorianCalendar;

import de.intevation.gnv.geobackend.util.DateUtils;

/**
 * Defaultimplementation of the Interface Result.
 * This Class stores the Attributevalues of one Result.
 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
 *
 */
public class DefaultResult
implements   Result
{
    /**
     * THE UID of this Classe
     */
    private static final long serialVersionUID = -6886218808840982766L;
    /**
     * Array which stores the Columnvalues
     */
     private Object [] values;
    /**
     * The ResultDescriptor which describes the ColumnValues
     */
    private ResultDescriptor resultDescriptor = null;

    /**
     * Constructor
     */
    public DefaultResult(ResultDescriptor resultDescriptor) {
        this.resultDescriptor = resultDescriptor;
        values = new Object[resultDescriptor.getColumnCount()];
    }

    /**
     * @see de.intevation.gnv.geobackend.base.Result#getDate(java.lang.String)
     */
    public Date getDate(String columnName) {
        return getDate(resultDescriptor.getColumnIndex(columnName));
    }

    /**
     * @see de.intevation.gnv.geobackend.base.Result#getDate(int)
     */
    public Date getDate(int column) {
        Object o = values[column];
        Date d = null;
        if(o instanceof Date){
            d = (Date)o;
        }else if (o instanceof GregorianCalendar){
            d = ((GregorianCalendar)o).getTime();
        }
        return d;
    }

    /**
     * @see de.intevation.gnv.geobackend.base.Result#getDouble(java.lang.String)
     */
    public Double getDouble(String columnName) {
        return getDouble(resultDescriptor.getColumnIndex(columnName));
    }

    /**
     * @see de.intevation.gnv.geobackend.base.Result#getDouble(int)
     */
    public Double getDouble(int column) {
        return (Double)values[column];
    }

    /**
     * @see de.intevation.gnv.geobackend.base.Result#getFloat(java.lang.String)
     */
    public Float getFloat(String columnName) {
        return getFloat(resultDescriptor.getColumnIndex(columnName));
    }

    /**
     * @see de.intevation.gnv.geobackend.base.Result#getFloat(int)
     */
    public Float getFloat(int column) {
        return (Float)values[column];
    }

    /**
     * @see de.intevation.gnv.geobackend.base.Result#getInteger(java.lang.String)
     */
    public Integer getInteger(String columnName) {
        int idx = resultDescriptor.getColumnIndex(columnName);
        return idx > -1 ? getInteger(idx) : -1;
    }

    /**
     * @see de.intevation.gnv.geobackend.base.Result#getInteger(int)
     */
    public Integer getInteger(int column) {
        Object value = values[column];
        if (value instanceof Double){
            value = new Integer(((Double)value).intValue());
        }
        return (Integer)value;
    }

    /**
     * @see de.intevation.gnv.geobackend.base.Result#getResultDescriptor()
     */
    public ResultDescriptor getResultDescriptor() {
        return this.resultDescriptor;
    }

    /**
     * @see de.intevation.gnv.geobackend.base.Result#getString(java.lang.String)
     */
    public String getString(String columnName) {
        int idx = resultDescriptor.getColumnIndex(columnName);
        return idx > -1 ? getString(idx) : null;
    }

    /**
     * @see de.intevation.gnv.geobackend.base.Result#getString(int)
     */
    public String getString(int column) {
        Object o = values[column];
        if (o instanceof Date){
            return DateUtils.getPatternedDateAmer((Date)o);
        }
        if (o instanceof GregorianCalendar){
            Date d = ((GregorianCalendar)o).getTime();
            return DateUtils.getPatternedDateAmer(d);
        }
        return o != null ? o.toString() : null;
    }

    /**
     * @see de.intevation.gnv.geobackend.base.Result#addColumnValue(int, java.lang.Object)
     */
    public void addColumnValue(int column, Object value) {
        values[column] = value;
    }

    /**
     * @see de.intevation.gnv.geobackend.base.Result#getObject(java.lang.String)
     */
    public Object getObject(String columnName) {
        return getObject(resultDescriptor.getColumnIndex(columnName));
    }

    /**
     * @see de.intevation.gnv.geobackend.base.Result#getObject(int)
     */
    public Object getObject(int column) {
        return values[column];
    }

}

http://dive4elements.wald.intevation.org