@@ -0,0 +1,2968 @@
+package eu.nerro.wolappla.util;%0A%0Aimport android.database.Cursor;%0Aimport android.database.sqlite.SQLiteDatabase;%0Aimport android.text.TextUtils;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0Aimport static eu.nerro.wolappla.util.LogUtils.LOGV;%0Aimport static eu.nerro.wolappla.util.LogUtils.makeLogTag;%0A%0A/**%0A * Helper for building selection clauses for %7B@link SQLiteDatabase%7D. Each%0A * appended clause is combined using %3Ccode%3EAND%3C/code%3E.%0A * %3Cp/%3E%0A * %3Cstrong%3ENote that this class is %3Cem%3Enot%3C/em%3E thread safe.%3C/strong%3E%0A */%0Apublic class SelectionBuilder %7B%0A  private static final String TAG = makeLogTag(SelectionBuilder.class);%0A%0A  private String mTable = null;%0A  private StringBuilder mSelection = new StringBuilder();%0A  private List%3CString%3E mSelectionArgs = new ArrayList%3CString%3E();%0A%0A  public SelectionBuilder table(String table) %7B%0A    mTable = table;%0A    return this;%0A  %7D%0A%0A  /**%0A   * Append the given selection clause to the internal state. Each clause%0A   * is surrounded with parenthesis and combined using %3Ccode%3EAND%3C/code%3E.%0A   */%0A  public SelectionBuilder where(String selection, String... selectionArgs) %7B%0A    if (TextUtils.isEmpty(selection)) %7B%0A      if (selectionArgs != null && selectionArgs.length %3E 0) %7B%0A        throw new IllegalArgumentException(%22Valid selection required when including arguments%22);%0A      %7D%0A      return this;%0A    %7D%0A%0A    if (mSelection.length() %3E 0) %7B%0A      mSelection.append(%22 AND %22);%0A    %7D%0A%0A    mSelection.append(%22(%22).append(selection).append(%22)%22);%0A    if (selectionArgs != null) %7B%0A      Collections.addAll(mSelectionArgs, selectionArgs);%0A    %7D%0A%0A    return this;%0A  %7D%0A%0A  /**%0A   * Execute query using current internal state as %3Ccode%3EWHERE%3C/code%3E clause.%0A   */%0A  public Cursor query(SQLiteDatabase database, String%5B%5D columns, String orderBy) %7B%0A    return query(database, columns, null, null, orderBy, null);%0A  %7D%0A%0A  /**%0A   * Execute query using current internal state as %3Ccode%3EWHERE%3C/code%3E clause.%0A   */%0A  public Cursor query(SQLiteDatabase database, String%5B%5D columns, String groupBy, String having, String orderBy, String limit) %7B%0A    assertTable();%0A    LOGV(TAG, %22query(columns=%22 + Arrays.toString(columns) + %22) %22 + this);%0A%0A    return database.query(mTable, columns, getSelection(), getSelectionArgs(), groupBy, having, orderBy, limit);%0A  %7D%0A%0A  private void assertTable() %7B%0A    if (mTable == null) %7B%0A      throw new IllegalStateException(%22Table not specified%22);%0A    %7D%0A  %7D%0A%0A  /**%0A   * Return selection string for current internal state.%0A   */%0A  public String getSelection() %7B%0A    return mSelection.toString();%0A  %7D%0A%0A  /**%0A   * Return selection arguments for current internal state.%0A   */%0A  public String%5B%5D getSelectionArgs() %7B%0A    return mSelectionArgs.toArray(new String%5BmSelectionArgs.size()%5D);%0A  %7D%0A%0A  @Override%0A  public String toString() %7B%0A    return %22SelectionBuilder=%5Btable=%22 + mTable + %22, selection=%22 + getSelection()%0A        + %22, %22 + Arrays.toString(getSelectionArgs()) + %22%5D%22;%0A  %7D%0A%7D%0A

Add helper for building selection clauses for sqlite database