-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConversion.java
More file actions
56 lines (44 loc) · 1.31 KB
/
Conversion.java
File metadata and controls
56 lines (44 loc) · 1.31 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
54
55
56
package com.yurii.salimov.lesson08.task02;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author Yuriy Salimov (yuriy.alex.salimov@gmail.com)
* @version 1.0
*/
public final class Conversion<T> {
private final List<T> list;
public Conversion() {
this.list = new ArrayList<>();
}
public Conversion(final T[] elements) {
this.list = new ArrayList<>(Arrays.asList(elements));
}
@Override
public String toString() {
return "Conversion{list=" + this.list + '}';
}
public void add(final T element) {
this.list.add(element);
}
public void remove(final int index) throws IndexOutOfBoundsException {
checkIndex(index);
this.list.remove(index);
}
public void remove(final int from, final int to) throws IndexOutOfBoundsException {
checkIndex(from);
checkIndex(to);
this.list.subList(from, to).clear();
}
public void clear() {
this.list.clear();
}
public List getList() {
return this.list;
}
private void checkIndex(final int index) throws IndexOutOfBoundsException {
if ((index < 0) || (index > this.list.size())) {
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + list.size());
}
}
}