@Test void testUnwrapPrefersLastAdvancedToken_NeitherSegmentAdvanced_OnlyLowerIsCandidate() { MergedTrackingToken merged = new MergedTrackingToken(token(3), mock(TrackingToken.class)); assertEquals(token(3), merged.unwrap(GlobalSequenceTrackingToken.class).orElse(null)); }
@Override public <R extends TrackingToken> Optional<R> unwrap(Class<R> tokenType) { if (tokenType.isInstance(this)) { return Optional.of(tokenType.cast(this)); } else { Optional<R> unwrappedLower = WrappedToken.unwrap(lowerSegmentToken, tokenType); Optional<R> unwrappedUpper = WrappedToken.unwrap(upperSegmentToken, tokenType); if (lowerSegmentAdvanced && unwrappedLower.isPresent()) { return unwrappedLower; } else { if (upperSegmentAdvanced && unwrappedUpper.isPresent()) { return unwrappedUpper; } else { if (unwrappedLower.isPresent()) { return unwrappedLower; } return unwrappedUpper; } } } }
MergedTrackingToken implements TrackingToken, Serializable, WrappedToken { @Override public <R extends TrackingToken> Optional<R> unwrap(Class<R> tokenType) { if (tokenType.isInstance(this)) { return Optional.of(tokenType.cast(this)); } else { Optional<R> unwrappedLower = WrappedToken.unwrap(lowerSegmentToken, tokenType); Optional<R> unwrappedUpper = WrappedToken.unwrap(upperSegmentToken, tokenType); if (lowerSegmentAdvanced && unwrappedLower.isPresent()) { return unwrappedLower; } else { if (upperSegmentAdvanced && unwrappedUpper.isPresent()) { return unwrappedUpper; } else { if (unwrappedLower.isPresent()) { return unwrappedLower; } return unwrappedUpper; } } } } }
MergedTrackingToken implements TrackingToken, Serializable, WrappedToken { @Override public <R extends TrackingToken> Optional<R> unwrap(Class<R> tokenType) { if (tokenType.isInstance(this)) { return Optional.of(tokenType.cast(this)); } else { Optional<R> unwrappedLower = WrappedToken.unwrap(lowerSegmentToken, tokenType); Optional<R> unwrappedUpper = WrappedToken.unwrap(upperSegmentToken, tokenType); if (lowerSegmentAdvanced && unwrappedLower.isPresent()) { return unwrappedLower; } else { if (upperSegmentAdvanced && unwrappedUpper.isPresent()) { return unwrappedUpper; } else { if (unwrappedLower.isPresent()) { return unwrappedLower; } return unwrappedUpper; } } } } @JsonCreator @ConstructorProperties({"lowerSegmentToken", "upperSegmentToken"})  MergedTrackingToken(
            @JsonProperty("lowerSegmentToken") TrackingToken lowerSegmentToken,
            @JsonProperty("upperSegmentToken") TrackingToken upperSegmentToken); protected  MergedTrackingToken(TrackingToken lowerSegmentToken, TrackingToken upperSegmentToken,
                                  boolean lowerSegmentAdvanced, boolean upperSegmentAdvanced); }
MergedTrackingToken implements TrackingToken, Serializable, WrappedToken { @Override public <R extends TrackingToken> Optional<R> unwrap(Class<R> tokenType) { if (tokenType.isInstance(this)) { return Optional.of(tokenType.cast(this)); } else { Optional<R> unwrappedLower = WrappedToken.unwrap(lowerSegmentToken, tokenType); Optional<R> unwrappedUpper = WrappedToken.unwrap(upperSegmentToken, tokenType); if (lowerSegmentAdvanced && unwrappedLower.isPresent()) { return unwrappedLower; } else { if (upperSegmentAdvanced && unwrappedUpper.isPresent()) { return unwrappedUpper; } else { if (unwrappedLower.isPresent()) { return unwrappedLower; } return unwrappedUpper; } } } } @JsonCreator @ConstructorProperties({"lowerSegmentToken", "upperSegmentToken"})  MergedTrackingToken(
            @JsonProperty("lowerSegmentToken") TrackingToken lowerSegmentToken,
            @JsonProperty("upperSegmentToken") TrackingToken upperSegmentToken); protected  MergedTrackingToken(TrackingToken lowerSegmentToken, TrackingToken upperSegmentToken,
                                  boolean lowerSegmentAdvanced, boolean upperSegmentAdvanced); static boolean isMergeInProgress(TrackingToken trackingToken); static OptionalLong mergePosition(TrackingToken trackingToken); @Override TrackingToken lowerBound(TrackingToken other); @Override OptionalLong position(); @Override TrackingToken upperBound(TrackingToken other); @Override boolean covers(TrackingToken other); @Override TrackingToken advancedTo(TrackingToken newToken); @Override Optional<R> unwrap(Class<R> tokenType); @Override TrackingToken lowerBound(); @Override TrackingToken upperBound(); @JsonGetter("lowerSegmentToken") @JsonTypeInfo(use = JsonTypeInfo.Id.MINIMAL_CLASS) TrackingToken lowerSegmentToken(); @JsonGetter("upperSegmentToken") @JsonTypeInfo(use = JsonTypeInfo.Id.MINIMAL_CLASS) TrackingToken upperSegmentToken(); @JsonIgnore boolean isLowerSegmentAdvanced(); @JsonIgnore boolean isUpperSegmentAdvanced(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
MergedTrackingToken implements TrackingToken, Serializable, WrappedToken { @Override public <R extends TrackingToken> Optional<R> unwrap(Class<R> tokenType) { if (tokenType.isInstance(this)) { return Optional.of(tokenType.cast(this)); } else { Optional<R> unwrappedLower = WrappedToken.unwrap(lowerSegmentToken, tokenType); Optional<R> unwrappedUpper = WrappedToken.unwrap(upperSegmentToken, tokenType); if (lowerSegmentAdvanced && unwrappedLower.isPresent()) { return unwrappedLower; } else { if (upperSegmentAdvanced && unwrappedUpper.isPresent()) { return unwrappedUpper; } else { if (unwrappedLower.isPresent()) { return unwrappedLower; } return unwrappedUpper; } } } } @JsonCreator @ConstructorProperties({"lowerSegmentToken", "upperSegmentToken"})  MergedTrackingToken(
            @JsonProperty("lowerSegmentToken") TrackingToken lowerSegmentToken,
            @JsonProperty("upperSegmentToken") TrackingToken upperSegmentToken); protected  MergedTrackingToken(TrackingToken lowerSegmentToken, TrackingToken upperSegmentToken,
                                  boolean lowerSegmentAdvanced, boolean upperSegmentAdvanced); static boolean isMergeInProgress(TrackingToken trackingToken); static OptionalLong mergePosition(TrackingToken trackingToken); @Override TrackingToken lowerBound(TrackingToken other); @Override OptionalLong position(); @Override TrackingToken upperBound(TrackingToken other); @Override boolean covers(TrackingToken other); @Override TrackingToken advancedTo(TrackingToken newToken); @Override Optional<R> unwrap(Class<R> tokenType); @Override TrackingToken lowerBound(); @Override TrackingToken upperBound(); @JsonGetter("lowerSegmentToken") @JsonTypeInfo(use = JsonTypeInfo.Id.MINIMAL_CLASS) TrackingToken lowerSegmentToken(); @JsonGetter("upperSegmentToken") @JsonTypeInfo(use = JsonTypeInfo.Id.MINIMAL_CLASS) TrackingToken upperSegmentToken(); @JsonIgnore boolean isLowerSegmentAdvanced(); @JsonIgnore boolean isUpperSegmentAdvanced(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }