1 package sensorpoint;
2
3 import java.util.Collection;
4 import java.util.Set;
5 import java.util.Map;
6 import java.util.HashMap;
7 import java.util.Iterator;
8
12 import point.Point; import sensor.Sensor; public class SensorPoint extends Point {
15
16 private Map<String,Sensor> sensors;
18
19 public SensorPoint(double l, double b, double z) {
20 super(l,b,z);
21 sensors = new HashMap<String,Sensor>();
22 }
23
24 public void addSensor(Sensor s) {
26 sensors.put(s.getName(),s);
27 }
28
29 public void listSensors() {
31 Set<String> names = sensors.keySet();
32 Iterator<String> sit = names.iterator();
33 String s;
34 System.out.print("all sensors:");
35 while (sit.hasNext()) {
36 s = sit.next();
37 System.out.print(" " + s);
38 }
39 System.out.println();
40 }
41
42 public void listSensorsV2() {
44 System.out.print("all sensors:");
45 for (String s: sensors.keySet())
46 System.out.print(" " + s);
47 System.out.println();
48 }
49
50 public void readSensor(String s) {
52 sensors.get(s).read();
53 }
54
55 public void print() {
57 System.out.println("point at position "+ this +":");
58 Collection<Sensor> sensors = this.sensors.values();
59 Iterator<Sensor> sit = sensors.iterator();
60 Sensor s;
61 while (sit.hasNext()) {
62 s = sit.next();
63 System.out.println(" <" + s.getName() + ", " +
64 ( s.getDate() !=null ? s.getDate() : "" ) + ", " +
65 s.getValue() + ">");
66 }
67 }
68
69 public void printV2() {
71 System.out.println("point at position "+ this +":");
72 for (Sensor s: sensors.values())
73 System.out.println(" <" + s.getName() + ", " +
74 ( s.getDate() !=null ? s.getDate() : "" ) + ", " +
75 s.getValue() + ">");
76 }
77
78 }
79