PageMixer API - 3.1

jp.ne.dti.lares.foozy.pagemixer.mixer
Class SequenceTrimFilter

java.lang.Object
  |
  +--jp.ne.dti.lares.foozy.pagemixer.mixer.Filter
        |
        +--jp.ne.dti.lares.foozy.pagemixer.mixer.SequenceEditFilter
              |
              +--jp.ne.dti.lares.foozy.pagemixer.mixer.SequenceTrimFilter
All Implemented Interfaces:
Consumer
Direct Known Subclasses:
SequenceTrimFilter.Inside, SequenceTrimFilter.Whole

public abstract class SequenceTrimFilter
extends SequenceEditFilter

Abstraction of filter trimming token sequence.

This provieds control flow of sequence trimming.

If you want trim inside of or whole sequence, you can create specific filter by concretizing shouldTrim(ConsumerContext) method of SequenceTrimFilter.Inside or SequenceTrimFilter.Whole derived class. It must return true when you want trim given sequence, and to decide return value, it may examine execution context.

If you want trim in your specific manner (e.g.: trim only first or last token of sequence, and so on), you should define SequenceTrimFilter.Strategy implement class and make getStrategy(boolean) returning its instance when sequence should be trimmed.

You must concretize below method(s) to have this function.


Inner Class Summary
static class SequenceTrimFilter.Inside
          Trimming inside of sequence.
protected static interface SequenceTrimFilter.Strategy
          Strategy to handle tokens of sequence.
static class SequenceTrimFilter.Whole
          Trimming whole sequence.
 
Inner classes inherited from class jp.ne.dti.lares.foozy.pagemixer.mixer.Filter
Filter.Factory
 
Field Summary
protected  SequenceTrimFilter.Strategy DEFAULT
          Strategy to pass tokens through.
 
Constructor Summary
SequenceTrimFilter(SequenceWatcher watcher)
          Create sequence trimming filter.
 
Method Summary
protected  void beforeFirst(ConsumerContext context)
          Decide handling strategy for current processing.
protected abstract  SequenceTrimFilter.Strategy getStrategy(boolean trim)
          Get strategy to handle tokens.
protected  void onFirst(ConsumerContext context, Token token, boolean empty)
          Delegate processing of first token to strategy.
protected  void onInside(ConsumerContext context, Token token)
          Delegate processing of inside token to strategy.
protected  void onLast(ConsumerContext context, Token token, boolean empty)
          Delegate processing of last token to strategy.
protected abstract  boolean shouldTrim(ConsumerContext context)
          Examine which current sequence is interesting one or not.
 
Methods inherited from class jp.ne.dti.lares.foozy.pagemixer.mixer.SequenceEditFilter
afterLast, consume, flush
 
Methods inherited from class jp.ne.dti.lares.foozy.pagemixer.mixer.Filter
addCleanup, clear, connectTo, getConsumer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

protected final SequenceTrimFilter.Strategy DEFAULT
Strategy to pass tokens through.
Constructor Detail

SequenceTrimFilter

public SequenceTrimFilter(SequenceWatcher watcher)
Create sequence trimming filter.
Parameters:
watcher - watcher to identify target sub sequence.
Method Detail

shouldTrim

protected abstract boolean shouldTrim(ConsumerContext context)
Examine which current sequence is interesting one or not.

This method allow you to judge whether current sequence should be trimmed or not at execution time.

This method is invoked only once per one sequence, and result of it is passed to getStrategy(boolean).

Parameters:
context - context to depend on
Returns:
true if current sequence is interesting one

getStrategy

protected abstract SequenceTrimFilter.Strategy getStrategy(boolean trim)
Get strategy to handle tokens.

This method is invoked only once per one sequence, and result of it is used to handle tokens of sequence.

So SequenceTrimFilter.Strategy reduces overhead of judgement what filter should do.

Parameters:
trim - whether current sequence should be trimmed or not
Returns:
strategy to handle tokens

beforeFirst

protected void beforeFirst(ConsumerContext context)
Decide handling strategy for current processing.
Overrides:
beforeFirst in class SequenceEditFilter
Parameters:
context - conetxt to depend on

onFirst

protected void onFirst(ConsumerContext context,
                       Token token,
                       boolean empty)
Delegate processing of first token to strategy.
Overrides:
onFirst in class SequenceEditFilter
Parameters:
context - conetxt to depend on
token - token to be processed
empty - whether sequence has only one token or not

onInside

protected void onInside(ConsumerContext context,
                        Token token)
Delegate processing of inside token to strategy.
Overrides:
onInside in class SequenceEditFilter
Parameters:
context - conetxt to depend on
token - token to be processed

onLast

protected void onLast(ConsumerContext context,
                      Token token,
                      boolean empty)
Delegate processing of last token to strategy.
Overrides:
onLast in class SequenceEditFilter
Parameters:
context - conetxt to depend on
token - token to be processed
empty - whether sequence has only one token or not

PageMixer API - 3.1