public class FieldRecord
extends java.lang.Object
Checkpoint
) denoting the time when the value was
recorded, as well as that old value of the field.
It is possible the records of a field have more than zero dimension, when the field is an array. In that case, records of different dimensions are stored in different tables. E.g., an int is considered zero-dimensional, and only one list is used to store its change history. an int[] is considered one-dimensional (with one possible index). Two lists are used in order to record assignments to the array itself, and the assignment to one of its element. In the latter case, the index of the changed element is also recorded. Similarly, a field of type int[][] requires three lists.
Lists of records are added with different add functions, which take a timestamp and record the old value taken at that timestamp at the head position of the corresponding list. Timestamps must be increasing. A value with larger timestamp means it is taken later in time.
To access the lists, iterators must be used to iterate from the most recent recorded value to the earliest ones. Records in the lists may also be removed with remove functions of the iterators. As with many other iterators, modifications cannot be made simultaneously with two different iterators. add functions cannot be called while accessing any list with an iterator, either. If changes are made simultaneously, the effect is unpredictable.
Modifier and Type | Class and Description |
---|---|
class |
FieldRecord.CombinedIterator
Combined iterator of all the dimensions.
|
class |
FieldRecord.IndividualIterator
Iterator of the records for the given dimension.
|
class |
FieldRecord.Record
Record of an old value.
|
protected static class |
FieldRecord.RecordList
Double linked list of records.
|
Constructor and Description |
---|
FieldRecord()
Construct a zero-dimensional (scalar) field record.
|
FieldRecord(int dimensions)
Construct a multi-dimensional field record.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_addRecord(int index,
FieldRecord.Record record)
Add a record to the list at the given index.
|
protected boolean |
_deepCopyArray(java.lang.Object source,
java.lang.Object destination)
Perform a deep copy from a source array to a destination array.
|
protected FieldRecord.Record |
_findRecord(java.util.Iterator recordListIterator,
long timestamp,
boolean trim)
Find the record with the smallest timestamp that is larger than the
given timestamp.
|
protected FieldRecordState |
_getTopState()
Get the state on the top of the states stack.
|
protected java.lang.Object |
_restoreField(java.lang.Object field,
FieldRecord.Record record)
Restore the old value in a record to the field.
|
void |
add(boolean value,
long timestamp)
Add an old value to the records, associated with a timestamp.
|
void |
add(byte value,
long timestamp)
Add an old value to the records, associated with a timestamp.
|
void |
add(char value,
long timestamp)
Add an old value to the records, associated with a timestamp.
|
void |
add(double value,
long timestamp)
Add an old value to the records, associated with a timestamp.
|
void |
add(float value,
long timestamp)
Add an old value to the records, associated with a timestamp.
|
void |
add(int[] indices,
boolean value,
long timestamp)
Add an old value to the specified indices of the records, and
associate it with a timestamp.
|
void |
add(int[] indices,
byte value,
long timestamp)
Add an old value to the specified indices of the records, and
associate it with a timestamp.
|
void |
add(int[] indices,
char value,
long timestamp)
Add an old value to the specified indices of the records, and
associate it with a timestamp.
|
void |
add(int[] indices,
double value,
long timestamp)
Add an old value to the specified indices of the records, and
associate it with a timestamp.
|
void |
add(int[] indices,
float value,
long timestamp)
Add an old value to the specified indices of the records, and
associate it with a timestamp.
|
void |
add(int[] indices,
int value,
long timestamp)
Add an old value to the specified indices of the records, and
associate it with a timestamp.
|
void |
add(int[] indices,
long value,
long timestamp)
Add an old value to the specified indices of the records, and
associate it with a timestamp.
|
void |
add(int[] indices,
java.lang.Object value,
long timestamp)
Add an old value to the specified indices of the records, and
associate it with a timestamp.
|
void |
add(int[] indices,
short value,
long timestamp)
Add an old value to the specified indices of the records, and
associate it with a timestamp.
|
void |
add(int value,
long timestamp)
Add an old value to the records, associated with a timestamp.
|
void |
add(long value,
long timestamp)
Add an old value to the records, associated with a timestamp.
|
void |
add(java.lang.Object value,
long timestamp)
Add an old value to the records, associated with a timestamp.
|
void |
add(short value,
long timestamp)
Add an old value to the records, associated with a timestamp.
|
void |
backup(int[] indices,
java.lang.Object array,
long timestamp)
Backup the values in an array, and associate the record with a
timestamp.
|
void |
backup(java.lang.Object array,
long timestamp)
Backup the values in an array, and associate the record with a
timestamp.
|
static void |
commit(FieldRecord[] records,
long timestamp,
long topStackTimestamp)
Commit the changes in all the FieldRecord objects up to the
time represented by the timestamp.
|
void |
commit(long timestamp)
Commit the changes up to the time represented by the timestamp.
|
void |
commitState()
Commit the state of this field record, and delete older states in its
stack.
|
java.util.Iterator |
iterator()
Return the iterator of all the records.
|
java.util.Iterator |
iterator(int index)
Return the iterator of the records with the specified index.
|
void |
popState()
Pop out the top state in the states stack, and the state next to it
becomes the top state.
|
static void |
popState(FieldRecord[] records)
For each state in the given array, pop out the top state.
|
void |
pushState()
Push a new state onto the top of the states stack, and the current top
state becomes the one right below it.
|
static void |
pushState(FieldRecord[] records)
For each state in the given array, push in a new state.
|
boolean |
restore(boolean current,
long timestamp,
boolean trim)
Restore the old value at the timestamp to the field.
|
byte |
restore(byte current,
long timestamp,
boolean trim)
Restore the old value at the timestamp to the field.
|
char |
restore(char current,
long timestamp,
boolean trim)
Restore the old value at the timestamp to the field.
|
double |
restore(double current,
long timestamp,
boolean trim)
Restore the old value at the timestamp to the field.
|
float |
restore(float current,
long timestamp,
boolean trim)
Restore the old value at the timestamp to the field.
|
int |
restore(int current,
long timestamp,
boolean trim)
Restore the old value at the timestamp to the field.
|
long |
restore(long current,
long timestamp,
boolean trim)
Restore the old value at the timestamp to the field.
|
java.lang.Object |
restore(java.lang.Object current,
long timestamp,
boolean trim)
Restore the old value at the timestamp to the field.
|
short |
restore(short current,
long timestamp,
boolean trim)
Restore the old value at the timestamp to the field.
|
public FieldRecord()
public FieldRecord(int dimensions)
dimensions
- Number of dimensions; can be omitted
when it is 1.public void add(java.lang.Object value, long timestamp)
value
- The old value.timestamp
- The current timestamp to be associated with the
old value.add(int[], Object, long)
public void add(boolean value, long timestamp)
value
- The old value.timestamp
- The current timestamp to be associated with the
old value.add(int[], boolean, long)
public void add(byte value, long timestamp)
value
- The old value.timestamp
- The current timestamp to be associated with the
old value.add(int[], byte, long)
public void add(char value, long timestamp)
value
- The old value.timestamp
- The current timestamp to be associated with the
old value.add(int[], char, long)
public void add(double value, long timestamp)
value
- The old value.timestamp
- The current timestamp to be associated with the
old value.add(int[], double, long)
public void add(float value, long timestamp)
value
- The old value.timestamp
- The current timestamp to be associated with the
old value.add(int[], float, long)
public void add(int value, long timestamp)
value
- The old value.timestamp
- The current timestamp to be associated with the
old value.add(int[], int, long)
public void add(int[] indices, java.lang.Object value, long timestamp)
buf[1][2][3] = new char[10];
If the indices array is null, it is assumed that no index is needed.
indices
- The indices.value
- The old value.timestamp
- The current timestamp to be associated with the
old value.public void add(int[] indices, boolean value, long timestamp)
buf[1][2][3] = new char[10];
If the indices array is null, it is assumed that no index is needed.
indices
- The indices.value
- The old value.timestamp
- The current timestamp to be associated with the
old value.public void add(int[] indices, byte value, long timestamp)
buf[1][2][3] = new char[10];
If the indices array is null, it is assumed that no index is needed.
indices
- The indices.value
- The old value.timestamp
- The current timestamp to be associated with the
old value.public void add(int[] indices, char value, long timestamp)
buf[1][2][3] = new char[10];
If the indices array is null, it is assumed that no index is needed.
indices
- The indices.value
- The old value.timestamp
- The current timestamp to be associated with the
old value.public void add(int[] indices, double value, long timestamp)
buf[1][2][3] = new char[10];
If the indices array is null, it is assumed that no index is needed.
indices
- The indices.value
- The old value.timestamp
- The current timestamp to be associated with the
old value.public void add(int[] indices, float value, long timestamp)
buf[1][2][3] = new char[10];
If the indices array is null, it is assumed that no index is needed.
indices
- The indices.value
- The old value.timestamp
- The current timestamp to be associated with the
old value.public void add(int[] indices, int value, long timestamp)
buf[1][2][3] = new char[10];
If the indices array is null, it is assumed that no index is needed.
indices
- The indices.value
- The old value.timestamp
- The current timestamp to be associated with the
old value.public void add(int[] indices, long value, long timestamp)
buf[1][2][3] = new char[10];
If the indices array is null, it is assumed that no index is needed.
indices
- The indices.value
- The old value.timestamp
- The current timestamp to be associated with the
old value.public void add(int[] indices, short value, long timestamp)
buf[1][2][3] = new char[10];
If the indices array is null, it is assumed that no index is needed.
indices
- The indices.value
- The old value.timestamp
- The current timestamp to be associated with the
old value.public void add(long value, long timestamp)
value
- The old value.timestamp
- The current timestamp to be associated with the
old value.add(int[], long, long)
public void add(short value, long timestamp)
value
- The old value.timestamp
- The current timestamp to be associated with the
old value.add(int[], short, long)
public void backup(java.lang.Object array, long timestamp)
array
- The array.timestamp
- The current timestamp to be associated with the
old value.public void backup(int[] indices, java.lang.Object array, long timestamp)
indices
- The indices.array
- The array.timestamp
- The current timestamp to be associated with the
old value.public static void commit(FieldRecord[] records, long timestamp, long topStackTimestamp)
records
- The array of field records.timestamp
- The timestamp.topStackTimestamp
- The timestamp taken when the checkpoint object
was assigned.commit(long)
,
CheckpointRecord.getTopTimestamp()
public void commit(long timestamp)
timestamp
- The timestamp.public void commitState()
Old states of field records are kept when a new checkpoint object is assigned to a monitored object. This function deletes those old states, but keep only the last (current) state.
popState()
,
pushState()
public java.util.Iterator iterator()
Iterator.next()
.iterator(int)
public java.util.Iterator iterator(int index)
index
- The index.iterator()
public void popState()
public static void popState(FieldRecord[] records)
records
- The array of field records.popState()
public void pushState()
public static void pushState(FieldRecord[] records)
records
- The array of field records.pushState()
public java.lang.Object restore(java.lang.Object current, long timestamp, boolean trim)
The given timestamp refers to the time when the field still possesses its old value. If the timestamp is increased at an assignment, the old value at that timestamp refers to the value of the field before assignment.
current
- The current value of the field.timestamp
- The timestamp.trim
- If true, any values newer than the restored value
are deleted from the record.public boolean restore(boolean current, long timestamp, boolean trim)
The given timestamp refers to the time when the field still possesses its old value. If the timestamp is increased at an assignment, the old value at that timestamp refers to the value of the field before assignment.
current
- The current value of the field.timestamp
- The timestamp.trim
- If true, any values newer than the restored value
are deleted from the record.public byte restore(byte current, long timestamp, boolean trim)
The given timestamp refers to the time when the field still possesses its old value. If the timestamp is increased at an assignment, the old value at that timestamp refers to the value of the field before assignment.
current
- The current value of the field.timestamp
- The timestamp.trim
- If true, any values newer than the restored value
are deleted from the record.public char restore(char current, long timestamp, boolean trim)
The given timestamp refers to the time when the field still possesses its old value. If the timestamp is increased at an assignment, the old value at that timestamp refers to the value of the field before assignment.
current
- The current value of the field.timestamp
- The timestamp.trim
- If true, any values newer than the restored value
are deleted from the record.public double restore(double current, long timestamp, boolean trim)
The given timestamp refers to the time when the field still possesses its old value. If the timestamp is increased at an assignment, the old value at that timestamp refers to the value of the field before assignment.
current
- The current value of the field.timestamp
- The timestamp.trim
- If true, any values newer than the restored value
are deleted from the record.public float restore(float current, long timestamp, boolean trim)
The given timestamp refers to the time when the field still possesses its old value. If the timestamp is increased at an assignment, the old value at that timestamp refers to the value of the field before assignment.
current
- The current value of the field.timestamp
- The timestamp.trim
- If true, any values newer than the restored value
are deleted from the record.public int restore(int current, long timestamp, boolean trim)
The given timestamp refers to the time when the field still possesses its old value. If the timestamp is increased at an assignment, the old value at that timestamp refers to the value of the field before assignment.
current
- The current value of the field.timestamp
- The timestamp.trim
- If true, any values newer than the restored value
are deleted from the record.public long restore(long current, long timestamp, boolean trim)
The given timestamp refers to the time when the field still possesses its old value. If the timestamp is increased at an assignment, the old value at that timestamp refers to the value of the field before assignment.
current
- The current value of the field.timestamp
- The timestamp.trim
- If true, any values newer than the restored value
are deleted from the record.public short restore(short current, long timestamp, boolean trim)
The given timestamp refers to the time when the field still possesses its old value. If the timestamp is increased at an assignment, the old value at that timestamp refers to the value of the field before assignment.
current
- The current value of the field.timestamp
- The timestamp.trim
- If true, any values newer than the restored value
are deleted from the record.protected void _addRecord(int index, FieldRecord.Record record)
index
- The index.record
- The record.protected boolean _deepCopyArray(java.lang.Object source, java.lang.Object destination)
source
- The source array.destination
- The destination array.protected FieldRecord.Record _findRecord(java.util.Iterator recordListIterator, long timestamp, boolean trim)
recordListIterator
- The iterator with which the records are
searched.timestamp
- The timestamp.trim
- If true, the records found with timestamps equal
to or larger than the given timestamp are deleted.protected FieldRecordState _getTopState()
protected java.lang.Object _restoreField(java.lang.Object field, FieldRecord.Record record)
field
- The field to be restored.record
- The record.