-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
917 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
core/src/main/java/io/github/zero88/schedulerx/trigger/rule/BaseTimeframe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.github.zero88.schedulerx.trigger.rule; | ||
|
||
import java.util.Objects; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
abstract class BaseTimeframe<T> implements Timeframe<T>, TimeParser<T> { | ||
|
||
private T from; | ||
private T to; | ||
|
||
protected BaseTimeframe() { } | ||
|
||
protected final BaseTimeframe<T> setValues(Object from, Object to) { | ||
final TimeframeValidator validator = validator(); | ||
final TimeParser<T> parser = parser(); | ||
this.from = validator.normalize(parser, from); | ||
this.to = validator.normalize(parser, to); | ||
validator.validate(this); | ||
return this; | ||
} | ||
|
||
@Override | ||
public final T from() { return from; } | ||
|
||
@Override | ||
public final T to() { return to; } | ||
|
||
@Override | ||
public final @NotNull TimeParser<T> parser() { return this; } | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = from.hashCode(); | ||
result = 31 * result + to.hashCode(); | ||
result = 31 * result + type().hashCode(); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
Timeframe<?> that = (Timeframe<?>) o; | ||
return Objects.equals(type(), that.type()) && Objects.equals(from, that.from()) && | ||
Objects.equals(to, that.to()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TimeFrame{type=" + type().getName() + ", (" + from + ", " + to + ")}"; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
core/src/main/java/io/github/zero88/schedulerx/trigger/rule/InstantTimeframe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.zero88.schedulerx.trigger.rule; | ||
|
||
import java.time.Instant; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class InstantTimeframe extends BaseTimeframe<Instant> implements TimeRangeConstraint { | ||
|
||
@Override | ||
public final @NotNull Class<Instant> type() { return Instant.class; } | ||
|
||
@Override | ||
public boolean check(@NotNull Instant instant) { | ||
return (from() == null || instant.isAfter(from())) && (to() == null || instant.isBefore(to())); | ||
} | ||
|
||
@Override | ||
public Instant parse(Object value) { | ||
if (value instanceof CharSequence) { | ||
return Instant.parse((CharSequence) value); | ||
} | ||
return (Instant) value; | ||
} | ||
|
||
@Override | ||
public @NotNull TimeframeValidator validator() { | ||
return super.validator().and(this); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
core/src/main/java/io/github/zero88/schedulerx/trigger/rule/LocalDateTimeFrame.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.github.zero88.schedulerx.trigger.rule; | ||
|
||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.time.ZoneId; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class LocalDateTimeFrame extends BaseTimeframe<LocalDate> implements TimeRangeConstraint { | ||
|
||
@Override | ||
public final @NotNull Class<LocalDate> type() { return LocalDate.class; } | ||
|
||
@Override | ||
public boolean check(@NotNull Instant instant) { | ||
final LocalDate given = instant.atZone(ZoneId.systemDefault()).toLocalDate(); | ||
return (from() == null || given.isAfter(from())) && (to() == null || given.isBefore(to())); | ||
} | ||
|
||
@Override | ||
public LocalDate parse(Object value) { | ||
if (value instanceof CharSequence) { | ||
return LocalDate.parse((CharSequence) value); | ||
} | ||
return (LocalDate) value; | ||
} | ||
|
||
@Override | ||
public @NotNull TimeframeValidator validator() { | ||
return super.validator().and(this); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
core/src/main/java/io/github/zero88/schedulerx/trigger/rule/LocalDateTimeTimeframe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.github.zero88.schedulerx.trigger.rule; | ||
|
||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class LocalDateTimeTimeframe extends BaseTimeframe<LocalDateTime> implements TimeRangeConstraint { | ||
|
||
@Override | ||
public final @NotNull Class<LocalDateTime> type() { return LocalDateTime.class; } | ||
|
||
@Override | ||
public boolean check(@NotNull Instant instant) { | ||
final LocalDateTime given = instant.atZone(ZoneId.systemDefault()).toLocalDateTime(); | ||
return (from() == null || given.isAfter(from())) && (to() == null || given.isBefore(to())); | ||
} | ||
|
||
@Override | ||
public LocalDateTime parse(Object value) { | ||
if (value instanceof CharSequence) { | ||
return LocalDateTime.parse((CharSequence) value); | ||
} | ||
return (LocalDateTime) value; | ||
} | ||
|
||
@Override | ||
public @NotNull TimeframeValidator validator() { | ||
return super.validator().and(this); | ||
} | ||
|
||
} |
Oops, something went wrong.