-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoundedBuffer.java
More file actions
53 lines (37 loc) · 1.04 KB
/
BoundedBuffer.java
File metadata and controls
53 lines (37 loc) · 1.04 KB
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
public class BoundedBuffer {
static int[] buffer;
static int last = 0;
static int first = 0;
static int size;
public BoundedBuffer(int length) {
size = length;
buffer = new int[length] ;
}
public static void decrementLast(){
last=last-1;
}
public static void augmentLast(){
last=last+1;
}
public static int getValue(){
decrementLast();
System.out.println("Pos at getValue: "+(last));
return buffer[last];
}
public static void addValue(int data){
buffer[last]=data;
augmentLast();
System.out.println("Pos at addValue: "+(last));
}
public static int getPosition(){
return last;
}
public static boolean isFull(){
System.out.println("Is Full: "+(last==size));
return last==size;
}
public static boolean isEmpty(){
System.out.println("Is Empty: "+(last==-1));
return last==-1;
}
}