ColumnContainer.java :  » Workflow-Engines » JFolder » org » jfolder » workflow » query » Java Open Source

Java Open Source » Workflow Engines » JFolder 
JFolder » org » jfolder » workflow » query » ColumnContainer.java
/*
 * JFolder, Copyright 2001-2006 Gary Steinmetz
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package org.jfolder.workflow.query;

//base classes
import java.util.ArrayList;

//project specific classes

//other classes

public class ColumnContainer {
    
    private final static Integer APP_STRING = new Integer(1);
    private final static Integer SYS_STRING = new Integer(2);
    private final static Integer APP_DECIMAL = new Integer(3);
    private final static Integer SYS_DECIMAL = new Integer(4);
    private final static Integer APP_BOOLEAN = new Integer(5);
    private final static Integer SYS_BOOLEAN = new Integer(6);
    //
    public final static Integer AGG_COUNT = new Integer(-1);
    public final static Integer AGG_AVG = new Integer(-2);
    public final static Integer AGG_SUM = new Integer(-3);
    public final static Integer AGG_MIN = new Integer(-4);
    public final static Integer AGG_MAX = new Integer(-5);
    
    private ArrayList types = null;
    private ArrayList names = null;
    private ArrayList funcs = null;
    
    //creation functions
    private ColumnContainer() {
        this.types = new ArrayList();
        this.names = new ArrayList();
        this.funcs = new ArrayList();
    }
    
    public final static ColumnContainer createColumnContainer() {
        
        ColumnContainer outValue = new ColumnContainer();
        return outValue;
    }
    
    //register functions
    public void registerCountAll() {
        this.names.add(null);
        this.types.add(null);
        this.funcs.add(AGG_COUNT);
    }
    
    public void registerSystemString(String inName, String inFunction) {
        this.names.add(inName.toUpperCase());
        this.types.add(SYS_STRING);
        this.funcs.add(inFunction);
    }
    
    public void registerSystemDecimal(String inName, String inFunction) {
        this.names.add(inName.toUpperCase());
        this.types.add(SYS_DECIMAL);
        this.funcs.add(inFunction);
    }
    
    public void registerSystemBoolean(String inName, String inFunction) {
        this.names.add(inName.toUpperCase());
        this.types.add(SYS_BOOLEAN);
        this.funcs.add(inFunction);
    }
    
    public void registerApplicationString(String inName, String inFunction) {
        this.names.add(inName.toUpperCase());
        this.types.add(APP_STRING);
        this.funcs.add(inFunction);
    }
    
    public void registerApplicationDecimal(String inName, String inFunction) {
        this.names.add(inName.toUpperCase());
        this.types.add(APP_DECIMAL);
        this.funcs.add(inFunction);
    }
    
    public void registerApplicationBoolean(String inName, String inFunction) {
        this.names.add(inName.toUpperCase());
        this.types.add(APP_BOOLEAN);
        this.funcs.add(inFunction);
    }
    
    //access functions
    public int getColumnCount() {
        return this.names.size();
    }
    public String getColumnName(int inIndex) {
        return (String)this.names.get(inIndex);
    }
    public boolean isSystemColumn(int inIndex) {
        Integer outValue = (Integer)this.types.get(inIndex);
        return (((outValue.intValue())%2) == 0);
    }
    public boolean isStringColumn(int inIndex) {
        Integer outValue = (Integer)this.types.get(inIndex);
        return (outValue.equals(APP_STRING) || outValue.equals(SYS_STRING));
    }
    public boolean isDecimalColumn(int inIndex) {
        Integer outValue = (Integer)this.types.get(inIndex);
        return (outValue.equals(APP_DECIMAL) || outValue.equals(SYS_DECIMAL));
    }
    public boolean isBooleanColumn(int inIndex) {
        Integer outValue = (Integer)this.types.get(inIndex);
        return (outValue.equals(APP_BOOLEAN) || outValue.equals(SYS_BOOLEAN));
    }
    
    //locating functions
    public int[] getColumnIndexes(String inAttrName, int inAttrType,
        int inAttrClass) {
        
        int outValue[] = null;
        Integer columnType = null;
        ArrayList selectedColumns = new ArrayList();
        
        if (inAttrType == BaseDBQueryVendor.SYSTEM
            && inAttrClass == BaseDBQueryVendor.DECIMAL) {
            columnType = SYS_DECIMAL;
        }
        else if (inAttrType == BaseDBQueryVendor.SYSTEM
            && inAttrClass == BaseDBQueryVendor.BOOLEAN) {
            columnType = SYS_BOOLEAN;
        }
        else if (inAttrType == BaseDBQueryVendor.SYSTEM
            && inAttrClass == BaseDBQueryVendor.STRING) {
            columnType = SYS_STRING;
        }
        else if (inAttrType == BaseDBQueryVendor.APPLICATION
            && inAttrClass == BaseDBQueryVendor.DECIMAL) {
            columnType = APP_DECIMAL;
        }
        else if (inAttrType == BaseDBQueryVendor.APPLICATION
            && inAttrClass == BaseDBQueryVendor.BOOLEAN) {
            columnType = APP_BOOLEAN;
        }
        else if (inAttrType == BaseDBQueryVendor.APPLICATION
            && inAttrClass == BaseDBQueryVendor.STRING) {
            columnType = APP_STRING;
        }
        
        for (int i = 0; i < this.names.size(); i++) {
            if (this.names.get(i).equals(inAttrName)
                && this.types.get(i).equals(columnType)) {
                selectedColumns.add(new Integer(i));
            }
        }
        
        outValue = new int[selectedColumns.size()];
        for (int i = 0; i < selectedColumns.size(); i++) {
            outValue[i] = ((Integer)selectedColumns.get(i)).intValue();
        }
        
        return outValue;
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.