-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayStore.java
More file actions
55 lines (44 loc) · 1021 Bytes
/
ArrayStore.java
File metadata and controls
55 lines (44 loc) · 1021 Bytes
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
import java.util.concurrent.atomic.AtomicInteger;
public class ArrayStore {
static AtomicInteger nextId = new AtomicInteger();
private int id;
private int size;
private int index;
int[] arrayStorage;
public ArrayStore(int size) {
// TODO Auto-generated constructor stub
this.setId(nextId.incrementAndGet());
this.setSize(size);
this.setIndex(0);
arrayStorage = new int[getSize()];
}
public boolean insert(int number) {
// TODO Auto-generated method stub
try{
arrayStorage[this.getIndex()] = number;
this.setIndex(this.index++);
return true;
}catch(Exception e){
e.printStackTrace();
return false;
}
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = nextId.incrementAndGet();
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
}