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

src.jptools.parser.language.sql.statements.elements.AbstractSQLHelper Maven / Gradle / Ivy

/*
 * AbstractSQLHelper.java
 * 
 * Copyright by jptools, all rights reserved.
 */
package jptools.parser.language.sql.statements.elements;


import jptools.parser.language.sql.SQLSymbolToken;
import jptools.parser.language.sql.statements.SQLSelectStatement;
import jptools.util.KeyValueHolder;

import java.util.ArrayList;
import java.util.List;


/**
 * Defines the super class of all helper classes
 * 
 * @author Meier Patrick
 * @version $Revision: 1.7 $
 */
public abstract class AbstractSQLHelper
{
    private List> expression;
    
    
    /**
     * Constructor for AbstractSQLHelper
     */
    public AbstractSQLHelper()
    {
        super();
        expression = new ArrayList>();
    }


    /**
     * Adds an expression
     * 
     * @param token the combination token
     * @param exp the expression
     */
    public void addExpression( SQLSymbolToken token, String exp )
    {
        expression.add( new KeyValueHolder( token, exp ) );
    }

    
    /**
     * Adds a select statement
     * 
     * @param token the combination token
     * @param statement the select statement
     */
    public void addSelectStatement( SQLSymbolToken token, SQLSelectStatement statement )
    {
        expression.add( new KeyValueHolder( token, statement ) );
    }

    
    /**
     * Gets the expression
     * 
     * @return a list with KeyValueHolders. The key contains the combination
     * token and the value the expression
     */
    public List> getExpressions()
    {
        return expression;
    }

    
    /**
     * Create a sub expression list
     * 
     * @param startTags the list contains String or SQLSymbolToken elements
     * @return a list with KeyValueHolders. The key contains the combination
     * token and the value the expression
     */
    public List> getSubExpressionList( List startTags )
    {
        if( startTags==null || startTags.size()==0 )
            return null;
    
        if( expression==null || 
            expression.isEmpty() || 
            expression.size() <= startTags.size() )
            return null;
        
        int i = 0;
        int idx = 0;
        while( ( i=expression.size() )
            return null;
        
        // i>0 && idx> result = new ArrayList>();
        for( int r = idx; r> list )
    {
        expression = list;
    }
    
    
    /**
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        return expression.toString();
    }

    
    /**
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        final int PRIME = 1000003;
        int result = 0;

        if( expression != null )
            result = PRIME * result + expression.hashCode();

        return result;
    }


    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals( Object oth )
    {
        if( this == oth )
            return true;

        if( oth == null )
            return false;

        if( oth.getClass() != getClass() )
            return false;

        AbstractSQLHelper other = (AbstractSQLHelper)oth;
        if( this.expression == null )
        {
            if( other.expression != null )
                return false;
        }
        else
        {
            if( !this.expression.equals( other.expression ) )
                return false;
        }

        return true;
    }
}