Code example for Stack

Methods: peek, push

0
    } 
 
    public ProviderCriteria startSubCriteria() { 
        addOperand(); 
        mWhereSb.append("(");
        mOperandStack.push(true);
        mIsWhereFirstElement = true;
        return this;
    } 
 
    public ProviderCriteria endSubCriteria() { 
        mWhereSb.append(")");
        mOperandStack.pop();
        mIsWhereFirstElement = false;
        return this;
    } 
 
    public ProviderCriteria startOr() { 
        mOperandStack.pop();
        mOperandStack.push(false);
        return this;
    } 
 
    public ProviderCriteria endOr() { 
        mOperandStack.pop();
        mOperandStack.push(true);
        return this;
    } 
 
    public ProviderCriteria addSortOrder(final ColumnMetadata metadata, final boolean isAscendant) {
        if (mIsOrderFirstElement) {
            mIsOrderFirstElement = false;
        } else { 
            mOrderSb.append(",");
        } 
        mOrderSb.append(metadata.getName()).append(isAscendant ? " ASC" : " DESC");
        return this;
    } 
 
    public String getWhereClause() {
        return mWhereSb.length() == 0 ? null : mWhereSb.toString();
    } 
 
    public String[] getWhereParams() {
        final int paramCount = mWhereParamList.size();
        final String[] paramArray = new String[paramCount];
        for (int i = 0; i < paramCount; i++) {
            paramArray[i] = mWhereParamList.get(i);
        } 
        return paramArray;
    } 
 
    public String getOrderClause() {
        return mOrderSb.length() == 0 ? null : mOrderSb.toString();
    } 
 
    private void addCriteria(final String column, final Object value, final int type) {
        mWhereSb.append(column);
        switch (type) {
            case TYPE_LIKE:
                mWhereSb.append(" like ?");
                break; 
            case TYPE_IN:
                mWhereSb.append(" in (?)");
                break; 
            case TYPE_EQ:
                mWhereSb.append(" = ?");
                break; 
            case TYPE_NE:
                mWhereSb.append(" != ?");
                break; 
            case TYPE_LT:
                mWhereSb.append(" < ?");
                break; 
            case TYPE_LTOE:
                mWhereSb.append(" <= ?");
                break; 
            case TYPE_GT:
                mWhereSb.append(" > ?");
                break; 
            case TYPE_GTOE:
                mWhereSb.append(" >= ?");
                break; 
        } 
        mWhereParamList.add(String.valueOf(value));
    } 
 
    private void addOperand() { 
        if (mIsWhereFirstElement) {
            mIsWhereFirstElement = false;
        } else { 
            mWhereSb.append(mOperandStack.peek() ? AND : OR);
        } 
    } 
}