org.abora.white.tumbler
Class Sequence

java.lang.Object
  |
  +--org.abora.white.xpp.basic.Heaper
        |
        +--org.abora.white.spaces.basic.Position
              |
              +--org.abora.white.tumbler.Sequence

public class Sequence
extends Position

Represents an infinite sequence of integers (of which only a finite number can be non-zero). They are lexically ordered, and there is a "decimal point" between the numbers at -1 and 0. Implementation note: The array should have no zeros at either end, and noone else should have a pointer to it.


Field Summary
protected  PrimIntegerArray myNumbers
           
protected  IntegerValue myShift
           
protected static Sequence TheZero
           
 
Constructor Summary
Sequence(IntegerValue shift, PrimIntegerArray numbers)
           
Sequence(Rcvr receiver)
           
 
Method Summary
 int actualHashForEqual()
          since we redefine equal, subclasses had better redefine actualHashForEqual
 XnRegion asRegion()
          Essential.
 int comparePrefix(Sequence other, IntegerValue n)
          Compare my numbers up to and including index n with the corresponding numbers in the other Sequence.
 CoordinateSpace coordinateSpace()
          Essential.
 IntegerValue count()
          How many numbers in the sequence, not counting leading or trailing zeros
 Sequence first()
          The sequence consisting of all numbers in this one up to but not including the first zero, or the entire thing if there are no zeros
 IntegerValue firstIndex()
          The smallest index with a non-zero number.
 IntegerValue integerAt(IntegerValue index)
          The number at the given index in the Sequence.
 PrimIntegerArray integers()
          Essential.
 boolean isEqual(Heaper other)
          Return true if the two objects are equal.
 boolean isGE(Position other)
          Whether this sequence is greater than or equal to the other sequence, using a lexical comparison of their corresponding numbers.
 boolean isZero()
          Whether all the numbers in the sequence are zero
 IntegerValue lastIndex()
          The largest index with a non-zero number.
 Sequence minus(Sequence other)
          A sequence with the corresponding numbers subtracted from each other
static Sequence numbers(PrimIntegerArray digits)
           
static Sequence one(IntegerValue a)
          A single element Sequence
 Sequence plus(Sequence other)
          A sequence with the corresponding numbers added to each other
static void printArrayOn(java.io.PrintWriter oo, PrimIntegerArray numbers)
          Print a sequence of numbers separated by dots.
 void printOn(java.io.PrintWriter oo)
          This should rarely be overridden.
static void printOn(java.io.PrintWriter oo, IntegerValue shift, PrimIntegerArray numbers)
          Print a sequence of numbers separated by dots.
static void printZerosOn(java.io.PrintWriter oo, IntegerValue shift)
          Print a sequence of zeros separated by dots.
 Sequence rest()
          The sequence consisting of all numbers in this one after but not including the first zero, or a null sequence if there are no zeros
 PrimIntegerArray secretNumbers()
          The array itself, for internal use
 void sendSelfTo(Xmtr xmtr)
           
 IntegerValue shift()
          The amount by which the numbers are shifted.
 Sequence shift(IntegerValue offset)
          Shift the numbers by some number of places.
static Sequence string(java.lang.String string)
           
static Sequence three(IntegerValue a, IntegerValue b, IntegerValue c)
          A three element Sequence
static Sequence two(IntegerValue a, IntegerValue b)
          A two element Sequence
static Sequence usingx(IntegerValue shift, PrimIntegerArray numbers)
          Don't need to make a copy of the array
 Sequence with(IntegerValue index, IntegerValue number)
          Change a single element of the sequence.
 Sequence withFirst(IntegerValue number)
          A Sequence with all my numbers followed by the given one
 Sequence withLast(IntegerValue number)
          A Sequence with all my numbers followed by the given one
 Sequence withRest(Sequence other)
          A sequence containing all the numbers in this one, followed by the other one, separated by a single zero.
static Sequence zero()
           
 
Methods inherited from class org.abora.white.spaces.basic.Position
info
 
Methods inherited from class org.abora.white.xpp.basic.Heaper
destroy, destruct, equals, hashForEqual, printContentsOn, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myShift

protected IntegerValue myShift

myNumbers

protected PrimIntegerArray myNumbers

TheZero

protected static Sequence TheZero
Constructor Detail

Sequence

public Sequence(IntegerValue shift,
                PrimIntegerArray numbers)

Sequence

public Sequence(Rcvr receiver)
Method Detail

asRegion

public XnRegion asRegion()
Description copied from class: Position
Essential. A region containing this position as its only element.

Specified by:
asRegion in class Position

coordinateSpace

