2016-08-24 16:28:10 -06:00
|
|
|
// references/TemperatureReading.java
|
|
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
2016-09-23 13:23:35 -06:00
|
|
|
// Visit http://OnJava8.com for more book information.
|
2016-08-24 16:28:10 -06:00
|
|
|
// Cloning a composed object
|
|
|
|
package references;
|
|
|
|
|
|
|
|
public class TemperatureReading implements Cloneable {
|
|
|
|
private long time;
|
|
|
|
private double temperature;
|
|
|
|
public TemperatureReading(double temperature) {
|
|
|
|
time = System.currentTimeMillis();
|
|
|
|
this.temperature = temperature;
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public TemperatureReading clone() {
|
|
|
|
try {
|
|
|
|
return (TemperatureReading)super.clone();
|
|
|
|
} catch(CloneNotSupportedException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public double getTemperature() {
|
|
|
|
return temperature;
|
|
|
|
}
|
|
|
|
public void setTemperature(double temp) {
|
|
|
|
this.temperature = temp;
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return String.valueOf(temperature);
|
|
|
|
}
|
|
|
|
}
|