-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStorageManager.java
120 lines (107 loc) · 3.29 KB
/
StorageManager.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package storage;
import java.io.IOException;
import java.util.Iterator;
/**
* A {@code StorageManager} manages a storage space.
*
* @author Jeong-Hyon Hwang (jhh@cs.albany.edu)
*
* @param <L>
* the type of locations of objects in the {@code StorageManager}
* @param <O>
* the type of objects managed by the {@code StorageManager}
*/
public interface StorageManager<L, O> {
/**
* Returns the first location in any file.
*
* @return the first location in any file.
*/
L first();
/**
* Adds the specified object in the specified file.
*
* @param fileID
* the ID of the file
* @param o
* the object to add
* @return the location of the object in the specified file
* @throws IOException
* if an I/O error occurs
*/
L add(int fileID, O o) throws IOException;
/**
* Puts the specified object at the specified location in the specified file.
*
* @param fileID
* the ID of the file
* @param location
* the location of the object
* @param o
* the object to put
* @return the object stored previously at the specified location in the specified file; {@code null} if no such
* object
* @throws IOException
* if an I/O error occurs
* @throws InvalidLocationException
* if an invalid location is given
*/
O put(int fileID, L location, O o) throws IOException, InvalidLocationException;
/**
* Returns the object at the specified location in the specified file.
*
* @param fileID
* the ID of the file
* @param location
* the location of the object
* @return the object at the specified location in the specified file
* @throws IOException
* if an I/O error occurs
* @throws InvalidLocationException
* if an invalid location is given
*/
O get(int fileID, L location) throws IOException, InvalidLocationException;
/**
* Removes the specified object at the specified location in the specified file.
*
* @param fileID
* the ID of the file
* @param location
* the location of the object
* @return the object stored previously at the specified location in the specified file; {@code null} if no such
* object
* @throws IOException
* if an I/O error occurs
* @throws InvalidLocationException
* if an invalid location is given
*/
O remove(int fileID, L location) throws IOException, InvalidLocationException;
/**
* Returns an iterator over all objects stored in the the specified file.
*
* @param fileID
* the ID of the file
* @return an iterator over all objects stored in the the specified file
*/
Iterator<Object> iterator(int fileID);
/**
* Removes all data from the specified file.
*
* @param fileID
* the ID of the file
* @throws IOException
* if an I/O error occurs
*/
void clear(int fileID) throws IOException;
/**
* An {@code InvalidLocationException} is thrown if an invalid location is used.
*
* @author Jeong-Hyon Hwang (jhh@cs.albany.edu)
*/
public class InvalidLocationException extends Exception {
/**
* Automatically generated serial version UID.
*/
private static final long serialVersionUID = 597318656808631892L;
}
}