2016-08-24 16:28:10 -06:00
|
|
|
// references/OceanReading.java
|
2016-12-30 17:23:13 -08:00
|
|
|
// (c)2017 MindView LLC: see Copyright.txt
|
2016-08-24 16:28:10 -06:00
|
|
|
// 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 OceanReading implements Cloneable {
|
|
|
|
private DepthReading depth;
|
|
|
|
private TemperatureReading temperature;
|
|
|
|
public
|
|
|
|
OceanReading(double tdata, double ddata) {
|
|
|
|
temperature = new TemperatureReading(tdata);
|
|
|
|
depth = new DepthReading(ddata);
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public OceanReading clone() {
|
|
|
|
OceanReading or = null;
|
|
|
|
try {
|
|
|
|
or = (OceanReading)super.clone();
|
|
|
|
} catch(CloneNotSupportedException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
// Must clone references:
|
|
|
|
or.depth = (DepthReading)or.depth.clone();
|
|
|
|
or.temperature =
|
|
|
|
(TemperatureReading)or.temperature.clone();
|
|
|
|
return or;
|
|
|
|
}
|
|
|
|
public TemperatureReading getTemperatureReading() {
|
|
|
|
return temperature;
|
|
|
|
}
|
|
|
|
public void
|
|
|
|
setTemperatureReading(TemperatureReading tr) {
|
|
|
|
temperature = tr;
|
|
|
|
}
|
|
|
|
public DepthReading getDepthReading() {
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
public void setDepthReading(DepthReading dr) {
|
|
|
|
this.depth = dr;
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "temperature: " + temperature +
|
|
|
|
", depth: " + depth;
|
|
|
|
}
|
|
|
|
}
|