Android Open Source - TwelveRules Criterion






From Project

Back to project page TwelveRules.

License

The source code is released under:

Apache License

If you think the Android project TwelveRules listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.manuelpeinado.sql_dsl;
//from w w w . j  a  v a 2s  .c om
import static com.manuelpeinado.sql_dsl.Constants.AND;
import static com.manuelpeinado.sql_dsl.Constants.EXISTS;
import static com.manuelpeinado.sql_dsl.Constants.LEFT_PARENTHESIS;
import static com.manuelpeinado.sql_dsl.Constants.OR;
import static com.manuelpeinado.sql_dsl.Constants.RIGHT_PARENTHESIS;
import static com.manuelpeinado.sql_dsl.Constants.SPACE;

public abstract class Criterion {
    protected final Operator operator;

    Criterion(Operator operator) {
        this.operator = operator;
    }
    
    public Criterion and(Criterion other) {
      if (other == null) {
        return this;
      }
        return Criterion.and(this, other);
    }

    public static Criterion and(final Criterion criterion, final Criterion... criterions) {
        return new Criterion(Operator.and) {

            protected void populate(StringBuilder sb) {
                sb.append(criterion);
                for (Criterion criterion : criterions) {
                    sb.append(SPACE).append(AND).append(SPACE).append(criterion);
                }
            }
        };
    }

    public static Criterion or(final Criterion criterion, final Criterion... criterions) {
        return new Criterion(Operator.or) {

            protected void populate(StringBuilder sb) {
                sb.append(criterion);
                for (Criterion criterion : criterions) {
                    sb.append(SPACE).append(OR).append(SPACE).append(criterion.toString());
                }
            }
        };
    }

    public static Criterion exists(final Query query) {
        return new Criterion(Operator.exists) {

            protected void populate(StringBuilder sb) {
                sb.append(EXISTS).append(SPACE).append(LEFT_PARENTHESIS).append(query).append(RIGHT_PARENTHESIS);
            }
        };
    }

    public static Criterion not(Criterion criterion) {
        return new Criterion(null) {

            protected void populate(StringBuilder sb) {
                
            }
        };
    }

    protected abstract void populate(StringBuilder sb);

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder(LEFT_PARENTHESIS);
        populate(builder);
        builder.append(RIGHT_PARENTHESIS);
        return builder.toString();
    }

}




Java Source Code List

com.manuelpeinado.sql_dsl.Constants.java
com.manuelpeinado.sql_dsl.Criterion.java
com.manuelpeinado.sql_dsl.DBObject.java
com.manuelpeinado.sql_dsl.Field.java
com.manuelpeinado.sql_dsl.GroupBy.java
com.manuelpeinado.sql_dsl.JoinType.java
com.manuelpeinado.sql_dsl.Join.java
com.manuelpeinado.sql_dsl.Operator.java
com.manuelpeinado.sql_dsl.OrderType.java
com.manuelpeinado.sql_dsl.Order.java
com.manuelpeinado.sql_dsl.Query.java
com.manuelpeinado.sql_dsl.Table.java
com.manuelpeinado.sql_dsl.UnaryCriterion.java
com.manuelpeinado.twelverules.AssetsDatabase.java
com.manuelpeinado.twelverules.ColumnSet.java
com.manuelpeinado.twelverules.ContentValuesCreator.java
com.manuelpeinado.twelverules.DatabaseColumn.java
com.manuelpeinado.twelverules.DatabaseTable.java
com.manuelpeinado.twelverules.Database.java
com.manuelpeinado.twelverules.DbUtils.java
com.manuelpeinado.twelverules.IDatabase.java