com.trg.search
Class SearchUtil

java.lang.Object
  extended by com.trg.search.SearchUtil

public class SearchUtil
extends java.lang.Object

Utilities for working with searches ISearch, IMutableSearch.

Author:
dwolverton

Nested Class Summary
static class SearchUtil.FilterVisitor
          Visitor for use with walkFilter and walkFilters
static class SearchUtil.ItemVisitor<T>
          Visitor for use with walkList()
 
Constructor Summary
SearchUtil()
           
 
Method Summary
static void addFetch(IMutableSearch search, java.lang.String property)
           
static void addFetches(IMutableSearch search, java.lang.String... properties)
           
static void addField(IMutableSearch search, Field field)
           
static void addField(IMutableSearch search, java.lang.String property)
          If this field is used with resultMode == RESULT_MAP, the property will also be used as the key for this value in the map.
static void addField(IMutableSearch search, java.lang.String property, int operator)
          If this field is used with resultMode == RESULT_MAP, the property will also be used as the key for this value in the map.
static void addField(IMutableSearch search, java.lang.String property, int operator, java.lang.String key)
          If this field is used with resultMode == RESULT_MAP, the key will be used as the key for this value in the map.
static void addField(IMutableSearch search, java.lang.String property, java.lang.String key)
          If this field is used with resultMode == RESULT_MAP, the key will be used as the key for this value in the map.
static void addFields(IMutableSearch search, Field... fields)
           
static void addFilter(IMutableSearch search, Filter filter)
           
static void addFilterAll(IMutableSearch search, java.lang.String property, Filter filter)
          Add a filter that uses the ALL operator.
static void addFilterAnd(IMutableSearch search, Filter... filters)
          Add a filter that uses the AND operator.
static void addFilterEmpty(IMutableSearch search, java.lang.String property)
          Add a filter that uses the IS EMPTY operator.
static void addFilterEqual(IMutableSearch search, java.lang.String property, java.lang.Object value)
          Add a filter that uses the == operator.
static void addFilterGreaterOrEqual(IMutableSearch search, java.lang.String property, java.lang.Object value)
          Add a filter that uses the >= operator.
static void addFilterGreaterThan(IMutableSearch search, java.lang.String property, java.lang.Object value)
          Add a filter that uses the > operator.
static void addFilterILike(IMutableSearch search, java.lang.String property, java.lang.String value)
          Add a filter that uses the ILIKE operator.
static void addFilterIn(IMutableSearch search, java.lang.String property, java.util.Collection<?> value)
          Add a filter that uses the IN operator.
static void addFilterIn(IMutableSearch search, java.lang.String property, java.lang.Object... value)
          Add a filter that uses the IN operator.
static void addFilterLessOrEqual(IMutableSearch search, java.lang.String property, java.lang.Object value)
          Add a filter that uses the <= operator.
static void addFilterLessThan(IMutableSearch search, java.lang.String property, java.lang.Object value)
          Add a filter that uses the < operator.
static void addFilterLike(IMutableSearch search, java.lang.String property, java.lang.String value)
          Add a filter that uses the LIKE operator.
static void addFilterNone(IMutableSearch search, java.lang.String property, Filter filter)
          Add a filter that uses the NONE operator.
static void addFilterNot(IMutableSearch search, Filter filter)
          Add a filter that uses the NOT operator.
static void addFilterNotEmpty(IMutableSearch search, java.lang.String property)
          Add a filter that uses the IS NOT EMPTY operator.
static void addFilterNotEqual(IMutableSearch search, java.lang.String property, java.lang.Object value)
          Add a filter that uses the !
static void addFilterNotIn(IMutableSearch search, java.lang.String property, java.util.Collection<?> value)
          Add a filter that uses the NOT IN operator.
static void addFilterNotIn(IMutableSearch search, java.lang.String property, java.lang.Object... value)
          Add a filter that uses the NOT IN operator.
static void addFilterNotNull(IMutableSearch search, java.lang.String property)
          Add a filter that uses the IS NOT NULL operator.
static void addFilterNull(IMutableSearch search, java.lang.String property)
          Add a filter that uses the IS NULL operator.
static void addFilterOr(IMutableSearch search, Filter... filters)
          Add a filter that uses the OR operator.
static void addFilters(IMutableSearch search, Filter... filters)
           
static void addFilterSome(IMutableSearch search, java.lang.String property, Filter filter)
          Add a filter that uses the SOME operator.
static void addSort(IMutableSearch search, Sort sort)
           
