-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBufferNode.java
84 lines (82 loc) · 2.5 KB
/
BufferNode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* A node in a linked list that references a buffer, it's position in the file,
* and whether it has been changed or not.
* @author Joshua Rush (jdrush89)
* @author Benjamin Roble (broble)
* @version Nov 2, 2011
*/
public class BufferNode
{
//The buffer this node is associated with.
private Buffer myBuffer;
//A flag to keep track of whether or not the buffer has changed.
private boolean changed;
//The starting position of the buffer in the file (the byte #)
private long blockID;
//A constant to represent the starting position of an empty buffer.
private static final int EMPTY = -1;
/**
* Initialize the BufferNode, creating a new Buffer and setting the blockID
* and changed flag.
*/
public BufferNode() {
myBuffer = new Buffer();
blockID = EMPTY;
changed = false;
}
// ----------------------------------------------------------
/**
* Return the buffer associated with this BufferNode.
* @return the buffer
*/
public Buffer getBuffer()
{
return myBuffer;
}
// ----------------------------------------------------------
/**
* Set the buffer associated with this BufferNode.
* @param myBuffer the buffer to set
*/
public void setMyBuffer(Buffer myBuffer)
{
this.myBuffer = myBuffer;
}
// ----------------------------------------------------------
/**
* Return whether or not the buffer has been changed since it read in data.
* @return the whether the buffer has been changed
*/
public boolean isChanged()
{
return changed;
}
// ----------------------------------------------------------
/**
* Set whether the buffer in this node has been changed.
* @param changed whether the buffer has been changed
*/
public void setChanged(boolean changed)
{
this.changed = changed;
}
// ----------------------------------------------------------
/**
* Return the byte number where the data block starts for the buffer
* associated with this node.
* @return the blockID
*/
public long getBlockID()
{
return blockID;
}
// ----------------------------------------------------------
/**
* Set the byte position from the file where the data in this node's buffer starts.
* @param startReadingPosition the blockID to set
*/
public void setBlockID(long startReadingPosition)
{
this.blockID = startReadingPosition;
}
}