-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManager.java
More file actions
158 lines (118 loc) · 4.27 KB
/
Manager.java
File metadata and controls
158 lines (118 loc) · 4.27 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package patterns.delegation.office;
import java.util.ArrayList;
import java.util.Collection;
import java.util.function.BinaryOperator;
public class Manager implements Employee{
private int count;
Printer printer = new Printer();
Clerk clerk = new Clerk(printer);
private int resourceCount = 1;
private Collection<Employee> workEmployees = new ArrayList<>();
Manager(Collection<Employee> employees){
if (employees.isEmpty()) {
throw new IllegalArgumentException("Kan ikke være tom");
}
else {
this.workEmployees = employees;
}
}
private Employee getEmployee() {
return workEmployees.stream().min((e1,e2) -> e1.getTaskCount()-e1.getTaskCount())
.get();
}
@Override
public double doCalculations(BinaryOperator<Double> operation, double value1, double value2) {
count++;
Employee employee = getEmployee();
return employee.doCalculations(operation, value1, value2);
}
@Override
public void printDocument(String document) {
Employee employee = getEmployee();
count++;
employee.printDocument(document);
}
@Override
public int getTaskCount() {
return this.count;
}
@Override
public int getResourceCount() {
for (Employee employee : workEmployees) {
resourceCount += employee.getResourceCount();
}
return resourceCount;
}
public static void main(String[] args) {
final BinaryOperator<Double> function = new BinaryOperator<Double>() {
public Double apply(final Double x, final Double y) {
return Double.valueOf((x + y));
}
};
final BinaryOperator<Double> function1 = new BinaryOperator<Double>() {
public Double apply(final Double x, final Double y) {
return Double.valueOf((x * y));
}
};
final BinaryOperator<Double> function2 = new BinaryOperator<Double>() {
public Double apply(final Double x, final Double y) {
return Double.valueOf((x / y));
}
};
Printer printer = new Printer();
Clerk clerk = new Clerk(printer);
Clerk clerk1 = new Clerk(printer);
Clerk clerk2= new Clerk(printer);
Clerk clerk3 = new Clerk(printer);
Collection<Employee> workers = new ArrayList<>();
workers.add(clerk);
workers.add(clerk1);
workers.add(clerk2);
workers.add(clerk3);
Manager manager = new Manager(workers);
manager.printDocument("a");
manager.printDocument("b");
manager.printDocument("c");
manager.printDocument("d");
manager.printDocument("e");
manager.printDocument("f");
manager.printDocument("g");
manager.printDocument("h");
manager.printDocument("i");
manager.doCalculations(function, 3, 5);
manager.doCalculations(function1, 3, 5);
manager.doCalculations(function2, 10,5);
System.out.println("Vanlig manager "+manager.getResourceCount());
System.out.println("Vanlig manager "+manager.getTaskCount());
System.out.println("Uten mellomledere: " + Double.valueOf(manager.getTaskCount() / Double.valueOf(manager.getResourceCount())));
Printer printer1 = new Printer();
Clerk clerk4 = new Clerk(printer1);
Clerk clerk5 = new Clerk(printer1);
Clerk clerk6 = new Clerk(printer1);
Clerk clerk7 = new Clerk(printer1);
Collection<Employee> workers1 = new ArrayList<>();
workers1.add(clerk4);
workers1.add(clerk5);
workers1.add(clerk6);
workers1.add(clerk7);
Collection<Employee> managers = new ArrayList<>();
Manager manager1 = new Manager(workers);
managers.add(manager);
managers.add(manager1);
Manager superManager = new Manager(managers);
superManager.printDocument("f");
superManager.printDocument("g");
superManager.printDocument("h");
superManager.printDocument("i");
superManager.printDocument("j");
superManager.printDocument("k");
superManager.printDocument("l");
superManager.printDocument("m");
superManager.doCalculations(function, 3, 5);
superManager.doCalculations(function1, 3, 5);
superManager.doCalculations(function2, 10,5);
System.out.println("Supermanager "+ superManager.getTaskCount());
System.out.println("Supermanager "+ superManager.getResourceCount());
System.out.println("Med mellomledere: " + Double.valueOf(superManager.getTaskCount() / Double.valueOf(superManager.getResourceCount())));
}
}