static void addSort(IMutableSearch search, java.lang.String property, boolean desc)
          Add sort by property.
static void addSort(IMutableSearch search, java.lang.String property, boolean desc, boolean ignoreCase)
          Add sort by property.
static void addSortAsc(IMutableSearch search, java.lang.String property)
          Add ascending sort by property
static void addSortAsc(IMutableSearch search, java.lang.String property, boolean ignoreCase)
          Add ascending sort by property
static void addSortDesc(IMutableSearch search, java.lang.String property)
          Add descending sort by property
static void addSortDesc(IMutableSearch search, java.lang.String property, boolean ignoreCase)
          Add descending sort by property
static void addSorts(IMutableSearch search, Sort... sorts)
           
static int calcFirstResult(ISearch search)
          Calculate the first result to use given the firstResult, page and maxResults values of the search object.
static void clear(IMutableSearch search)
           
static void clearFetches(IMutableSearch search)
           
static void clearFields(IMutableSearch search)
           
static void clearFilters(IMutableSearch search)
           
static void clearPaging(IMutableSearch search)
           
static void clearSorts(IMutableSearch search)
           
static IMutableSearch copy(ISearch source)
          Copy the contents of the source search object into a new search object.
static
<T extends IMutableSearch>
T
copy(ISearch source, T destination)
          Copy the contents of the source search object to the destination search object, overriding any contents previously found in the destination.
static boolean equals(ISearch search, java.lang.Object obj)
          Return true if the search objects have equivalent contents.
static int hashCode(ISearch search)
          Return a hash code value for the given search.
static void mergeFetches(IMutableSearch search, java.util.List<java.lang.String> fetches)
          Modify the search by adding the given fetches to the current fetches in the search.
static void mergeFetches(IMutableSearch search, java.lang.String... fetches)
          Modify the search by adding the given fetches to the current fetches in the search.
static void mergeFieldsAfter(IMutableSearch search, Field... fields)
          Modify the search by adding the given fields after the current fields in the search.
static void mergeFieldsAfter(IMutableSearch search, java.util.List<Field> fields)
          Modify the search by adding the given fields after the current fields in the search.
static void mergeFieldsBefore(IMutableSearch search, Field... fields)
          Modify the search by adding the given fields before the current fields in the search.
static void mergeFieldsBefore(IMutableSearch search, java.util.List<Field> fields)
          Modify the search by adding the given fields before the current fields in the search.
static void mergeFiltersAnd(IMutableSearch search, Filter... filters)
          Modify the search by adding the given filters using AND semantics
static void mergeFiltersAnd(IMutableSearch search, java.util.List<Filter> filters)
          Modify the search by adding the given filters using AND semantics
static void mergeFiltersOr(IMutableSearch search, Filter... filters)
          Modify the search by adding the given filters using OR semantics
static void mergeFiltersOr(IMutableSearch search, java.util.List<Filter> filters)
          Modify the search by adding the given filters using OR semantics
static void mergeSortsAfter(IMutableSearch search, java.util.List<Sort> sorts)
          Modify the search by adding the given sorts after the current sorts in the search.
static void mergeSortsAfter(IMutableSearch search, Sort... sorts)
          Modify the search by adding the given sorts after the current sorts in the search.
static void mergeSortsBefore(IMutableSearch search, java.util.List<Sort> sorts)
          Modify the search by adding the given sorts before the current sorts in the search.
static void mergeSortsBefore(IMutableSearch search, Sort... sorts)
          Modify the search by adding the given sorts before the current sorts in the search.
static void removeFetch(IMutableSearch search, java.lang.String property)
           
static void removeField(IMutableSearch search, Field field)
           
static void removeField(IMutableSearch search, java.lang.String property)
           
static void removeField(IMutableSearch search, java.lang.String property, java.lang.String key)
           
static void removeFilter(IMutableSearch search, Filter filter)
           
static void removeFiltersOnProperty(IMutableSearch search, java.lang.String property)
          Remove all filters on the given property.
static void removeSort(IMutableSearch search, Sort sort)
           
static void removeSort(IMutableSearch search, java.lang.String property)
           
static IMutableSearch shallowCopy(ISearch source)
          Copy the contents of the source search object to the destination search object, overriding any contents previously found in the destination.
static IMutableSearch shallowCopy(ISearch source, IMutableSearch destination)
          Copy the contents of the source search object to the destination search object, overriding any contents previously found in the destination.
