org.cdmckay.coffeedom.filter
Class ContentFilter

java.lang.Object
  extended by org.cdmckay.coffeedom.filter.AbstractFilter
      extended by org.cdmckay.coffeedom.filter.ContentFilter
All Implemented Interfaces:
Serializable, Filter

public class ContentFilter
extends AbstractFilter

A general purpose Filter able to represent all legal CoffeeDOM objects or a specific subset. Filtering is accomplished by way of a filtering enum set in which each enum constant represents whether a CoffeeDOM object is visible or not. For example to view all Text and CDATA nodes in the content of element x.


      Filter filter = new ContentFilter(EnumSet.of(ContentType.Text, ContentType.CDATA));
      List<Content> content = x.getContents(filter);
 

The default is to allow all valid CoffeeDOM objects.

Author:
Bradley S. Huffman, Cameron McKay
See Also:
Serialized Form

Nested Class Summary
static class ContentFilter.ContentType
           
 
Constructor Summary
ContentFilter()
          Default constructor that allows any legal CoffeeDOM objects.
ContentFilter(boolean allVisible)
          Set whether all CoffeeDOM objects are visible or not.
ContentFilter(EnumSet<ContentFilter.ContentType> set)
          Filter out CoffeeDOM objects according to a filtering set.
 
Method Summary
 boolean equals(Object object)
          Returns whether the two filters are equivalent (i.e. the matching mask values are identical).
 void filterDocumentContent()
          Set filter to match only CoffeeDOM objects that are legal document content.
 void filterElementContent()
          Set filter to match only CoffeeDOM objects that are legal element content.
 EnumSet<ContentFilter.ContentType> getFilterSet()
          Return current filtering set.
 int hashCode()
           
 boolean matches(Object object)
          Check to see if the object matches according to the filter mask.
 void resetFilterSet()
          Reset this filter to allow all legal CoffeeDOM objects.
 void setFilterSet(EnumSet<ContentFilter.ContentType> set)
          Set filtering set.
 
Methods inherited from class org.cdmckay.coffeedom.filter.AbstractFilter
and, negate, or
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContentFilter

public ContentFilter()
Default constructor that allows any legal CoffeeDOM objects.


ContentFilter

public ContentFilter(boolean allVisible)
Set whether all CoffeeDOM objects are visible or not.

Parameters:
allVisible - true all CoffeeDOM objects are visible, false all CoffeeDOM objects are hidden.

ContentFilter

public ContentFilter(EnumSet<ContentFilter.ContentType> set)
Filter out CoffeeDOM objects according to a filtering set.

Parameters:
set - Set of CoffeeDOM content types to allow.
Method Detail

getFilterSet

public EnumSet<ContentFilter.ContentType> getFilterSet()
Return current filtering set.

Returns:
The current filtering set.

setFilterSet

public void setFilterSet(EnumSet<ContentFilter.ContentType> set)
Set filtering set.

Parameters:
set - the new filtering set

resetFilterSet

public void resetFilterSet()
Reset this filter to allow all legal CoffeeDOM objects.


filterDocumentContent

public void filterDocumentContent()
Set filter to match only CoffeeDOM objects that are legal document content.


filterElementContent

public void filterElementContent()
Set filter to match only CoffeeDOM objects that are legal element content.


matches

public boolean matches(Object object)
Check to see if the object matches according to the filter mask.

Parameters:
object - The object to verify.
Returns:
true if the objected matched a predfined set of rules.

equals

public boolean equals(Object object)
Returns whether the two filters are equivalent (i.e. the matching mask values are identical).

Overrides:
equals in class Object
Parameters:
object - the object to compare against
Returns:
whether the two filters are equal

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2011. All Rights Reserved.