-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbehaviour.java
More file actions
68 lines (52 loc) · 1.65 KB
/
behaviour.java
File metadata and controls
68 lines (52 loc) · 1.65 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
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
public class Trades {
enum Pairs {
EURJPY(19), AUDJPY(25), OILUSD(290), USDJPY(400);
private final int profit;
Pairs(int profit) {
this.profit = profit;
}
public int getProfit() {
return profit;
}
}
public interface TradesPredicate {
boolean test(Trades trades);
}
public static class MuchLow implements TradesPredicate {
public boolean test(Trades trades) {
return trades.getProfit() < 50;
}
}
public static class Higher implements TradesPredicate {
public boolean test(Trades trades) {
return trades.getProfit() > 100;
}
}
public static List<Trades> filterTrades(List<Trades> inventory, TradesPredicate p) {
List<Trades> result = new ArrayList<>();
for (Trades trades : inventory) {
if (p.test(trades)) {
result.add(trades);
}
}
return result;
}
public static void main(String[] args) {
List<Trades> inventory = new ArrayList<>();
inventory.add(new Trades( Pairs.USDJPY.getProfit()));
inventory.add(new Trades( Pairs.OILUSD.getProfit()));
List<Trades> good = filterTrades(inventory, new Higher());
for(Trades trade:good){
System.out.println("Better profit is " + trade.getProfit());}
}
private int profit;
public Trades(int profit) {
this.profit =profit; // Example initialization, modify as needed
}
public int getProfit() {
return profit;
}
}