1 package net.sourceforge.phpdt.sql.sql;
3 import java.util.ArrayList;
5 public class FilterSort {
6 private ArrayList filterList = new ArrayList();
7 private ArrayList sortList = new ArrayList();
8 public void addFilter(String column, String operator, String value, boolean isString) {
9 FilterRow row = new FilterRow();
11 row.operator = operator;
13 row.isString = isString;
16 public void clearFilters() {
19 public void addSort(String column) {
22 public void removeSort(String column) {
23 sortList.remove(column);
25 public String toString() {
26 StringBuffer text = new StringBuffer();
27 if (filterList.size() > 0) {
28 text.append(" WHERE ");
29 for (int i = 0; i < filterList.size(); i++) {
30 FilterRow row = (FilterRow) filterList.get(i);
31 text.append(row.column);
33 text.append(row.operator);
36 text.append(escape(row.value));
38 text.append(row.value);
41 if (i < filterList.size() - 1) {
46 if (sortList.size() > 0) {
47 text.append(" ORDER BY ");
48 for (int i = 0; i < sortList.size(); i++) {
49 String value = (String) sortList.get(i);
51 if (i < sortList.size() - 1) {
56 return text.toString();
58 public static String escape(String original) {
59 return '\'' + original + '\'';
65 public String operator;
67 public boolean isString;