ec9c5755bdb6c22f3d00e9f4916018cee2877ee0
[des2015.git] / mart / ev3 / ex2 / nl / ru / des / bluetooth / ColorMemory.java
1 package nl.ru.des.bluetooth;
2
3 import java.util.Arrays;
4 import java.util.HashSet;
5 import java.util.List;
6 import java.util.Set;
7
8 import lejos.robotics.Color;
9 import nl.ru.des.LCDPrinter;
10
11 public class ColorMemory implements MessageHandler {
12 public static final List<Integer> COLORSTOFIND = Arrays.asList(new Integer[] {Color.BLUE, Color.RED, Color.YELLOW});
13 private Set<Integer> colors;
14
15 public ColorMemory() {
16 colors = new HashSet<Integer>();
17 }
18
19 @Override
20 public void handleMessage(String message) {
21 colors.add(Integer.valueOf(message));
22 LCDPrinter.print(message + " received");
23 LCDPrinter.print(colors.toString());
24 }
25
26 public boolean finished() {
27 return colors.containsAll(COLORSTOFIND);
28 }
29
30 public void addColor(int current) {
31 BTController.sendMessage(Integer.toString(current));
32 colors.add(current);
33 LCDPrinter.print(current + " found");
34 LCDPrinter.print(colors.toString());
35 }
36 }