Constructor and Description |
---|
Page(Relation relation,
PageIdentifier pageId)
Creates a new page given its schema and page identifier.
|
Modifier and Type | Method and Description |
---|---|
void |
addTuple(Tuple tuple)
Adds a new tuple to the page.
|
boolean |
canSubstitute(int index,
Tuple nt)
Checks whether the specified index can be substituted for the
new tuple.
|
int |
getNumberOfTuples()
Returns the number of occupied tuples of this page.
|
PageIdentifier |
getPageIdentifier()
Retrieves the ID of this page
|
Relation |
getRelation()
Returns the relation this page conforms to.
|
boolean |
hasRoom(Tuple t)
Checks whether this page has room for one more tuple.
|
java.util.Iterator<Tuple> |
iterator()
Returns an iterator over this page.
|
Tuple |
retrieveTuple(int index)
Retrieves the specified tuple from the page.
|
void |
setTuple(int index,
Tuple tuple)
Sets the specified tuple.
|
void |
swap(int x,
int y)
Swaps two tuples by their indexes.
|
java.lang.String |
toString()
Returns a textual representation of the page.
|
public Page(Relation relation, PageIdentifier pageId)
relation
- the relation this page conforms to.pageId
- the ID of this page.public Relation getRelation()
public boolean hasRoom(Tuple t)
trueif there is room for one more tuple on this page,
falseotherwise.
public int getNumberOfTuples()
public void addTuple(Tuple tuple) throws java.lang.ArrayIndexOutOfBoundsException
tuple
- the new tuple.java.lang.ArrayIndexOutOfBoundsException
- thrown whenever the page
boundaries are crossed.public void setTuple(int index, Tuple tuple) throws java.lang.ArrayIndexOutOfBoundsException, java.lang.IllegalArgumentException
index
- the index of the tuple to be changed.tuple
- the new tuple.java.lang.ArrayIndexOutOfBoundsException
- thrown whenever the page
boundaries are crossed.java.lang.IllegalArgumentException
- if the new tuple does not fit
into the page.public boolean canSubstitute(int index, Tuple nt) throws java.lang.ArrayIndexOutOfBoundsException
index
- the index of the tuple to be changed.nt
- the new tuple.java.lang.ArrayIndexOutOfBoundsException
- whenever the referenced
index does not exist.public void swap(int x, int y) throws java.lang.ArrayIndexOutOfBoundsException
x
- the first index.y
- the second index.java.lang.ArrayIndexOutOfBoundsException
- whenever any of the
referenced indexes do not exist.public Tuple retrieveTuple(int index) throws java.lang.ArrayIndexOutOfBoundsException
index
- the index of the tuple to be retrieved.java.lang.ArrayIndexOutOfBoundsException
- thrown whenever there
is an error in the indexing.public PageIdentifier getPageIdentifier()
public java.util.Iterator<Tuple> iterator()
iterator
in interface java.lang.Iterable<Tuple>
public java.lang.String toString()
toString
in class java.lang.Object