static java.lang.String toString(ISearch search)
          Return a human-readable string describing the contents of the given search.
static Filter walkFilter(Filter filter, SearchUtil.FilterVisitor visitor, boolean removeNulls)
          Walk a filter and all its sub filters, visiting each filter in the tree.
static java.util.List<Filter> walkFilters(java.util.List<Filter> filters, SearchUtil.FilterVisitor visitor, boolean removeNulls)
          Walk through a list of filters and all the sub filters, visiting each filter in the tree.
static
<T> java.util.List<T>
walkList(java.util.List<T> list, SearchUtil.ItemVisitor<T> visitor, boolean removeNulls)
          Visit each non-null item is a list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SearchUtil

public SearchUtil()
Method Detail

addFetch

public static void addFetch(IMutableSearch search,
                            java.lang.String property)

addFetches

public static void addFetches(IMutableSearch search,
                              java.lang.String... properties)

addField

public static void addField(IMutableSearch search,
                            Field field)

addFields

public static void addFields(IMutableSearch search,
                             Field... fields)

addField

public static void addField(IMutableSearch search,
                            java.lang.String property)
If this field is used with resultMode == RESULT_MAP, the property will also be used as the key for this value in the map.


addField

public static void addField(IMutableSearch search,
                            java.lang.String property,
                            int operator)
If this field is used with resultMode == RESULT_MAP, the property will also be used as the key for this value in the map.


addField

public static void addField(IMutableSearch search,
                            java.lang.String property,
                            int operator,
                            java.lang.String key)
If this field is used with resultMode == RESULT_MAP, the key will be used as the key for this value in the map.


addField

public static void addField(IMutableSearch search,
                            java.lang.String property,
                            java.lang.String key)
If this field is used with resultMode == RESULT_MAP, the key will be used as the key for this value in the map.


addFilter

public static void addFilter(IMutableSearch search,
                             Filter filter)

addFilters

public static void addFilters(IMutableSearch search,
                              Filter... filters)

addFilterAll

public static void addFilterAll(IMutableSearch search,
                                java.lang.String property,
                                Filter filter)
Add a filter that uses the ALL operator.


addFilterAnd

public static void addFilterAnd(IMutableSearch search,
                                Filter... filters)
Add a filter that uses the AND operator.

This takes a variable number of parameters. Any number of Filter s can be specified.


addFilterEmpty

public static void addFilterEmpty(IMutableSearch search,
                                  java.lang.String property)
Add a filter that uses the IS EMPTY operator.


addFilterEqual

public static void addFilterEqual(IMutableSearch search,
                                  java.lang.String property,
                                  java.lang.Object value)
Add a filter that uses the == operator.


addFilterGreaterOrEqual

public static void addFilterGreaterOrEqual(IMutableSearch search,
                                           java.lang.String property,
                                           java.lang.Object value)
Add a filter that uses the >= operator.


addFilterGreaterThan

public static void addFilterGreaterThan(IMutableSearch search,
                                        java.lang.String property,
                                        java.lang.Object value)
Add a filter that uses the > operator.


addFilterILike

public static void addFilterILike(IMutableSearch search,
                                  java.lang.String property,
                                  java.lang.String value)
Add a filter that uses the ILIKE operator.


addFilterIn

public static void addFilterIn(IMutableSearch search,
                               java.lang.String property,
                               java.util.Collection<?> value)
Add a filter that uses the IN operator.


addFilterIn

public static void addFilterIn(IMutableSearch search,
                               java.lang.String property,
                               java.lang.Object... value)
Add a filter that uses the IN operator.

This takes a variable number of parameters. Any number of values can be specified.


addFilterLessOrEqual

public static void addFilterLessOrEqual(IMutableSearch search,
                                        java.lang.String property,
                                        java.lang.Object value)
Add a filter that uses the <= operator.


addFilterLessThan

public static void addFilterLessThan(IMutableSearch search,
                                     java.lang.String property,
                                     java.lang.Object value)
Add a filter that uses the < operator.


addFilterLike

public static void addFilterLike(IMutableSearch search,
                                 java.lang.String property,
                                 java.lang.String value)
Add a filter that uses the LIKE operator.


addFilterNone

public static void addFilterNone(IMutableSearch search,
                                 java.lang.String property,
                                 Filter filter)
Add a filter that uses the NONE operator.


addFilterNot

public static void addFilterNot(IMutableSearch search,
                                Filter filter)
Add a filter that uses the NOT operator.


addFilterNotEqual

