-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarketImpl.java
More file actions
84 lines (72 loc) · 2.04 KB
/
MarketImpl.java
File metadata and controls
84 lines (72 loc) · 2.04 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
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
package market;
import datastructures.StockImpl;
import domain.Agent;
import domain.producttypes.Product;
import domain.producttypes.RawMaterial.Origin;
import goods.Pencil;
import goods.RawGraphite;
import goods.RawPlastic;
import java.util.Optional;
import org.checkerframework.checker.nullness.qual.Raw;
public class MarketImpl implements Market {
private StockImpl<Pencil> pencils;
private StockImpl<Product> disposed;
private StockImpl<RawGraphite> newRawGraphite;
private StockImpl<RawGraphite> recycledRawGraphite;
private StockImpl<RawPlastic> newRawPlastic;
private StockImpl<RawPlastic> recycledRawPlastic;
public MarketImpl() {
pencils = new StockImpl<>();
disposed = new StockImpl<>();
newRawGraphite = new StockImpl<>();
recycledRawGraphite = new StockImpl<>();
newRawPlastic = new StockImpl<>();
recycledRawPlastic = new StockImpl<>();
}
@Override
public void sellRawPlastic(RawPlastic item, Agent agent) {
if (item.origin == Origin.NEW) {
newRawPlastic.push(item, agent);
} else {
recycledRawPlastic.push(item, agent);
}
}
@Override
public Optional<RawPlastic> buyRawPlastic() {
if (recycledRawPlastic.size() == 0) {
return newRawPlastic.pop();
}
return recycledRawPlastic.pop();
}
@Override
public void sellRawGraphite(RawGraphite item, Agent agent) {
if (item.origin == Origin.NEW) {
newRawGraphite.push(item, agent);
} else {
recycledRawGraphite.push(item, agent);
}
}
@Override
public Optional<RawGraphite> buyRawGraphite() {
if (recycledRawGraphite.size() == 0) {
return newRawGraphite.pop();
}
return recycledRawGraphite.pop();
}
@Override
public void sellPencil(Pencil item, Agent agent) {
pencils.push(item, agent);
}
@Override
public Optional<Pencil> buyPencil() {
return pencils.pop();
}
@Override
public void disposePencil(Pencil item, Agent agent) {
disposed.push(item, agent);
}
@Override
public Optional<Product> collectDisposedGood() {
return disposed.pop();
}
}