-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList.java
95 lines (90 loc) · 3.3 KB
/
List.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
/**
* A list is a collection of objects that are sorted and can be
* accessed by index. The first element in the list is at index 0.
*
* A list can store objects of any kind, and they can be of different
* types: Integers, Doubles, String, or even other lists. However,
* this list cannot store null objects.
*
* There is no limit to the number of elements in the list (provided
* that there is free memory in the Java Virtual Machine).
*
* Not all operations on a list will always be successful. For
* example, a programmer may try to remove an element from an empty
* list, or from a position where there is nothing. Since we hace not
* covered exceptions yet, we need another mechanism to report
* errors. In order to do that, methods of this list will return a
* {@see ReturnObject} that will contain either an object or an error
* value of the right kind (as defined in {@see ErrorMessage}).
*
* @author PiJ
*/
public interface List {
/**
* Returns true if the list is empty, false otherwise.
*
* @return true if the list is empty, false otherwise.
*/
public boolean isEmpty();
/**
* Returns the number of items currently in the list.
*
* @return the number of items currently in the list
*/
public int size();
/**
* Returns the element at the given position.
*
* If the index is negative or greater or equal than the size of
* the list, then an appropriate error must be returned.
*
* @param index the position in the list of the item to be retrieved
* @return the element or an appropriate error message,
* encapsulated in a ReturnObject
*/
public ReturnObject get(int index);
/**
* Returns the elements at the given position and removes it
* from the list. The indeces of elements after the removed
* element must be updated accordignly.
*
* If the index is negative or greater or equal than the size of
* the list, then an appropriate error must be returned.
*
* @param index the position in the list of the item to be retrieved
* @return the element or an appropriate error message,
* encapsulated in a ReturnObject
*/
public ReturnObject remove(int index);
/**
* Adds an element to the list, inserting it at the given
* position. The indeces of elements at and after that position
* must be updated accordignly.
*
* If the index is negative or greater or equal than the size of
* the list, then an appropriate error must be returned.
*
* If a null object is provided to insert in the list, the
* request must be ignored and an appropriate error must be
* returned.
*
* @param index the position at which the item should be inserted in
* the list
* @param item the value to insert into the list
* @return an ReturnObject, empty if the operation is successful
* or containing an appropriate error message otherwise
*/
public ReturnObject add(int index, Object item);
/**
* Adds an element at the end of the list.
*
* If a null object is provided to insert in the list, the
* request must be ignored and an appropriate error must be
* returned.
*
* @param item the value to insert into the list
* @return an ReturnObject, empty if the operation is successful
* or containing an appropriate error message otherwise
*/
public ReturnObject add(Object item);
}