public CoordinateSpace coordinateSpace()
Description copied from class: Position
Essential. The coordinate space this is a position in. This implies that a position object is only a position in one particular coordinate space.

Specified by:
coordinateSpace in class Position

count

public IntegerValue count()
How many numbers in the sequence, not counting leading or trailing zeros


firstIndex

public IntegerValue firstIndex()
The smallest index with a non-zero number. Blasts if it is all zeros.


integerAt

public IntegerValue integerAt(IntegerValue index)
The number at the given index in the Sequence. Returns zeros beyond either end of the array.


integers

public PrimIntegerArray integers()
Essential. The numbers in this Sequence. This is a copy of the array, so you may modify it. Note that two Sequences which are isEqual, may actually have arrays of numbers which have different specs. Also, the array will not have any zeros at the beginning or end.


isZero

public boolean isZero()
Whether all the numbers in the sequence are zero


lastIndex

public IntegerValue lastIndex()
The largest index with a non-zero number. Blasts if it is all zeros.


shift

public IntegerValue shift()
The amount by which the numbers are shifted. Positive means less significant, negative means more significant. This is contrary to the usual arithmetic notions, but it is the right thing for arrays.


comparePrefix

public int comparePrefix(Sequence other,
                         IntegerValue n)
Compare my numbers up to and including index n with the corresponding numbers in the other Sequence. Return -1, 0 or 1 depending on whether they are <, =, or > the other.


actualHashForEqual

public int actualHashForEqual()
Description copied from class: Position
since we redefine equal, subclasses had better redefine actualHashForEqual

Overrides:
actualHashForEqual in class Position

isEqual

public boolean isEqual(Heaper other)
Description copied from class: Heaper
Return true if the two objects are equal.

Specified by:
isEqual in class Position

isGE

public boolean isGE(Position other)
Whether this sequence is greater than or equal to the other sequence, using a lexical comparison of their corresponding numbers.


secretNumbers

public PrimIntegerArray secretNumbers()
The array itself, for internal use


printOn

public void printOn(java.io.PrintWriter oo)
Description copied from class: Heaper
This should rarely be overridden. In Tofu, it prints ClassName(...), where ... is either produced by printInsideOn or is ??? if printInsideOn it not overridden.

Overrides:
printOn in class Heaper

first

public Sequence first()
The sequence consisting of all numbers in this one up to but not including the first zero, or the entire thing if there are no zeros


minus

public Sequence minus(Sequence other)
A sequence with the corresponding numbers subtracted from each other


plus

public Sequence plus(Sequence other)
A sequence with the corresponding numbers added to each other


rest

public Sequence rest()
The sequence consisting of all numbers in this one after but not including the first zero, or a null sequence if there are no zeros


shift

public Sequence shift(IntegerValue offset)
Shift the numbers by some number of places. Positive shifts make it less significant, negative shifts make it more significant.


with

public Sequence with(IntegerValue index,
                     IntegerValue number)
Change a single element of the sequence.


withFirst

public Sequence withFirst(IntegerValue number)
A Sequence with all my numbers followed by the given one


withLast

public Sequence withLast(IntegerValue number)
A Sequence with all my numbers followed by the given one


withRest

public Sequence withRest(Sequence other)
A sequence containing all the numbers in this one, followed by the other one, separated by a single zero.


sendSelfTo

public void sendSelfTo(Xmtr xmtr)
Overrides:
sendSelfTo in class Heaper

numbers

public static Sequence numbers(PrimIntegerArray digits)

one

public static Sequence one(IntegerValue a)
A single element Sequence


string

public static Sequence string(java.lang.String string)

three

public static Sequence three(IntegerValue a,
                             IntegerValue b,
                             IntegerValue c)
A three element Sequence


two

public static Sequence two(IntegerValue a,
                           IntegerValue b)
A two element Sequence


zero

public static Sequence zero()

printArrayOn

public static void printArrayOn(java.io.PrintWriter oo,
                                PrimIntegerArray numbers)
Print a sequence of numbers separated by dots. Deal with strings specially.


printOn

public static void printOn(java.io.PrintWriter oo,
                           IntegerValue shift,
                           PrimIntegerArray numbers)
Print a sequence of numbers separated by dots. Deal with strings specially.


printZerosOn

public static void printZerosOn(java.io.PrintWriter oo,
                                IntegerValue shift)
Print a sequence of zeros separated by dots. Deal with large numbers specially.


usingx

public static Sequence usingx(IntegerValue shift,
                              PrimIntegerArray numbers)
Don't need to make a copy of the array



Copyright © 2003 David G Jones. All Rights Reserved.
Original Udanax-Gold - Copyright © 1979-1999 Udanax.com. All rights reserved.