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
22
23
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
33
34 private static final long serialVersionUID = -7005400402941378347L;
35
36
37
38
39 @Id
40 @GeneratedValue
41 @Column(name = "ID", nullable = false)
42 private Long id = null;
43
44
45
46
47 @Column(name = "POINT_ORDER", nullable = false)
48 private int order;
49
50
51
52
53 @Embedded
54 @AttributeOverrides({ @AttributeOverride(name = "value", column = @Column(name = "AZIMUTH", nullable = false)) })
55 private EmbeddedDecimalCoordinate embeddedAzimuth;
56
57
58
59
60 @Embedded
61 @AttributeOverrides({ @AttributeOverride(name = "value", column = @Column(name = "ALTITUDE", nullable = false)) })
62 private EmbeddedDecimalCoordinate embeddedAltitude;
63
64
65
66
67 public CelestialLimitPointImpl () {
68 super();
69 }
70
71
72
73
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
85
86
87 public Long getId () {
88 return this.id;
89 }
90
91
92
93
94
95 public int getOrder () {
96 return this.order;
97 }
98
99
100
101
102
103 public void setOrder (final int order) {
104 this.order = order;
105 }
106
107
108
109
110
111 public Coordinate getAzimuth () {
112 return (this.embeddedAzimuth != null ? this.embeddedAzimuth.toCoordinate(false) : null);
113 }
114
115
116
117
118
119 public Coordinate getAltitude () {
120 return (this.embeddedAltitude != null ? this.embeddedAltitude.toCoordinate(false) : null);
121 }
122
123
124
125
126
127 @Override
128 public int hashCode () {
129 return this.order;
130 }
131
132
133
134
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
150
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 }