< prev index next >
src/java.base/share/classes/java/time/zone/ZoneOffsetTransition.java
Print this page
*** 102,111 ****
--- 102,115 ----
/**
* Serialization version.
*/
private static final long serialVersionUID = -6946044323557704546L;
/**
+ * The transition epoch-second.
+ */
+ private final long epochSecond;
+ /**
* The local transition date-time at the transition.
*/
private final LocalDateTime transition;
/**
* The offset before transition.
*** 150,159 ****
--- 154,164 ----
* @param transition the transition date-time with the offset before the transition, not null
* @param offsetBefore the offset before the transition, not null
* @param offsetAfter the offset at and after the transition, not null
*/
ZoneOffsetTransition(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
+ this.epochSecond = transition.toEpochSecond(offsetBefore);
this.transition = transition;
this.offsetBefore = offsetBefore;
this.offsetAfter = offsetAfter;
}
*** 163,172 ****
--- 168,178 ----
* @param epochSecond the transition epoch-second
* @param offsetBefore the offset before the transition, not null
* @param offsetAfter the offset at and after the transition, not null
*/
ZoneOffsetTransition(long epochSecond, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
+ this.epochSecond = epochSecond;
this.transition = LocalDateTime.ofEpochSecond(epochSecond, 0, offsetBefore);
this.offsetBefore = offsetBefore;
this.offsetAfter = offsetAfter;
}
*** 207,217 ****
*
* @param out the output stream, not null
* @throws IOException if an error occurs
*/
void writeExternal(DataOutput out) throws IOException {
! Ser.writeEpochSec(toEpochSecond(), out);
Ser.writeOffset(offsetBefore, out);
Ser.writeOffset(offsetAfter, out);
}
/**
--- 213,223 ----
*
* @param out the output stream, not null
* @throws IOException if an error occurs
*/
void writeExternal(DataOutput out) throws IOException {
! Ser.writeEpochSec(epochSecond, out);
Ser.writeOffset(offsetBefore, out);
Ser.writeOffset(offsetAfter, out);
}
/**
*** 251,261 ****
* Gets the transition instant as an epoch second.
*
* @return the transition epoch second
*/
public long toEpochSecond() {
! return transition.toEpochSecond(offsetBefore);
}
//-------------------------------------------------------------------------
/**
* Gets the local transition date-time, as would be expressed with the 'before' offset.
--- 257,267 ----
* Gets the transition instant as an epoch second.
*
* @return the transition epoch second
*/
public long toEpochSecond() {
! return epochSecond;
}
//-------------------------------------------------------------------------
/**
* Gets the local transition date-time, as would be expressed with the 'before' offset.
*** 395,406 ****
--- 401,418 ----
* @param transition the transition to compare to, not null
* @return the comparator value, negative if less, positive if greater
*/
@Override
public int compareTo(ZoneOffsetTransition transition) {
+ if (epochSecond < transition.epochSecond) {
+ return -1;
+ } else if (epochSecond > transition.epochSecond) {
+ return 1;
+ } else {
return this.getInstant().compareTo(transition.getInstant());
}
+ }
//-----------------------------------------------------------------------
/**
* Checks if this object equals another.
* <p>
*** 414,424 ****
if (other == this) {
return true;
}
if (other instanceof ZoneOffsetTransition) {
ZoneOffsetTransition d = (ZoneOffsetTransition) other;
! return transition.equals(d.transition) &&
offsetBefore.equals(d.offsetBefore) && offsetAfter.equals(d.offsetAfter);
}
return false;
}
--- 426,437 ----
if (other == this) {
return true;
}
if (other instanceof ZoneOffsetTransition) {
ZoneOffsetTransition d = (ZoneOffsetTransition) other;
! return epochSecond == d.epochSecond &&
! transition.equals(d.transition) &&
offsetBefore.equals(d.offsetBefore) && offsetAfter.equals(d.offsetAfter);
}
return false;
}
< prev index next >