com.devexperts.qd.kit
Class PatternFilter

java.lang.Object
  extended by com.devexperts.qd.kit.PatternFilter
All Implemented Interfaces:
StableSubscriptionFilter, SubscriptionFilter

public final class PatternFilter
extends java.lang.Object
implements StableSubscriptionFilter

SubscriptionFilter that understands a simple GLOB-like grammar to specify matching symbols.

This filter always accepts wildcard symbol regardless of an actual pattern.


Method Summary
 boolean acceptRecord(DataRecord record, int cipher, java.lang.String symbol)
          Determines if specified record shall be processed by corresponding subsystem.
static SubscriptionFilterFactory getFactory(DataScheme scheme)
           
static PatternFilter getInstance(java.lang.String pattern)
          Deprecated. Use PatternFilter.valueOf(pattern, scheme)
static SubscriptionFilter getInstance(java.lang.String pattern, SubscriptionFilter chained_filter)
          Deprecated. Use CompositeFilters.makeAnd(PatternFilter.valueOf(pattern, scheme), chained_filter)
static java.lang.String quote(java.lang.String string)
          Quotes all reserved characters in the given string, so that it can be used as a pattern filter.
 StableSubscriptionFilter toStableFilter()
          Returns a stable filter that is the same or more encompassing as this filter.
 java.lang.String toString()
          Returns filter description -- its pattern.
static SubscriptionFilter valueOf(java.lang.String pattern, DataScheme scheme)
          Returns filter with a specified pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getFactory

public static SubscriptionFilterFactory getFactory(DataScheme scheme)

quote

public static java.lang.String quote(java.lang.String string)
                              throws FilterSyntaxException
Quotes all reserved characters in the given string, so that it can be used as a pattern filter. For example, quote("Trade&N") will be equal to "Trade[&]N". Special characters that are quoted with braces are: '!', ':', ';', '|', '&', '*', '?', '+', '(', ')', '{', '}', '<', '>', '\', '~', ',', '"', ''', and '`'.

If the input string starts with a lower-case characters (from 'a' to 'z') it is also quoted with braces, because patterns starting with a lower case letter are reserved. For example, quote("feed") is equal to "[f]eed".

Throws:
java.lang.NullPointerException - if the string is null.
FilterSyntaxException - if the string contains characters that cannot be represented in pattern filter in any form. All characters with codes larger than 32 and lower than 128 are supported with the exception of '[' and ']'.

valueOf

public static SubscriptionFilter valueOf(java.lang.String pattern,
                                         DataScheme scheme)
                                  throws FilterSyntaxException
Returns filter with a specified pattern. Returns null if pattern is empty or matches everything.

Throws:
java.lang.NullPointerException - if pattern is null.
FilterSyntaxException - if pattern is invalid.

getInstance

public static PatternFilter getInstance(java.lang.String pattern)
                                 throws FilterSyntaxException
Deprecated. Use PatternFilter.valueOf(pattern, scheme)

Returns filter with a specified pattern. Returns null if pattern is empty or matches everything.

Throws:
java.lang.NullPointerException - if pattern is null.
FilterSyntaxException - if pattern is invalid.

getInstance

public static SubscriptionFilter getInstance(java.lang.String pattern,
                                             SubscriptionFilter chained_filter)
                                      throws FilterSyntaxException
Deprecated. Use CompositeFilters.makeAnd(PatternFilter.valueOf(pattern, scheme), chained_filter)

Creates filter with a specified pattern and chained filter working in AND fashion. Returns null if resulting filter matches everything.

Throws:
java.lang.NullPointerException - if pattern is null.
FilterSyntaxException - if pattern is invalid.

toStableFilter

public StableSubscriptionFilter toStableFilter()
Description copied from interface: StableSubscriptionFilter
Returns a stable filter that is the same or more encompassing as this filter. It is always safe to return null, which means that this filter is not stable and the only stable extension of it consitutes all symbols. Stable filters must return this as a result of this method. The result of this method satisfies the following constrains:
  1. Result must be stable filter, that is result is null or result.toStableFilter() == result
  2. Result must be more encompasing, that is result is null or this.acceptRecord(...) implies result.acceptRecord(...).
  3. Result must be reconstructible from string, that is result is null or result.toString() must parse back to the same filter via data scheme's SubscriptionFilterFactory.

Specified by:
toStableFilter in interface StableSubscriptionFilter

toString

public java.lang.String toString()
Returns filter description -- its pattern.

Overrides:
toString in class java.lang.Object

acceptRecord

public boolean acceptRecord(DataRecord record,
                            int cipher,
                            java.lang.String symbol)
Description copied from interface: SubscriptionFilter
Determines if specified record shall be processed by corresponding subsystem.

Specified by:
acceptRecord in interface SubscriptionFilter
Returns:
true if the record should be processed; false if it should be ignored.