View Javadoc

1   package org.minetti.astrodevice.server.hibernate.object;
2   
3   import java.io.Serializable;
4   import java.util.Locale;
5   import javax.persistence.AttributeOverride;
6   import javax.persistence.AttributeOverrides;
7   import javax.persistence.Column;
8   import javax.persistence.Embedded;
9   import javax.persistence.Entity;
10  import javax.persistence.GeneratedValue;
11  import javax.persistence.Id;
12  import javax.persistence.Table;
13  import javax.persistence.UniqueConstraint;
14  import org.hibernate.annotations.Index;
15  import org.minetti.astrodevice.common.coordinate.Coordinate;
16  import org.minetti.astrodevice.common.coordinate.format.CoordinateFormat;
17  import org.minetti.astrodevice.server.core.object.CelestialLimitPoint;
18  import org.minetti.astrodevice.server.hibernate.object.embedded.EmbeddedDecimalCoordinate;
19  
20  /**
21   * Object representing a point of the celestial limit used to delimit the visible portion of the
22   * sky.
23   * @author Jean-Philippe MINETTI
24   */
25  @Table(name = "CELESTIAL_LIMIT_POINT", uniqueConstraints = { @UniqueConstraint(name = "K_COORDINATES", columnNames = { "OBSERVING_SITE_ID", "AZIMUTH", "ALTITUDE" }) })
26  @org.hibernate.annotations.Table(appliesTo = "CELESTIAL_LIMIT_POINT", indexes = { @Index(name = "K_POINT_ORDER", columnNames = { "OBSERVING_SITE_ID", "POINT_ORDER" }) })
27  @Entity
28  public final class CelestialLimitPointImpl
29  		implements CelestialLimitPoint, Serializable {
30  
31  	/**
32  	 * Serial number.
33  	 */
34  	private static final long serialVersionUID = -7005400402941378347L;
35  
36  	/**
37  	 * Identifier given to point of the celestial limit.
38  	 */
39  	@Id
40  	@GeneratedValue
41  	@Column(name = "ID", nullable = false)
42  	private Long id = null;
43  
44  	/**
45  	 * Order of point in the celestial limit.
46  	 */
47  	@Column(name = "POINT_ORDER", nullable = false)
48  	private int order;
49  
50  	/**
51  	 * Azimuth A of the celestial position in degrees (°).
52  	 */
53  	@Embedded
54  	@AttributeOverrides({ @AttributeOverride(name = "value", column = @Column(name = "AZIMUTH", nullable = false)) })
55  	private EmbeddedDecimalCoordinate embeddedAzimuth;
56  
57  	/**
58  	 * Altitude a of the celestial position in degrees (°).
59  	 */
60  	@Embedded
61  	@AttributeOverrides({ @AttributeOverride(name = "value", column = @Column(name = "ALTITUDE", nullable = false)) })
62  	private EmbeddedDecimalCoordinate embeddedAltitude;
63  
64  	/**
65  	 * Constructor.
66  	 */
67  	public CelestialLimitPointImpl () {
68  		super();
69  	}
70  
71  	/**
72  	 * Constructor.
73  	 * @param celestialLimitPoint Point of the celestial limit.
74  	 */
75  	public CelestialLimitPointImpl (final CelestialLimitPoint celestialLimitPoint) {
76  		super();
77  		this.id = celestialLimitPoint.getId();
78  		this.order = celestialLimitPoint.getOrder();
79  		this.embeddedAzimuth = (celestialLimitPoint.getAzimuth() != null ? new EmbeddedDecimalCoordinate(false, celestialLimitPoint.getAzimuth()) : null);
80  		this.embeddedAltitude = (celestialLimitPoint.getAltitude() != null ? new EmbeddedDecimalCoordinate(false, celestialLimitPoint.getAltitude()) : null);
81  	}
82  
83  	/*
84  	 * (non-Javadoc)
85  	 * @see org.minetti.astrodevice.server.core.object.CelestialLimitPoint#getId()
86  	 */
87  	public Long getId () {
88  		return this.id;
89  	}
90  
91  	/*
92  	 * (non-Javadoc)
93  	 * @see org.minetti.astrodevice.server.core.object.CelestialLimitPoint#getOrder()
94  	 */
95  	public int getOrder () {
96  		return this.order;
97  	}
98  
99  	/*
100 	 * (non-Javadoc)
101 	 * @see org.minetti.astrodevice.server.core.object.CelestialLimitPoint#setOrder(int)
102 	 */
103 	public void setOrder (final int order) {
104 		this.order = order;
105 	}
106 
107 	/*
108 	 * (non-Javadoc)
109 	 * @see org.minetti.astrodevice.server.core.object.HorizontalCoordinates#getAzimuth()
110 	 */
111 	public Coordinate getAzimuth () {
112 		return (this.embeddedAzimuth != null ? this.embeddedAzimuth.toCoordinate(false) : null);
113 	}
114 
115 	/*
116 	 * (non-Javadoc)
117 	 * @see org.minetti.astrodevice.server.core.object.HorizontalCoordinates#getAltitude()
118 	 */
119 	public Coordinate getAltitude () {
120 		return (this.embeddedAltitude != null ? this.embeddedAltitude.toCoordinate(false) : null);
121 	}
122 
123 	/*
124 	 * (non-Javadoc)
125 	 * @see java.lang.Object#hashCode()
126 	 */
127 	@Override
128 	public int hashCode () {
129 		return this.order;
130 	}
131 
132 	/*
133 	 * (non-Javadoc)
134 	 * @see java.lang.Object#equals(java.lang.Object)
135 	 */
136 	@Override
137 	public boolean equals (final Object obj) {
138 		boolean result = false;
139 		if (obj == this) {
140 			result = true;
141 		}
142 		else if (obj instanceof CelestialLimitPoint) {
143 			result = (((CelestialLimitPoint) obj).getOrder() == this.order);
144 		}
145 		return result;
146 	}
147 
148 	/*
149 	 * (non-Javadoc)
150 	 * @see java.lang.Object#toString()
151 	 */
152 	@Override
153 	public String toString () {
154 		return "Point " + this.order + " (A = " + CoordinateFormat.getSexagesimalAzimuthInstance(Locale.getDefault(), 60).format(getAzimuth()) + ", a = "
155 				+ CoordinateFormat.getSexagesimalAltitudeInstance(Locale.getDefault(), 60).format(getAltitude()) + ")";
156 	}
157 
158 }