01: package com.db4o.f1.chapter4;
02:
03: import java.util.*;
04:
05: public class Car {
06: private String model;
07: private Pilot pilot;
08: private List history;
09:
10: public Car(String model) {
11: this .model = model;
12: this .pilot = null;
13: this .history = new ArrayList();
14: }
15:
16: public Pilot getPilot() {
17: return pilot;
18: }
19:
20: public void setPilot(Pilot pilot) {
21: this .pilot = pilot;
22: }
23:
24: public String getModel() {
25: return model;
26: }
27:
28: public SensorReadout[] getHistory() {
29: return (SensorReadout[]) history
30: .toArray(new SensorReadout[history.size()]);
31: }
32:
33: public void snapshot() {
34: history.add(new TemperatureSensorReadout(new Date(), this ,
35: "oil", pollOilTemperature()));
36: history.add(new TemperatureSensorReadout(new Date(), this ,
37: "water", pollWaterTemperature()));
38: history.add(new PressureSensorReadout(new Date(), this , "oil",
39: pollOilPressure()));
40: }
41:
42: protected double pollOilTemperature() {
43: return 0.1 * history.size();
44: }
45:
46: protected double pollWaterTemperature() {
47: return 0.2 * history.size();
48: }
49:
50: protected double pollOilPressure() {
51: return 0.3 * history.size();
52: }
53:
54: public String toString() {
55: return model + "[" + pilot + "]/" + history.size();
56: }
57: }
|