View Javadoc
1   package org.minetti.astrodevice.server.hibernate.object.embedded;
2   
3   import java.io.Serializable;
4   import javax.persistence.Embeddable;
5   import org.minetti.astrodevice.common.coordinate.Coordinate;
6   import org.minetti.astrodevice.common.coordinate.DecimalCoordinate;
7   
8   /**
9    * Object representing a coordinate stored as decimal format (embeddable class for Hibernate
10   * framework).
11   * @author Jean-Philippe MINETTI
12   */
13  @Embeddable
14  public final class EmbeddedDecimalCoordinate
15  		implements Serializable {
16  
17  	/**
18  	 * Serial number.
19  	 */
20  	private static final long serialVersionUID = -6494669290341787706L;
21  
22  	/**
23  	 * Full value of the coordinate in hours (h) or degrees (°).
24  	 */
25  	private double value;
26  
27  	/**
28  	 * Constructor.
29  	 */
30  	public EmbeddedDecimalCoordinate () {
31  		super();
32  	}
33  
34  	/**
35  	 * Constructor.
36  	 * @param hourAngle <code>TRUE</code> if the coordinate must be an hour angle and therefore
37  	 *            expressed in hours.
38  	 * @param coordinate Coordinate.
39  	 */
40  	public EmbeddedDecimalCoordinate (final boolean hourAngle, final Coordinate coordinate) {
41  		super();
42  		if (hourAngle == coordinate.isHourAngle()) {
43  			this.value = coordinate.getValue();
44  		}
45  		else {
46  			this.value = coordinate.getValue() / (coordinate.isHourAngle() ? 24.0 : 360.0) * (hourAngle ? 24.0 : 360.0);
47  		}
48  	}
49  
50  	/**
51  	 * Returns the full value of the coordinate in hours (h) or degrees (°).
52  	 * @return Full value of the coordinate.
53  	 */
54  	public double getValue () {
55  		return this.value;
56  	}
57  
58  	/**
59  	 * Sets the full value of the coordinate in hours (h) or degrees (°).
60  	 * @param value Full value of the coordinate.
61  	 */
62  	public void setValue (final double value) {
63  		this.value = value;
64  	}
65  
66  	/**
67  	 * Returns the coordinate.
68  	 * @param hourAngle <code>TRUE</code> if the coordinate must be an hour angle and therefore
69  	 *            expressed in hours.
70  	 * @return Coordinate.
71  	 */
72  	public Coordinate toCoordinate (final boolean hourAngle) {
73  		return new DecimalCoordinate(hourAngle, this.value);
74  	}
75  
76  	/*
77  	 * (non-Javadoc)
78  	 * @see java.lang.Object#toString()
79  	 */
80  	@Override
81  	public String toString () {
82  		return "EmbeddedDecimalCoordinate[value=" + this.value + "]";
83  	}
84  
85  }