de.dante.extex.interpreter.type.count
Class Count

java.lang.Object
  extended byde.dante.extex.interpreter.type.count.Count
All Implemented Interfaces:
FixedCount, java.io.Serializable
Direct Known Subclasses:
ImmutableCount, TCount

public class Count
extends java.lang.Object
implements java.io.Serializable, FixedCount

This class represents a long integer value. It is used for instance as count register.

Version:
$Revision: 1.33 $
Author:
Gerd Neugebauer, Michael Niedermair
See Also:
Serialized Form

Field Summary
static Count ONE
          The constant ONE contains the count register with the value 1.
protected static long serialVersionUID
          The constant serialVersionUID contains the id for serialization.
static Count THOUSAND
          The constant THOUSAND contains the count register with the value 1000.
static Count ZERO
          The constant ZERO contains the count register with the value 0.
 
Constructor Summary
Count(FixedCount count)
          Creates a new object.
Count(long value)
          Creates a new object.
 
Method Summary
 void add(long val)
          Add a long to the value.
 void divide(long denom)
          Divide the value by a long.
 boolean eq(FixedCount count)
          Compare the value for equality.
 boolean ge(FixedCount count)
          Compare the value for a greater or equal value.
protected  Localizer getLocalizer()
          Getter for the localizer.
 long getValue()
          Getter for the value
 boolean gt(FixedCount count)
          Compare the value for a greater value.
 boolean le(FixedCount count)
          Compare the value for a less or equal value.
 boolean lt(FixedCount count)
          Compare the value for a lesser value.
 void multiply(long factor)
          Multiply the value with a factor.
 boolean ne(FixedCount count)
          Compare the value for non-equality.
static Count parse(Context context, TokenSource source, Typesetter typesetter)
          parse a token stream for a count value.
static long scanInteger(Context context, TokenSource source, Typesetter typesetter)
          Scan the input stream for tokens making up an integer, this is a number optionally preceded by a sign (+ or -).
static long scanNumber(Context context, TokenSource source, Typesetter typesetter)
          Scan the input stream for tokens making up a number, i.e.
static long scanNumber(Context context, TokenSource source, Typesetter typesetter, Token token)
          Scan the input stream for tokens making up a number, this is a sequence of digits with category code OTHER.
 void set(long l)
          Setter for the value.
 void setValue(long l)
          Setter for the value.
 java.lang.String toString()
          Determine the printable representation of the object.
 void toString(java.lang.StringBuffer sb)
          Determine the printable representation of the object.
 Tokens toToks(Context context)
          Determine the printable representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ONE

public static final Count ONE
The constant ONE contains the count register with the value 1. This count register is in fact immutable.


serialVersionUID

protected static final long serialVersionUID
The constant serialVersionUID contains the id for serialization.

See Also:
Constant Field Values

THOUSAND

public static final Count THOUSAND
The constant THOUSAND contains the count register with the value 1000. This count register is in fact immutable.


ZERO

public static final Count ZERO
The constant ZERO contains the count register with the value 0. This count register is in fact immutable.

Constructor Detail

Count

public Count(FixedCount count)
Creates a new object.

Parameters:
count - the reference to be copied

Count

public Count(long value)
Creates a new object.

Parameters:
value - the value
Method Detail

scanInteger

public static long scanInteger(Context context,
                               TokenSource source,
                               Typesetter typesetter)
                        throws InterpreterException
Scan the input stream for tokens making up an integer, this is a number optionally preceded by a sign (+ or -). The number can be preceded by optional white space. White space is also ignored between the sign and the number. All non-whitespace characters must have the category code OTHER.

This method parses the following syntactic entity:

A Number

   ⟨number⟩ 

A number consists of a non-empty sequence of digits with category code OTHER. The number is optionally preceded by white space and a sign + or -.

Tokens are expanded while gathering the requested values.

Parameters:
context - the processor context
source - the source for new tokens
typesetter - the typesetter to use for conversion
Returns:
the value of the count
Throws:
InterpreterException - in case of an error

scanNumber

public static long scanNumber(Context context,
                              TokenSource source,
                              Typesetter typesetter)
                       throws InterpreterException
Scan the input stream for tokens making up a number, i.e. a sequence of digits with category code OTHER. The number can be preceded by optional white space.

This method implements the generalization of several syntactic definitions from TeX:

A Number

   ⟨number⟩ 

A number consists of a non-empty sequence of digits with category code OTHER.

Scan the input stream for tokens making up a number, this is a sequence of digits with category code OTHER. The number can be preceded by optional white space. Alternate representations for an integer exist.

Parameters:
context - the processor context
source - the source for new tokens
typesetter - the typesetter
Returns:
the value of the integer scanned
Throws:
InterpreterException - in case that no number is found or the end of file has been reached before an integer could be acquired

