Package com.github.tommyettinger.random
Class LongSequence
java.lang.Object
com.github.tommyettinger.random.LongSequence
- All Implemented Interfaces:
Externalizable
,Serializable
A very basic append-only list of
long
items.
This is used to store the sequence of results used by a KnownSequenceRandom
, and
can be produced by an ArchivalWrapper
.- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionlong[]
static final LongSequence
This is a special single instance of a subclass of LongSequence; it doesn't store anything, and can't have itsget(int)
method called.int
-
Constructor Summary
ConstructorDescriptionLongSequence
(int initialCapacity) LongSequence
(long[] longs) LongSequence
(LongSequence other) -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(long item) appendSerialized
(StringBuilder sb, com.github.tommyettinger.digital.Base base) void
clear()
copy()
boolean
long
get
(int index) int
hashCode()
void
The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.void
resize
(int newCapacity) int
size()
stringDeserialize
(String data) stringDeserialize
(String data, com.github.tommyettinger.digital.Base base) stringSerialize
(com.github.tommyettinger.digital.Base base) toString()
static LongSequence
with
(long item) static LongSequence
with
(long... items) void
The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.
-
Field Details
-
items
public long[] items -
size
public int size -
NO_OP
This is a special single instance of a subclass of LongSequence; it doesn't store anything, and can't have itsget(int)
method called. Theadd(long)
method does nothing here, and won't cause any memory to be allocated. This can be useful to assign to theArchivalWrapper.archive
field when you don't want it to do anything beyond a normal generator; then you can assign a "real" LongSequence when you want to start storing.
-
-
Constructor Details
-
LongSequence
public LongSequence() -
LongSequence
public LongSequence(int initialCapacity) -
LongSequence
-
LongSequence
public LongSequence(long[] longs)
-
-
Method Details
-
get
public long get(int index) Gets thelong
item atindex
, which must be at least 0 and less thansize
. This does not do any bounds checking beyond a possibleArrayIndexOutOfBoundsException
that will be thrown if you give an index that is negative or greater thanitems.length
(the capacity). If you request an index betweensize
anditems.length
, this will return 0.- Parameters:
index
- which item to retrieve; must be at least 0 and less thansize
- Returns:
- the item at the specified index
-
add
public void add(long item) -
size
public int size() -
resize
public void resize(int newCapacity) -
clear
public void clear() -
copy
-
toString
-
equals
-
hashCode
public int hashCode() -
appendSerialized
-
appendSerialized
-
stringSerialize
-
stringSerialize
-
stringDeserialize
-
stringDeserialize
-
with
-
with
-
writeExternal
The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.- Specified by:
writeExternal
in interfaceExternalizable
- Parameters:
out
- the stream to write the object to- Throws:
IOException
- Includes any I/O exceptions that may occur
-
readExternal
The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.- Specified by:
readExternal
in interfaceExternalizable
- Parameters:
in
- the stream to read data from in order to restore the object- Throws:
IOException
- if I/O errors occur
-