Class EInterval
- java.lang.Object
-
- net.sf.eBus.messages.EMessageObject
-
- net.sf.eBus.messages.EField
-
- net.sf.eBusx.time.EInterval
-
- All Implemented Interfaces:
java.io.Serializable
public final class EInterval extends EField
Implements a time interval from oneInstant
to another.EInterval
guarantees that begin time is ≤ end time. Each end point may be separately configured to be inclusive or exclusive. If begin time equals end time then both ends must be marked as inclusive.EInterval
extendsEField
so that it can be used in an eBus message. This means thatEInterval.Builder
must be used to create anEInterval
instance.EInterval
is immutable and thread-safe.Allen's Interval Algebra
Allen's temporal reasoning calculus is based on 13 base relations. Since 12 of these relations are simply inverses of each other (for example the inverse of x precedes y is y is preceded by x) only 7 relations are implemented in
EInterval
which are:- : interval 1 precedes interval 2 if interval 1 end time < interval 2 begin time.
- : interval 1 meets interval 2 if if interval 1 end time equals interval 2 begin time.
- : interval 1 overlaps interval 2 if interval 1 begin time < interval 2 begin time and interval 1 end time < interval 2 end time.
- : interval 1 contains interval 2 if interval 1 begin time < interval 2 begin time and interval 1 end time > interval 2 end time.
- : interval 1 starts interval 2 if interval 1 begin time equals interval 2 begin time and interval 1 end time < interval 2 end time.
- : interval 1 finishes interval 2 if interval 1 begin time > interval 2 begin time and interval 1 end time equals interval 2 end time.
- : interval 1 begin and end times equal interval 2 begin and end times.
Note: interval algebra methods below are based solely on the end point times and do not take clusivity into account.
- Author:
- Charles W. Rapp
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EInterval.Builder
EInterval
instances may be created only by using aBuilder
instance.static class
EInterval.Clusivity
Specifies whether an end point is inclusive or exclusive.
-
Field Summary
Fields Modifier and Type Field Description EInterval.Clusivity
beginClusivity
Interval begin time clusivity.java.time.Instant
beginTime
Interval begin time.EInterval.Clusivity
endClusivity
Interval end time clusivity.java.time.Instant
endTime
Interval end time.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static EInterval.Builder
builder()
Returns a newEInterval
builder instance which is used to create anEInterval
object.boolean
contains(EInterval interval)
: Returnstrue
if:this EInterval
begin time <interval
begin time andthis EInterval
end time >interval
end time.boolean
equals(java.lang.Object o)
: Returnstrue
if:o
is the sameEInterval
instance asthis
interval oro
is a non-null EInterval
instance with the same end points and clusivities asthis EInterval
instance.boolean
finishes(EInterval interval)
: Returnstrue
if this interval starts afterintervaL
buts ends at the same time.int
hashCode()
Returns hash code based on end point times and clusivities.boolean
meets(EInterval interval)
: Returnstrue
ifthis EInterval
end time equalsinterval
begin time.boolean
overlaps(EInterval interval)
: Returnstrue
if:this EInterval
end time is >interval
's begin time,this EInterval
end time is <interval
's end time, andthis EInterval
begin time is <interval
's begin time.boolean
precedes(EInterval interval)
: Returnstrue
ifthis EInterval
end time is <interval
begin time.boolean
starts(EInterval interval)
: Returnstrue
if this interval starts at the same time asinterval
but ends before.java.lang.String
toString()
Returns textual representation of end point times and clusivities.
-
-
-
Field Detail
-
beginTime
public final java.time.Instant beginTime
Interval begin time.
-
beginClusivity
public final EInterval.Clusivity beginClusivity
Interval begin time clusivity.
-
endTime
public final java.time.Instant endTime
Interval end time.
-
endClusivity
public final EInterval.Clusivity endClusivity
Interval end time clusivity.
-
-
Method Detail
-
toString
public java.lang.String toString()
Returns textual representation of end point times and clusivities. Uses defaultInstant
time format.- Overrides:
toString
in classjava.lang.Object
- Returns:
- interval as text.
-
equals
public boolean equals(java.lang.Object o)
: Returnstrue
if:-
o
is the sameEInterval
instance asthis
interval or -
o
is a non-null EInterval
instance with the same end points and clusivities asthis EInterval
instance.
false
.- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- comparison object.- Returns:
true
ifo
is a non-null EInterval
instance whose end points are equal and have the same clusivities.
-
-
hashCode
public int hashCode()
Returns hash code based on end point times and clusivities.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- hash code based on end point times and clusivities.
-
precedes
public boolean precedes(EInterval interval)
: Returnstrue
ifthis EInterval
end time is <interval
begin time.Note that this comparison is based only on time and does not take clusivity into account.
- Parameters:
interval
- comparison time interval.- Returns:
true
ifthis EInterval
precedesinterval
andfalse
otherwise.
-
meets
public boolean meets(EInterval interval)
: Returnstrue
ifthis EInterval
end time equalsinterval
begin time.Note that this comparison is based only on time and does not take clusivity into account.
- Parameters:
interval
- comparison time interval.- Returns:
true
ifthis EInterval
meetsinterval
andfalse
otherwise.
-
overlaps
public boolean overlaps(EInterval interval)
: Returnstrue
if:-
this EInterval
end time is >interval
's begin time, -
this EInterval
end time is <interval
's end time, and -
this EInterval
begin time is <interval
's begin time.
Note that this comparison is based only on time and does not take clusivity into account.
- Parameters:
interval
- comparison time interval.- Returns:
true
ifthis EInterval
overlapsinterval
andfalse
otherwise.
-
-
contains
public boolean contains(EInterval interval)
: Returnstrue
if:-
this EInterval
begin time <interval
begin time and -
this EInterval
end time >interval
end time.
Note that this comparison is based only on time and does not take clusivity into account.
- Parameters:
interval
- comparison time interval.- Returns:
true
if this interval begins beforeinterval
and ends after.
-
-
starts
public boolean starts(EInterval interval)
: Returnstrue
if this interval starts at the same time asinterval
but ends before. That is:-
this EInterval
begin time equalsinterval
begin time and -
this EInterval
end time <interval
end time.
Note that this comparison is based only on time and does not take clusivity into account.
- Parameters:
interval
- comparison time interval.- Returns:
true
if this interval starts at the same time asinterval
but ends before.
-
-
finishes
public boolean finishes(EInterval interval)
: Returnstrue
if this interval starts afterintervaL
buts ends at the same time. That is:-
this EInterval
begin time >interval
begin time and -
this EInterval
end time equalsinterval
end time.
Note that this comparison is based only on time and does not take clusivity into account.
- Parameters:
interval
- comparison time interval.- Returns:
true
if this interval starts afterintervaL
buts ends at the same time.
-
-
builder
public static EInterval.Builder builder()
Returns a newEInterval
builder instance which is used to create anEInterval
object. It is recommended that a new builder be used when creating anEInterval
instance and not re-use aBuilder
to create multiple intervals.- Returns:
- interval builder instance.
-
-