scanNumber

public static long scanNumber(Context context,
                              TokenSource source,
                              Typesetter typesetter,
                              Token token)
                       throws InterpreterException
Scan the input stream for tokens making up a number, this is a sequence of digits with category code OTHER. The number can be preceded by optional white space. Alternate representations for an integer exist.

Parameters:
context - the processor context
source - the source for new tokens
typesetter - the typesetter
token - the first token
Returns:
the value of the integer scanned
Throws:
InterpreterException - in case that no number is found or the end of file has been reached before an integer could be acquired

parse

public static Count parse(Context context,
                          TokenSource source,
                          Typesetter typesetter)
                   throws InterpreterException
parse a token stream for a count value.

Parameters:
context - the processor context
source - the source for new tokens
typesetter - the typesetter
Returns:
a new Count instance with the value acquired
Throws:
InterpreterException - in case of an error

add

public void add(long val)
Add a long to the value. This operation modifies the value.

Parameters:
val - the value to add to

divide

public void divide(long denom)
            throws ArithmeticOverflowException
Divide the value by a long. This operation modifies the value.

Parameters:
denom - the denominator to divide by
Throws:
ArithmeticOverflowException - in case of a division by zero

eq

public boolean eq(FixedCount count)
Description copied from interface: FixedCount
Compare the value for equality.

Specified by:
eq in interface FixedCount
Parameters:
count - the count to compare to
Returns:
true iff count has an equal value to the current one
See Also:
FixedCount.eq( de.dante.extex.interpreter.type.count.FixedCount)

ge

public boolean ge(FixedCount count)
Description copied from interface: FixedCount
Compare the value for a greater or equal value.

Specified by:
ge in interface FixedCount
Parameters:
count - the count to compare to
Returns:
true iff count has an value greater or equal to the current one
See Also:
FixedCount.ge( de.dante.extex.interpreter.type.count.FixedCount)

getLocalizer

protected Localizer getLocalizer()
Getter for the localizer. The localizer is initialized from the name of the Count class.

Returns:
the localizer

getValue

public long getValue()
Getter for the value

Specified by:
getValue in interface FixedCount
Returns:
the value

gt

public boolean gt(FixedCount count)
Description copied from interface: FixedCount
Compare the value for a greater value.

Specified by:
gt in interface FixedCount
Parameters:
count - the count to compare to
Returns:
true iff count has an value greater than the current one
See Also:
FixedCount.gt( de.dante.extex.interpreter.type.count.FixedCount)

le

public boolean le(FixedCount count)
Description copied from interface: FixedCount
Compare the value for a less or equal value.

Specified by:
le in interface FixedCount
Parameters:
count - the count to compare to
Returns:
true iff count has an value less or equal to the current one
See Also:
FixedCount.le( de.dante.extex.interpreter.type.count.FixedCount)

lt

public boolean lt(FixedCount count)
Description copied from interface: FixedCount
Compare the value for a lesser value.

Specified by:
lt in interface FixedCount
Parameters:
count - the count to compare to
Returns:
true iff count has an value less than the current one
See Also:
FixedCount.lt( de.dante.extex.interpreter.type.count.FixedCount)

multiply

public void multiply(long factor)
Multiply the value with a factor. This operation modifies the value.

Parameters:
factor - the factor to multiply with

ne

public boolean ne(FixedCount count)
Description copied from interface: FixedCount
Compare the value for non-equality.

Specified by:
ne in interface FixedCount
Parameters:
count - the count to compare to
Returns:
true iff count has an value not equal to the current one
See Also:
FixedCount.ne( de.dante.extex.interpreter.type.count.FixedCount)

set

public void set(long l)
Setter for the value.

Parameters:
l - the new value
See Also:
setValue(long)

setValue

public void setValue(long l)
Setter for the value.

Parameters:
l - the new value
See Also:
set(long)

toString

public java.lang.String toString()
Determine the printable representation of the object. The value returned is exactly the string which would be produced by TeX to print the Count.

Specified by:
toString in interface FixedCount
Returns:
the printable representation
See Also:
toString(StringBuffer)

toString

public void toString(java.lang.StringBuffer sb)
Determine the printable representation of the object. The value returned is exactly the string which would be produced by TeX to print the Count.

Specified by:
toString in interface FixedCount
Parameters:
sb - the target string buffer
See Also:
toString()

toToks

public Tokens toToks(Context context)
              throws InterpreterException
Determine the printable representation of the object. The value returned is exactly the string which would be produced by TeX to print the Count.

Specified by:
toToks in interface FixedCount
Parameters:
context - the interpreter context
Returns:
the Tokens representing this instance
Throws:
InterpreterException - in case of an error