Top Description Fields Constructors Methods
net.fortuna.ical4j.model

public Class TemporalComparator

extends Object
implements Comparator<Temporal>
Class Inheritance
All Implemented Interfaces
java.util.Comparator
Imports
net.fortuna.ical4j.util.TimeZones, java.time.*, java.time.temporal.ChronoUnit, .Temporal, .TemporalUnit, java.util.Comparator

The purpose of this comparator is to compare two temporals regardless of type. Some temporal types are not directly comparable, due to differences in supported units. For these cases we support hints to indicate how they should be compared. Compare Temporal values based on a specified ChronoUnit.

Field Summary

Modifier and TypeField and Description
private final TemporalUnit
private final ZoneId
public static final TemporalComparator

Constructor Summary

AccessConstructor and Description
public
public
TemporalComparator(TemporalUnit defaultComparisonUnit)

public
TemporalComparator(ZoneId defaultZoneId)

public
TemporalComparator(TemporalUnit
the fallback comparison unit if all other temporal comparisons are not applicable.
defaultComparisonUnit
,
ZoneId defaultZoneId)

Method Summary

Modifier and TypeMethod and Description
public int
compare(Temporal
the first object to be compared.
o1
,
Temporal
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(Instant
the first object to be compared.
o1
,
Instant
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(OffsetDateTime
the first object to be compared.
o1
,
OffsetDateTime
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(LocalDateTime
the first object to be compared.
o1
,
LocalDateTime
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(LocalDate
the first object to be compared.
o1
,
LocalDate
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(Instant
the first object to be compared.
o1
,
LocalDateTime
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(LocalDateTime
the first object to be compared.
o1
,
Instant
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(Instant
the first object to be compared.
o1
,
OffsetDateTime
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(OffsetDateTime
the first object to be compared.
o1
,
Instant
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(OffsetDateTime
the first object to be compared.
o1
,
LocalDateTime
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(LocalDateTime
the first object to be compared.
o1
,
OffsetDateTime
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(Instant
the first object to be compared.
o1
,
LocalDate
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(LocalDate
the first object to be compared.
o1
,
Instant
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(OffsetDateTime
the first object to be compared.
o1
,
LocalDate
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(LocalDate
the first object to be compared.
o1
,
OffsetDateTime
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(LocalDateTime
the first object to be compared.
o1
,
LocalDate
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

public int
compare(LocalDate
the first object to be compared.
o1
,
LocalDateTime
the second object to be compared.
o2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultComparisonUnitback to summary
private final TemporalUnit defaultComparisonUnit
defaultZoneIdback to summary
private final ZoneId defaultZoneId
INSTANCEback to summary
public static final TemporalComparator INSTANCE

Constructor Detail

TemporalComparatorback to summary
public TemporalComparator()
TemporalComparatorback to summary
public TemporalComparator(TemporalUnit defaultComparisonUnit)
TemporalComparatorback to summary
public TemporalComparator(ZoneId defaultZoneId)
TemporalComparatorback to summary
public TemporalComparator(TemporalUnit defaultComparisonUnit, ZoneId defaultZoneId)
Parameters
defaultComparisonUnit:TemporalUnit

the fallback comparison unit if all other temporal comparisons are not applicable.

Method Detail

compareback to summary
public int compare(Temporal o1, Temporal o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:Temporal

the first object to be compared.

o2:Temporal

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Annotations
@Override
compareback to summary
public int compare(Instant o1, Instant o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:Instant

the first object to be compared.

o2:Instant

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(OffsetDateTime o1, OffsetDateTime o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:OffsetDateTime

the first object to be compared.

o2:OffsetDateTime

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(LocalDateTime o1, LocalDateTime o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:LocalDateTime

the first object to be compared.

o2:LocalDateTime

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(LocalDate o1, LocalDate o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:LocalDate

the first object to be compared.

o2:LocalDate

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(Instant o1, LocalDateTime o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:Instant

the first object to be compared.

o2:LocalDateTime

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(LocalDateTime o1, Instant o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:LocalDateTime

the first object to be compared.

o2:Instant

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(Instant o1, OffsetDateTime o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:Instant

the first object to be compared.

o2:OffsetDateTime

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(OffsetDateTime o1, Instant o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:OffsetDateTime

the first object to be compared.

o2:Instant

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(OffsetDateTime o1, LocalDateTime o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:OffsetDateTime

the first object to be compared.

o2:LocalDateTime

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(LocalDateTime o1, OffsetDateTime o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:LocalDateTime

the first object to be compared.

o2:OffsetDateTime

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(Instant o1, LocalDate o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:Instant

the first object to be compared.

o2:LocalDate

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(LocalDate o1, Instant o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:LocalDate

the first object to be compared.

o2:Instant

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(OffsetDateTime o1, LocalDate o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:OffsetDateTime

the first object to be compared.

o2:LocalDate

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(LocalDate o1, OffsetDateTime o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:LocalDate

the first object to be compared.

o2:OffsetDateTime

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(LocalDateTime o1, LocalDate o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:LocalDateTime

the first object to be compared.

o2:LocalDate

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

compareback to summary
public int compare(LocalDate o1, LocalDateTime o2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
o1:LocalDate

the first object to be compared.

o2:LocalDateTime

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.