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
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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
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
-
CONSTANT_STRATEGY
- all values are the same;
deviations should generate an error.
-
DEFAULT_STRATEGY
- values are rarely different from the
initial value; deviants are indicated with a meta event.
-
REPEAT_STRATEGY
- values consist of long sequences of the
same value; new default values are indicated with a meta event.
- Throws:
IllegalArgumentException
- if strategy
is invalid.
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