-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactory.java
115 lines (100 loc) · 3.77 KB
/
Factory.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
import java.util.NoSuchElementException;
public interface Factory {
/**
* Inserts {@code product} at the beginning of this factory line.
*
* @param product the product to add
*/
void addFirst(Product product);
/**
* Inserts {@code product} to the end of this factory line.
*
* @param product the product to add
*/
void addLast(Product product);
/**
* Removes and returns the first product from this factory line.
*
* @return the first product from this factory line
* @throws NoSuchElementException if the line is empty
*/
Product removeFirst() throws NoSuchElementException;
/**
* Removes and returns the first product from this factory line.
*
* @return the last product from this factory line
* @throws NoSuchElementException if the line is empty
*/
Product removeLast() throws NoSuchElementException;
/**
* Finds and returns the product with the specified {@code id}.
*
* @param id id of the product
* @return the product with the specified id
* @throws NoSuchElementException if the product does not exist
*/
Product find(int id) throws NoSuchElementException;
/**
* Updates the product value with {@code id} in this factory line
* with the given {@code newValue}.
*
* @param id id of the product to update
* @param value new value for the specified product
* @return the previous product with {@code id}
* @throws NoSuchElementException if the product does not exist
*/
Product update(int id, Integer value) throws NoSuchElementException;
/**
* Returns the product at the specified position in this factory line.
*
* @param index index of the product to return
* @return the product at the specified position in this factory line
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
Product get(int index) throws IndexOutOfBoundsException;
/**
* Insert the {@code product} at the specified position in this factory line.
* Shifts the products currently at and to the right of that position.
*
* @param index index at which the product is to be inserted
* @param product the product to be inserted
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
void add(int index, Product product) throws IndexOutOfBoundsException;
/**
* Removes and returns the product at the specified position in this
* factory line.
*
* @param index index of the product to remove
* @return the removed {@code product}
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
Product removeIndex(int index) throws IndexOutOfBoundsException;
/**
* Removes the first occurrence of the {@code product} with the
* specified {@code value} from this factory line. If this factory
* line does not contain a product with the specified {@code value},
* it is unchanged. More formally, removes the {@code product} with the
* lowest index {@code i} such that {@code product.getValue() == value}.
*
* @param value value of the {@code product} to be removed from
* this factory line, if present
* @return the removed {@code product}
* @throws NoSuchElementException if the product with the given
* {@code value} does not exist
*
*
*/
Product removeProduct(int value) throws NoSuchElementException;
/**
* Filters the factory line such that every duplicate product is removed.
* Duplicate products are products with the same value in this context.
*
* @return number of removed products
*/
int filterDuplicates();
/**
* Reverses the factory line.
*/
void reverse();
}