@@ -215,7 +215,7 @@ public <T, R> LocalDateTimeline<R> combine(final LocalDateTimeline<T> other, fin
215
215
* for å 'redusere' tidslinjen ned til enkleste form før lagring etc.
216
216
*/
217
217
public LocalDateTimeline <V > compress () {
218
- var factory = new CompressorFactory <V >(Objects ::equals , LocalDateSegment :: new );
218
+ var factory = new CompressorFactory <V >(Objects ::equals , ( i , lhs , rhs ) -> new LocalDateSegment <>( i , lhs . getValue ()) );
219
219
TimelineCompressor <V > compressor = segments .stream ()
220
220
.collect (factory ::get , TimelineCompressor ::accept , TimelineCompressor ::combine );
221
221
@@ -225,9 +225,9 @@ public LocalDateTimeline<V> compress() {
225
225
/**
226
226
* Fikser opp tidslinjen ved å slå sammen sammenhengende intervall med "like" verider utover periode.
227
227
* @param e - likhetspredikat for å sammenligne to segment som vurderes slått sammen
228
- * @param c - konstruktør som tar nytt intervall og gammel verdi og lager et nytt segment
228
+ * @param c - combinator for å slå sammen to tids-abut-segmenter som oppfyller e
229
229
*/
230
- public LocalDateTimeline <V > compress (BiPredicate <V , V > e , BiFunction < LocalDateInterval , V , LocalDateSegment < V > > c ) {
230
+ public LocalDateTimeline <V > compress (BiPredicate <V , V > e , LocalDateSegmentCombinator < V , V , V > c ) {
231
231
var factory = new CompressorFactory <>(e , c );
232
232
TimelineCompressor <V > compressor = segments .stream ()
233
233
.collect (factory ::get , TimelineCompressor ::accept , TimelineCompressor ::combine );
@@ -773,11 +773,11 @@ static class TimelineCompressor<V> implements Consumer<LocalDateSegment<V>> {
773
773
774
774
private final NavigableSet <LocalDateSegment <V >> segmenter = new TreeSet <>();
775
775
private final BiPredicate <V , V > equals ;
776
- private final BiFunction < LocalDateInterval , V , LocalDateSegment < V >> construct ;
776
+ private final LocalDateSegmentCombinator < V , V , V > combinator ;
777
777
778
- TimelineCompressor (BiPredicate <V , V > e , BiFunction < LocalDateInterval , V , LocalDateSegment < V > > c ) {
778
+ TimelineCompressor (BiPredicate <V , V > e , LocalDateSegmentCombinator < V , V , V > c ) {
779
779
this .equals = e ;
780
- this .construct = c ;
780
+ this .combinator = c ;
781
781
}
782
782
783
783
@ Override
@@ -791,7 +791,7 @@ public void accept(LocalDateSegment<V> t) {
791
791
// bytt ut og ekspander intervall for siste
792
792
segmenter .remove (last );
793
793
LocalDateInterval expandedInterval = last .getLocalDateInterval ().expand (t .getLocalDateInterval ());
794
- segmenter .add (construct . apply (expandedInterval , last .getValue ()));
794
+ segmenter .add (new LocalDateSegment <>( expandedInterval , combinator . combine (expandedInterval , last , t ) .getValue ()));
795
795
} else {
796
796
segmenter .add (t );
797
797
}
@@ -806,15 +806,15 @@ public void combine(@SuppressWarnings("unused") TimelineCompressor<V> other) {
806
806
807
807
static class CompressorFactory <V > {
808
808
private final BiPredicate <V , V > equals ;
809
- private final BiFunction < LocalDateInterval , V , LocalDateSegment < V >> construct ;
809
+ private final LocalDateSegmentCombinator < V , V , V > combinator ;
810
810
811
- CompressorFactory (BiPredicate <V , V > e , BiFunction < LocalDateInterval , V , LocalDateSegment < V > > c ) {
811
+ CompressorFactory (BiPredicate <V , V > e , LocalDateSegmentCombinator < V , V , V > c ) {
812
812
this .equals = e ;
813
- this .construct = c ;
813
+ this .combinator = c ;
814
814
}
815
815
816
816
TimelineCompressor <V > get () {
817
- return new TimelineCompressor <>(equals , construct );
817
+ return new TimelineCompressor <>(equals , combinator );
818
818
}
819
819
}
820
820
0 commit comments