public static void addFilterNotEqual(IMutableSearch search,
                                     java.lang.String property,
                                     java.lang.Object value)
Add a filter that uses the != operator.


addFilterNotIn

public static void addFilterNotIn(IMutableSearch search,
                                  java.lang.String property,
                                  java.util.Collection<?> value)
Add a filter that uses the NOT IN operator.


addFilterNotIn

public static void addFilterNotIn(IMutableSearch search,
                                  java.lang.String property,
                                  java.lang.Object... value)
Add a filter that uses the NOT IN operator.

This takes a variable number of parameters. Any number of values can be specified.


addFilterNotEmpty

public static void addFilterNotEmpty(IMutableSearch search,
                                     java.lang.String property)
Add a filter that uses the IS NOT EMPTY operator.


addFilterNotNull

public static void addFilterNotNull(IMutableSearch search,
                                    java.lang.String property)
Add a filter that uses the IS NOT NULL operator.


addFilterNull

public static void addFilterNull(IMutableSearch search,
                                 java.lang.String property)
Add a filter that uses the IS NULL operator.


addFilterOr

public static void addFilterOr(IMutableSearch search,
                               Filter... filters)
Add a filter that uses the OR operator.

This takes a variable number of parameters. Any number of Filter s can be specified.


addFilterSome

public static void addFilterSome(IMutableSearch search,
                                 java.lang.String property,
                                 Filter filter)
Add a filter that uses the SOME operator.


addSort

public static void addSort(IMutableSearch search,
                           Sort sort)

addSorts

public static void addSorts(IMutableSearch search,
                            Sort... sorts)

addSort

public static void addSort(IMutableSearch search,
                           java.lang.String property,
                           boolean desc)
Add sort by property. Ascending if desc == false, descending if desc == true.


addSort

public static void addSort(IMutableSearch search,
                           java.lang.String property,
                           boolean desc,
                           boolean ignoreCase)
Add sort by property. Ascending if desc == false, descending if desc == true.


addSortAsc

public static void addSortAsc(IMutableSearch search,
                              java.lang.String property)
Add ascending sort by property


addSortAsc

public static void addSortAsc(IMutableSearch search,
                              java.lang.String property,
                              boolean ignoreCase)
Add ascending sort by property


addSortDesc

public static void addSortDesc(IMutableSearch search,
                               java.lang.String property)
Add descending sort by property


addSortDesc

public static void addSortDesc(IMutableSearch search,
                               java.lang.String property,
                               boolean ignoreCase)
Add descending sort by property


removeFetch

public static void removeFetch(IMutableSearch search,
                               java.lang.String property)

removeField

public static void removeField(IMutableSearch search,
                               Field field)

removeField

public static void removeField(IMutableSearch search,
                               java.lang.String property)

removeField

public static void removeField(IMutableSearch search,
                               java.lang.String property,
                               java.lang.String key)

removeFilter

public static void removeFilter(IMutableSearch search,
                                Filter filter)

removeFiltersOnProperty

public static void removeFiltersOnProperty(IMutableSearch search,
                                           java.lang.String property)
Remove all filters on the given property.


removeSort

public static void removeSort(IMutableSearch search,
                              Sort sort)

removeSort

public static void removeSort(IMutableSearch search,
                              java.lang.String property)

clear

public static void clear(IMutableSearch search)

clearFetches

public static void clearFetches(IMutableSearch search)

clearFields

public static void clearFields(IMutableSearch search)

clearFilters

public static void clearFilters(IMutableSearch search)

clearPaging

public static void clearPaging(IMutableSearch search)

clearSorts

public static void clearSorts(IMutableSearch search)

mergeSortsBefore

public static void mergeSortsBefore(IMutableSearch search,
                                    java.util.List<Sort> sorts)
Modify the search by adding the given sorts before the current sorts in the search.


mergeSortsBefore

public static void mergeSortsBefore(IMutableSearch search,
                                    Sort... sorts)
Modify the search by adding the given sorts before the current sorts in the search.


mergeSortsAfter

public static void mergeSortsAfter(IMutableSearch search,
                                   java.util.List<Sort> sorts)
Modify the search by adding the given sorts after the current sorts in the search.


mergeSortsAfter

public static void mergeSortsAfter(IMutableSearch search,
                                   Sort... sorts)
Modify the search by adding the given sorts after the current sorts in the search.


mergeFetches

public static void mergeFetches(IMutableSearch search,
                                java.util.List<java.lang.String> fetches)
