1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.magicproject.tools;
22
23 import java.util.ArrayList;
24
25 /***
26 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
27 * @since 0.82
28 */
29 public class IntegerList extends ArrayList<Integer> {
30
31 /***
32 * Create a new instance of this class.
33 */
34 public IntegerList() {
35 super();
36 }
37
38 /***
39 * Returns a shallow copy of this <tt>ArrayList</tt> instance. (The elements
40 * themselves are not copied.)
41 *
42 * @return a clone of this <tt>ArrayList</tt> instance.
43 */
44 @Override
45 public IntegerList clone() {
46 IntegerList v = (IntegerList) super.clone();
47 return v;
48 }
49
50 /***
51 * Return the last int of the list.
52 *
53 * @return the last int of the list.
54 */
55 public int getLastInt() {
56 return super.get(size() - 1).intValue();
57 }
58
59 /***
60 * Return the first int of the list.
61 *
62 * @return the first int of the list.
63 */
64 public int getFirstInt() {
65 return super.get(0).intValue();
66 }
67
68 /***
69 * Returns the element at the specified position in this list.
70 *
71 * @param index
72 * index of element to return.
73 * @return the element at the specified position in this list.
74 */
75 public int getInt(int index) {
76 return super.get(index).intValue();
77 }
78
79 /***
80 * Appends the specified element to the end of this list.
81 *
82 * @param value
83 * element to be appended to this list.
84 */
85 public void addInt(int value) {
86 super.add(new Integer(value));
87 }
88
89 /***
90 * Inserts the specified element at the specified position in this list.
91 * Shifts the element currently at that position (if any) and any subsequent
92 * elements to the right (adds one to their indices).
93 *
94 * @param index
95 * index at which the specified element is to be inserted.
96 * @param value
97 * element to be inserted.
98 */
99 public void addInt(int index, int value) {
100 super.add(index, new Integer(value));
101 }
102
103 /***
104 * Removes the element at the last position in this list. Shifts any
105 * subsequent elements to the left (subtracts one from their indices).
106 *
107 * @return the element that was removed from the list.
108 */
109 public int removeLastInt() {
110 return super.remove(size() - 1).intValue();
111 }
112
113 /***
114 * Removes the element at the first position in this list. Shifts any
115 * subsequent elements to the left (subtracts one from their indices).
116 *
117 * @return the element that was removed from the list.
118 */
119 public int removeFirstInt() {
120 return remove(0).intValue();
121 }
122
123 /***
124 * Removes the element at the specified position in this list. Shifts any
125 * subsequent elements to the left (subtracts one from their indices).
126 *
127 * @param index
128 * the index of the element to removed.
129 * @return the element that was removed from the list.
130 */
131 public int removeInt(int index) {
132 return super.remove(index).intValue();
133 }
134 }