Skip to content

Commit

Permalink
Merge tag '1.0' to android
Browse files Browse the repository at this point in the history
upgrade to jdk17, fix date usage
  • Loading branch information
kahles committed May 6, 2024
2 parents ff198f7 + b3f8df9 commit bab3021
Show file tree
Hide file tree
Showing 33 changed files with 659 additions and 812 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 1.8
- name: Set up JDK
uses: actions/setup-java@v2
with:
distribution: 'zulu'
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ dependencies {
<version>0.9.4-android</version>
</dependency>
```
https://github.com/kahles/libZodiac/blob/master/src/test/java/de/kah2/zodiac/libZodiac/example/CalendarExampleSimple.java
https://github.com/kahles/libZodiac/blob/master/src/test/java/de/kah2/libZodiac/example/CalendarExampleSimple.java

### Usage
- [`CalendarExampleSimple.java`](src/test/java/de/kah2/libZodiac/example/CalendarExampleSimple.java) shows basic usage of this framework.
- [`CalendarDataStringBuilder.java`](src/test/java/de/kah2/libZodiac/example/CalendarDataStringBuilder.java) shows how to access data.
- [`CalendarExampleStorage.java`](src/test/java/de/kah2/libZodiac/example/CalendarExampleStorage.java) shows how to create, store , load and
- [`CalendarExampleSimple.java`](src/test/java/de/kah2/zodiac/libZodiac/example/CalendarExampleSimple.java) shows basic usage of this framework.
- [`CalendarDataStringBuilder.java`](src/test/java/de/kah2/zodiac/libZodiac/example/CalendarDataStringBuilder.java) shows how to access data.
- [`CalendarExampleStorage.java`](src/test/java/de/kah2/zodiac/libZodiac/example/CalendarExampleStorage.java) shows how to create, store , load and
extend a calendar.
- [`ProgressListenerExample.java`](src/test/java/de/kah2/libZodiac/example/ProgressListenerExample.java) shows how to enable progress
- [`ProgressListenerExample.java`](src/test/java/de/kah2/zodiac/libZodiac/example/ProgressListenerExample.java) shows how to enable progress
listening.


Expand Down
21 changes: 7 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ repositories {

dependencies {

implementation 'org.slf4j:slf4j-api:1.7.36'
testImplementation 'org.slf4j:slf4j-simple:1.7.36'
implementation 'org.slf4j:slf4j-api:2.0.12'
testImplementation 'org.slf4j:slf4j-simple:2.0.13'

// Removed, because actual version doesn't work for multi-threaded use
// compile 'net.sourceforge.novaforjava:novaforjava:0.15.0.0'
Expand All @@ -55,15 +55,8 @@ dependencies {

//implementation 'com.android.support:appcompat-v7:27.1.1'

implementation 'com.jakewharton.threetenabp:threetenabp:1.4.6'
implementation 'net.sourceforge.streamsupport:android-retrofuture:1.7.1'

testImplementation('org.threeten:threetenbp:1.6.8') {
exclude group: 'com.jakewharton.threetenabp', module: 'threetenabp'
}

testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
testImplementation 'org.assertj:assertj-core:3.23.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
testImplementation 'org.assertj:assertj-core:3.25.3'
}

android {
Expand All @@ -74,7 +67,7 @@ android {

defaultConfig {

minSdkVersion 21
minSdkVersion 26
targetSdkVersion 34

versionCode androidGitVersion.code()
Expand All @@ -91,8 +84,8 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

testOptions {
Expand Down
126 changes: 25 additions & 101 deletions src/main/java/de/kah2/zodiac/libZodiac4A/Calendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.bp.LocalDate;
import org.threeten.bp.ZoneId;

import java.time.LocalDate;
import java.util.ConcurrentModificationException;
import java.util.LinkedList;
import java.util.List;
import java.util.TreeSet;

import de.kah2.zodiac.libZodiac4A.interpretation.Interpreter;
import de.kah2.zodiac.libZodiac4A.planetary.Position;

/**
* <p>This is the "main" class of libZodiac. It contains the main logic of managing calendar data like ranges, scope, etc.</p>
* <ul>
Expand All @@ -22,19 +18,19 @@
* see de.kah2.libZodiac.example
* @author kahles
*/
public class Calendar implements LocationProvider {
public class Calendar {

private final Logger log = LoggerFactory.getLogger(this.getClass());

private final LocationProvider locationProvider;

// This is the range the Calendar shall contain.
private DateRange rangeExpected;

private final CalendarData days = new CalendarData();

private CalendarGenerator generator = new CalendarGenerator(this);

private Class<? extends Interpreter> interpreterClass;

/**
* Tells the calendar, how much data is needed / how much overhead to
* produce
Expand All @@ -61,83 +57,24 @@ public enum Scope {

private final Scope scope;

private final ZoneId timeZoneId;
private final Position observerPosition;

/**
* Creates an empty Calendar with "CYCLE" as default for
* {@link Scope} and using system default {@link ZoneId}.
*
* @param observerPosition
* The position of the observer needed for rise and set
* calculation.
* @param expectedRange
* the range defining start date and end date of the
* {@link Calendar} instance.
*
*/
public Calendar(final Position observerPosition, final DateRange expectedRange) {
this(observerPosition, expectedRange, Scope.CYCLE);
}

/**
* Creates an empty Calendar with "CYCLE" as default for
* {@link Scope}.
*
* @param observerPosition
* The position of the observer needed for rise and set
* calculation.
* @param zoneId
* the time zone of the observer needed for rise and set times of
* sun and moon
* @param expectedRange
* the range defining start date and end date of the
* {@link Calendar} instance.
*
*/
public Calendar(final Position observerPosition, final ZoneId zoneId, final DateRange expectedRange) {
this(observerPosition, zoneId, expectedRange, Scope.CYCLE);
}

/**
* Creates an empty Calendar using system default {@link ZoneId}.
*
* @param observerPosition
* The position of the observer needed for rise and set
* calculation.
* @param expectedRange
* the range defining start date and end date of the
* {@link Calendar} instance.
* @param scope
* Allows to set the scope manually
*/
public Calendar(final Position observerPosition, final DateRange expectedRange, final Scope scope) {
this(observerPosition, ZoneId.systemDefault(), expectedRange, scope);
}

/**
* Creates an empty Calendar.
*
* @param observerPosition
* The position of the observer needed for rise and set
* calculation.
* @param zoneId
* the time zone of the observer needed for rise and set times of
* sun and moon
* @param expectedRange
* the range defining start date and end date of the
* {@link Calendar} instance.
* @param scope
* Allows to set the scope manually
* @param locationProvider The {@link LocationProvider} that is needed for calculations
*/
public Calendar(final Position observerPosition, final ZoneId zoneId, final DateRange expectedRange,
final Scope scope) {

this.timeZoneId = zoneId;
this.observerPosition = observerPosition;
public Calendar(
final DateRange expectedRange,
final Scope scope,
final LocationProvider locationProvider ) {

this.rangeExpected = expectedRange;
this.scope = scope;
this.locationProvider = locationProvider;
}

/**
Expand Down Expand Up @@ -190,12 +127,12 @@ public void fixRangeExpectedToIncludeExistingDays() {

if (!this.days.isEmpty()) {
if (allDays.getFirst().getDate().isBefore(expectedStart)) {
this.log.debug("Fixing start of expected range: " + allDays.getFirst().getDate() + " => " + expectedStart);
this.log.debug( "Fixing start of expected range: {} => {}", allDays.getFirst().getDate(), expectedStart );
expectedStart = allDays.getFirst().getDate();
}

if (allDays.getLast().getDate().isAfter(expectedEnd)) {
this.log.debug("Fixing end of expected range: " + allDays.getLast().getDate() + " => " + expectedEnd);
this.log.debug( "Fixing end of expected range: {} => {}", allDays.getLast().getDate(), expectedEnd );
expectedEnd = allDays.getLast().getDate();
}

Expand All @@ -219,22 +156,12 @@ public void fixRangeExpectedToIncludeExistingDays() {
*/
public LinkedList<Day> removeOverhead(final boolean alsoDeleteFutureDays) {

DateRange rangeToKeep;

switch (this.scope) {

case PHASE:
rangeToKeep = new DateRange( this.getRangeExpected().getStart().minusDays(1), this.getRangeExpected().getEnd().plusDays(1) );
break;

case CYCLE:
rangeToKeep = this.getRangeNeededToKeepCycle(alsoDeleteFutureDays);
break;

default: // DAY:
rangeToKeep = this.getRangeExpected();
break;
}
DateRange rangeToKeep = switch ( this.scope ) {
case PHASE -> new DateRange( this.getRangeExpected().getStart().minusDays( 1 ), this.getRangeExpected().getEnd().plusDays( 1 ) );
case CYCLE -> this.getRangeNeededToKeepCycle( alsoDeleteFutureDays );
default -> // DAY:
this.getRangeExpected();
};

LinkedList<Day> removed = this.days.removeBefore( rangeToKeep.getStart() );

Expand Down Expand Up @@ -313,16 +240,6 @@ private LocalDate findNextLunarExtreme(TreeSet<Day> days, LocalDate start, boole
}
}

@Override
public ZoneId getTimeZoneId() {
return this.timeZoneId;
}

@Override
public Position getObserverPosition() {
return this.observerPosition;
}

/**
* @return the range which the {@link Calendar} shall contain.
*/
Expand Down Expand Up @@ -438,4 +355,11 @@ CalendarGenerator getGenerator() {
CalendarData getDays() {
return days;
}

/**
* @return the {@link LocationProvider} that is used for calculations
*/
public LocationProvider getLocationProvider() {
return locationProvider;
}
}
5 changes: 2 additions & 3 deletions src/main/java/de/kah2/zodiac/libZodiac4A/CalendarData.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.kah2.zodiac.libZodiac4A;

import org.threeten.bp.LocalDate;

import java.time.LocalDate;
import java.util.LinkedList;
import java.util.List;
import java.util.NavigableSet;
Expand Down Expand Up @@ -112,7 +111,7 @@ Day get(final LocalDate date) {

NavigableSet<Day> subSet = this.data.subSet(dummyDay, true, dummyDay, true);

if ( subSet.size() == 0 ) {
if ( subSet.isEmpty() ) {
return null;
} else {
return subSet.first();
Expand Down
Loading

0 comments on commit bab3021

Please sign in to comment.