21
21
import static org .swisseph .api .ISweConstants .*;
22
22
import static org .swisseph .api .ISweJulianDate .*;
23
23
import static swisseph .SweConst .ERR ;
24
- import static swisseph .SweConst .SE_GREG_CAL ;
25
24
26
25
/**
26
+ * {@link ISwissEph} is a wrapper interface to the Swiss Ephemeris API defined in {@link SwephExp}.
27
+ * It also adds default factory methods to create and initialize {@link ISweJulianDate}
28
+ * which is a wrapper for different date/time fields needed for datetime presentation.
29
+ * <br><br>
30
+ * This interface has two implementations: Native {@link SwephNative}, which is the default one
31
+ * and pure Java {@link swisseph.SwissEph}, which was created by:
32
+ * Thomas Mack (http://th-mack.de/international/download/index.html)
33
+ * <br><br>
34
+ * {@link ISwissEph} is the object that may hold resources (such as file handles) until it is closed.
35
+ * The close() method of an AutoCloseable object is called automatically when exiting a try-with-resources block.
36
+ *
27
37
* @author Yura
28
- * @version 1.0, 2020-05
38
+ * @version 1.1, 2021-12
29
39
*/
30
- public interface ISwissEph extends Serializable {
40
+ public interface ISwissEph extends Serializable , AutoCloseable {
41
+ /**
42
+ * @return SweConst.SE_GREG_CAL if julDay relates to Gregorian calendar date (>= October 15, 1582),
43
+ * else returns SweConst.SE_JUL_CAL if julDay relates to Julian calendar (< October 15, 1582)
44
+ */
45
+ static int getCalendarType (final double julDay ) {
46
+ return julDay >= JD_GC0 ? SweConst .SE_GREG_CAL : SweConst .SE_JUL_CAL ;
47
+ }
31
48
32
49
/**
33
50
* @return true if it is the native implementation
@@ -36,8 +53,12 @@ default boolean isNativeAPI() {
36
53
return true ;
37
54
}
38
55
39
- static int getCalendarType (final double julDay ) {
40
- return julDay >= JD_GC0 ? SweConst .SE_GREG_CAL : SweConst .SE_JUL_CAL ;
56
+ /**
57
+ * Closes this resource, relinquishing any underlying resources (close Swiss Ephemeris).
58
+ * This method is invoked automatically on objects managed by the try-with-resources statement.
59
+ */
60
+ default void close () {
61
+ swe_close ();
41
62
}
42
63
43
64
default ISweJulianDate getJulianDate (final double julDay ) {
@@ -48,8 +69,8 @@ default ISweJulianDate getJulianDate(final double julDay, final double timeZone)
48
69
return initJulianDate (new SweJulianDate (julDay , timeZone ));
49
70
}
50
71
51
- default ISweJulianDate getJulianDate (final int [] date , final boolean gregorianCalendar , final double timeZone ) {
52
- return initJulianDate (new SweJulianDate (date , gregorianCalendar , timeZone ));
72
+ default ISweJulianDate getJulianDate (final int [] date , final double timeZone ) {
73
+ return initJulianDate (new SweJulianDate (date , timeZone ));
53
74
}
54
75
55
76
default ISweJulianDate getJulianDate (final Calendar calendar ) {
@@ -68,7 +89,7 @@ default ISweJulianDate getJulianDate(final Calendar calendar, final double timeZ
68
89
calendar .get (MILLISECOND )
69
90
};
70
91
71
- return initJulianDate (new SweJulianDate (datetime , true , timeZone ));
92
+ return initJulianDate (new SweJulianDate (datetime , timeZone ));
72
93
}
73
94
74
95
/**
@@ -338,7 +359,7 @@ default ISweJulianDate swe_revjul(double jd, int gregflag) {
338
359
final int [] yearMonDay = new int [3 ];
339
360
340
361
SwephExp .swe_revjul (jd , gregflag , yearMonDay , utime );
341
- return new SweJulianDate (jd , yearMonDay , utime [0 ], SE_GREG_CAL == gregflag );
362
+ return new SweJulianDate (jd , yearMonDay , utime [0 ]);
342
363
}
343
364
344
365
default ISweJulianDate swe_utc_to_jd (int year , int month , int day , int hour , int min , double sec , int gregflag , StringBuilder serr ) {
@@ -355,7 +376,7 @@ default ISweJulianDate swe_utc_to_jd(int year, int month, int day, int hour, int
355
376
// dret[1] = Julian day number UT1
356
377
357
378
return new SweJulianDate (dret [1 ], new int []{year , month , day ,
358
- hour , min , (int ) sec }, time , SE_GREG_CAL == gregflag );
379
+ hour , min , (int ) sec }, time );
359
380
}
360
381
361
382
default ISweJulianDate swe_jdet_to_utc (double tjd_et , int gregflag ) {
@@ -369,7 +390,7 @@ default ISweJulianDate swe_jdet_to_utc(double tjd_et, int gregflag) {
369
390
time += (outYearMonthDayHourMin [IDXI_MINUTE ] / d60 );
370
391
time += (outDsec [0 ] / d3600 );
371
392
372
- return new SweJulianDate (tjd_et , outYearMonthDayHourMin , time , SE_GREG_CAL == gregflag );
393
+ return new SweJulianDate (tjd_et , outYearMonthDayHourMin , time );
373
394
}
374
395
375
396
default ISweJulianDate swe_jdut1_to_utc (double tjd_ut , int gregflag ) {
@@ -383,7 +404,7 @@ default ISweJulianDate swe_jdut1_to_utc(double tjd_ut, int gregflag) {
383
404
time += (outYearMonthDayHourMin [IDXI_MINUTE ] / d60 );
384
405
time += (outDsec [0 ] / d3600 );
385
406
386
- return new SweJulianDate (tjd_ut , outYearMonthDayHourMin , time , SE_GREG_CAL == gregflag );
407
+ return new SweJulianDate (tjd_ut , outYearMonthDayHourMin , time );
387
408
}
388
409
389
410
/**
@@ -411,9 +432,7 @@ default ISweJulianDate swe_utc_time_zone(int iyear, int imonth, int iday,
411
432
utime += (outYearMonthDayHourMin [IDXI_MINUTE ] / d60 );
412
433
utime += (outDsec [0 ] / d3600 );
413
434
414
- SweJulianDate sweJulDate = new SweJulianDate (outYearMonthDayHourMin , utime , true );
415
- sweJulDate .timeZone (timezone );
416
- return sweJulDate ;
435
+ return new SweJulianDate (outYearMonthDayHourMin , utime , timezone );
417
436
}
418
437
419
438
/****************************
0 commit comments