step.encoding
Class ConstantStrategy

java.lang.Object
  |
  +--step.encoding.Encoder
        |
        +--step.encoding.Strategy
              |
              +--step.encoding.RegularValueStrategy
                    |
                    +--step.encoding.ConstantStrategy
Direct Known Subclasses:
PConstantStrategy

public class ConstantStrategy
extends RegularValueStrategy

Assume values are mostly the same. If the value remains constant, there is no need to write anything to the output. The decoder simply returns the default value instead of reading from the input.

The "constant" variant of the algorithm throws an exception if an irregular value is encountered. The "default" variant allows deviations from the initial value, signalling the irregularity with an IrregularValueEvent. The "repeat" variant shifts to a new default every time the value differs from the previous, signalling the change with an IrregularValueEvent.

Algorithm:

 if current == default
     then -> nothing
     else if constant
         then ERROR!
         else -> meta:IrregularValueEvent, current
 


Field Summary
static int CONSTANT_STRATEGY
           
static String CONSTANT_STRATEGY_NAME
           
static int DEFAULT_STRATEGY
           
static String DEFAULT_STRATEGY_NAME
           
static int REPEAT_STRATEGY
           
static String REPEAT_STRATEGY_NAME
           
 
Fields inherited from class step.encoding.RegularValueStrategy
_nextIsRegular
 
Fields inherited from class step.encoding.Strategy
_baseEncoder
 
Constructor Summary
ConstantStrategy(Encoder baseEncoder, int strategy)
          Create a new constant value strategy.
 
Method Summary
 StepObject decode(DecodeContext context)
          Decode a constant value.
 void dump(int level)
           
 void encode(StepObject o, EncodeContext context)
          Encode a constant value.
protected  int getStrategyVariant()
           
 
Methods inherited from class step.encoding.RegularValueStrategy
setNextIsRegular
 
Methods inherited from class step.encoding.Strategy
baseDecode, baseEncode, eventMessage
 
Methods inherited from class step.encoding.Encoder
getFactory, getName, indent, makeFieldName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONSTANT_STRATEGY_NAME

public static final String CONSTANT_STRATEGY_NAME
See Also:
Constant Field Values

DEFAULT_STRATEGY_NAME

public static final String DEFAULT_STRATEGY_NAME
See Also:
Constant Field Values

REPEAT_STRATEGY_NAME

public static final String REPEAT_STRATEGY_NAME
See Also:
Constant Field Values

CONSTANT_STRATEGY

public static final int CONSTANT_STRATEGY
See Also:
Constant Field Values

DEFAULT_STRATEGY

public static final int DEFAULT_STRATEGY
See Also:
Constant Field Values

REPEAT_STRATEGY

public static final int REPEAT_STRATEGY
See Also:
Constant Field Values
Constructor Detail

ConstantStrategy

public ConstantStrategy(Encoder baseEncoder,
                        int strategy)
Create a new constant value strategy.

Parameters:
baseEncoder - the encoder for the values passed to this strategy.
strategy - one of
Throws:
IllegalArgumentException - if strategy is invalid.
Method Detail

getStrategyVariant

protected int getStrategyVariant()

encode

public void encode(StepObject o,
                   EncodeContext context)
            throws EncoderException,
                   IOException
Encode a constant value.

Specified by:
encode in class Encoder
Throws:
EncoderException - if the value is different from the default (initial) value and the "constant" option is set.
IOException - if the encode operation encountered an I/O failure.

decode

public StepObject decode(DecodeContext context)
                  throws EncoderException,
                         IOException
Decode a constant value.

Specified by:
decode in class Encoder
Throws:
IOException - if the decode operation encountered an I/O failure.
EncoderException - if the decode operation encountered an error.

dump

public void dump(int level)
Specified by:
dump in class Encoder