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 import org.minetti.astrodevice.common.coordinate.SexagesimalCoordinate;
8
9
10
11
12
13
14 @Embeddable
15 public final class EmbeddedSexagesimalCoordinate
16 implements Serializable {
17
18
19
20
21 private static final long serialVersionUID = 5380898268847795274L;
22
23
24
25
26 private int angle;
27
28
29
30
31 private int minutes;
32
33
34
35
36 private double seconds;
37
38
39
40
41 public EmbeddedSexagesimalCoordinate () {
42 super();
43 }
44
45
46
47
48
49
50
51 public EmbeddedSexagesimalCoordinate (final boolean hourAngle, final Coordinate coordinate) {
52 super();
53 final Coordinate convertedCoordinate = convert(hourAngle, coordinate);
54 this.angle = convertedCoordinate.getAngle();
55 this.minutes = convertedCoordinate.getMinutes();
56 this.seconds = convertedCoordinate.getSeconds();
57 }
58
59
60
61
62
63
64
65
66 private static Coordinate convert (final boolean hourAngle, final Coordinate coordinate) {
67 Coordinate result;
68 if (hourAngle == coordinate.isHourAngle()) {
69 result = coordinate;
70 }
71 else {
72 final double value = coordinate.getValue() / (coordinate.isHourAngle() ? 24.0 : 360.0) * (hourAngle ? 24.0 : 360.0);
73 result = new DecimalCoordinate(hourAngle, value);
74 }
75 return result;
76 }
77
78
79
80
81
82 public int getAngle () {
83 return this.angle;
84 }
85
86
87
88
89
90 public void setAngle (final int angle) {
91 this.angle = angle;
92 }
93
94
95
96
97
98 public int getMinutes () {
99 return this.minutes;
100 }
101
102
103
104
105
106 public void setMinutes (final int minutes) {
107 this.minutes = minutes;
108 }
109
110
111
112
113
114 public double getSeconds () {
115 return this.seconds;
116 }
117
118
119
120
121
122 public void setSeconds (double seconds) {
123 this.seconds = seconds;
124 }
125
126
127
128
129
130
131
132 public Coordinate toCoordinate (final boolean hourAngle) {
133 return new SexagesimalCoordinate(hourAngle, this.angle, this.minutes, this.seconds);
134 }
135
136
137
138
139
140 @Override
141 public String toString () {
142 return "EmbeddedSexagesimalCoordinate[angle=" + this.angle + ", minutes=" + this.minutes + ", seconds=" + this.seconds + "]";
143 }
144
145 }