Modify the search by adding the given fetches to the current fetches in the search.


mergeFetches

public static void mergeFetches(IMutableSearch search,
                                java.lang.String... fetches)
Modify the search by adding the given fetches to the current fetches in the search.


mergeFiltersAnd

public static void mergeFiltersAnd(IMutableSearch search,
                                   java.util.List<Filter> filters)
Modify the search by adding the given filters using AND semantics


mergeFiltersAnd

public static void mergeFiltersAnd(IMutableSearch search,
                                   Filter... filters)
Modify the search by adding the given filters using AND semantics


mergeFiltersOr

public static void mergeFiltersOr(IMutableSearch search,
                                  java.util.List<Filter> filters)
Modify the search by adding the given filters using OR semantics


mergeFiltersOr

public static void mergeFiltersOr(IMutableSearch search,
                                  Filter... filters)
Modify the search by adding the given filters using OR semantics


mergeFieldsBefore

public static void mergeFieldsBefore(IMutableSearch search,
                                     java.util.List<Field> fields)
Modify the search by adding the given fields before the current fields in the search.


mergeFieldsBefore

public static void mergeFieldsBefore(IMutableSearch search,
                                     Field... fields)
Modify the search by adding the given fields before the current fields in the search.


mergeFieldsAfter

public static void mergeFieldsAfter(IMutableSearch search,
                                    java.util.List<Field> fields)
Modify the search by adding the given fields after the current fields in the search.


mergeFieldsAfter

public static void mergeFieldsAfter(IMutableSearch search,
                                    Field... fields)
Modify the search by adding the given fields after the current fields in the search.


calcFirstResult

public static int calcFirstResult(ISearch search)
Calculate the first result to use given the firstResult, page and maxResults values of the search object.

The calculation is as follows:


shallowCopy

public static IMutableSearch shallowCopy(ISearch source,
                                         IMutableSearch destination)
Copy the contents of the source search object to the destination search object, overriding any contents previously found in the destination. All destination properties reference the same objects from the source properties.


shallowCopy

public static IMutableSearch shallowCopy(ISearch source)
Copy the contents of the source search object to the destination search object, overriding any contents previously found in the destination. All destination properties reference the same objects from the source properties.


copy

public static <T extends IMutableSearch> T copy(ISearch source,
                                                T destination)
Copy the contents of the source search object to the destination search object, overriding any contents previously found in the destination. All collections are copied into new collections, but the items in those collections are not duplicated; they still point to the same objects.


copy

public static IMutableSearch copy(ISearch source)
Copy the contents of the source search object into a new search object. All collections are copied into new collections, but the items in those collections are not duplicated; they still point to the same objects.


equals

public static boolean equals(ISearch search,
                             java.lang.Object obj)
Return true if the search objects have equivalent contents.


hashCode

public static int hashCode(ISearch search)
Return a hash code value for the given search.


toString

public static java.lang.String toString(ISearch search)
Return a human-readable string describing the contents of the given search.


walkList

public static <T> java.util.List<T> walkList(java.util.List<T> list,
                                             SearchUtil.ItemVisitor<T> visitor,
                                             boolean removeNulls)
Visit each non-null item is a list. Each item may be replaced by the visitor. The modified list is returned. If removeNulls is true, any null elements will be removed from the final list.

If there are any modifications to be made to the list a new list is made with the changes so that the original list remains unchanged. If no changes are made, the original list is returned.


walkFilters

public static java.util.List<Filter> walkFilters(java.util.List<Filter> filters,
                                                 SearchUtil.FilterVisitor visitor,
                                                 boolean removeNulls)
Walk through a list of filters and all the sub filters, visiting each filter in the tree. A FilterVisitor is used to visit each filter. The FilterVisitor may replace the Filter that is is visiting. If it does, a new tree and list of Filters will be created for every part of the tree that is affected, thus preserving the original tree.

Returns:
if any changes have been made, the new list of Filters; if not, the original list.

walkFilter

public static Filter walkFilter(Filter filter,
                                SearchUtil.FilterVisitor visitor,
                                boolean removeNulls)
Walk a filter and all its sub filters, visiting each filter in the tree. A FilterVisitor is used to visit each filter. The FilterVisitor may replace the Filter that is is visiting. If it does, a new tree and will be created for every part of the tree that is affected, thus preserving the original tree.

Returns:
if any changes have been made, the new Filter; if not, the original Filter.


Copyright © 2008-2010 eBM WebSourcing. All Rights Reserved.