@Test public void fixSequence() { List<TimeSeriesCollection> collection = Arrays.asList( new EmptyTimeSeriesCollection(new DateTime(600, DateTimeZone.UTC)), new EmptyTimeSeriesCollection(new DateTime(0, DateTimeZone.UTC)), new EmptyTimeSeriesCollection(new DateTime(600, DateTimeZone.UTC))); ObjectSequence<TimeSeriesCollection> fixed = Util.fixSequence(new ForwardSequence(0, collection.size()).map(collection::get, false, true, false)); assertEquals(2, fixed.size()); assertThat(fixed.toArray(new TimeSeriesCollection[0]), arrayContaining( new EmptyTimeSeriesCollection(new DateTime(0, DateTimeZone.UTC)), new EmptyTimeSeriesCollection(new DateTime(600, DateTimeZone.UTC)))); }
public static ObjectSequence<TimeSeriesCollection> fixSequence(ObjectSequence<TimeSeriesCollection> seq) { seq = seq.sort(); if (!seq.isDistinct() && !seq.isEmpty()) { List<ObjectSequence<TimeSeriesCollection>> toConcat = new ArrayList<>(); int lastGoodIdx = 0; int curIdx = 0; while (curIdx < seq.size()) { final TimeSeriesCollection curElem = seq.get(curIdx); int nextIdx = curIdx + 1; while (nextIdx < seq.size() && curElem.getTimestamp().equals(seq.get(nextIdx).getTimestamp())) { ++nextIdx; } if (curIdx + 1 < nextIdx) { toConcat.add(seq.limit(curIdx).skip(lastGoodIdx)); TimeSeriesCollection replacement = new LazyMergedTSC(seq.limit(nextIdx).skip(curIdx)); toConcat.add(ObjectSequence.of(true, true, true, replacement)); lastGoodIdx = curIdx = nextIdx; } else { ++curIdx; } } if (lastGoodIdx < curIdx) toConcat.add(seq.skip(lastGoodIdx)); seq = ObjectSequence.concat(toConcat, true, true); } return seq; }
Util { public static ObjectSequence<TimeSeriesCollection> fixSequence(ObjectSequence<TimeSeriesCollection> seq) { seq = seq.sort(); if (!seq.isDistinct() && !seq.isEmpty()) { List<ObjectSequence<TimeSeriesCollection>> toConcat = new ArrayList<>(); int lastGoodIdx = 0; int curIdx = 0; while (curIdx < seq.size()) { final TimeSeriesCollection curElem = seq.get(curIdx); int nextIdx = curIdx + 1; while (nextIdx < seq.size() && curElem.getTimestamp().equals(seq.get(nextIdx).getTimestamp())) { ++nextIdx; } if (curIdx + 1 < nextIdx) { toConcat.add(seq.limit(curIdx).skip(lastGoodIdx)); TimeSeriesCollection replacement = new LazyMergedTSC(seq.limit(nextIdx).skip(curIdx)); toConcat.add(ObjectSequence.of(true, true, true, replacement)); lastGoodIdx = curIdx = nextIdx; } else { ++curIdx; } } if (lastGoodIdx < curIdx) toConcat.add(seq.skip(lastGoodIdx)); seq = ObjectSequence.concat(toConcat, true, true); } return seq; } }
Util { public static ObjectSequence<TimeSeriesCollection> fixSequence(ObjectSequence<TimeSeriesCollection> seq) { seq = seq.sort(); if (!seq.isDistinct() && !seq.isEmpty()) { List<ObjectSequence<TimeSeriesCollection>> toConcat = new ArrayList<>(); int lastGoodIdx = 0; int curIdx = 0; while (curIdx < seq.size()) { final TimeSeriesCollection curElem = seq.get(curIdx); int nextIdx = curIdx + 1; while (nextIdx < seq.size() && curElem.getTimestamp().equals(seq.get(nextIdx).getTimestamp())) { ++nextIdx; } if (curIdx + 1 < nextIdx) { toConcat.add(seq.limit(curIdx).skip(lastGoodIdx)); TimeSeriesCollection replacement = new LazyMergedTSC(seq.limit(nextIdx).skip(curIdx)); toConcat.add(ObjectSequence.of(true, true, true, replacement)); lastGoodIdx = curIdx = nextIdx; } else { ++curIdx; } } if (lastGoodIdx < curIdx) toConcat.add(seq.skip(lastGoodIdx)); seq = ObjectSequence.concat(toConcat, true, true); } return seq; }  }
Util { public static ObjectSequence<TimeSeriesCollection> fixSequence(ObjectSequence<TimeSeriesCollection> seq) { seq = seq.sort(); if (!seq.isDistinct() && !seq.isEmpty()) { List<ObjectSequence<TimeSeriesCollection>> toConcat = new ArrayList<>(); int lastGoodIdx = 0; int curIdx = 0; while (curIdx < seq.size()) { final TimeSeriesCollection curElem = seq.get(curIdx); int nextIdx = curIdx + 1; while (nextIdx < seq.size() && curElem.getTimestamp().equals(seq.get(nextIdx).getTimestamp())) { ++nextIdx; } if (curIdx + 1 < nextIdx) { toConcat.add(seq.limit(curIdx).skip(lastGoodIdx)); TimeSeriesCollection replacement = new LazyMergedTSC(seq.limit(nextIdx).skip(curIdx)); toConcat.add(ObjectSequence.of(true, true, true, replacement)); lastGoodIdx = curIdx = nextIdx; } else { ++curIdx; } } if (lastGoodIdx < curIdx) toConcat.add(seq.skip(lastGoodIdx)); seq = ObjectSequence.concat(toConcat, true, true); } return seq; }  static long segmentLength(long dataLength); static ObjectSequence<TimeSeriesCollection> fixSequence(ObjectSequence<TimeSeriesCollection> seq); static ObjectSequence<TimeSeriesCollection> mergeSequences(ObjectSequence<TimeSeriesCollection>... tsSeq); }
Util { public static ObjectSequence<TimeSeriesCollection> fixSequence(ObjectSequence<TimeSeriesCollection> seq) { seq = seq.sort(); if (!seq.isDistinct() && !seq.isEmpty()) { List<ObjectSequence<TimeSeriesCollection>> toConcat = new ArrayList<>(); int lastGoodIdx = 0; int curIdx = 0; while (curIdx < seq.size()) { final TimeSeriesCollection curElem = seq.get(curIdx); int nextIdx = curIdx + 1; while (nextIdx < seq.size() && curElem.getTimestamp().equals(seq.get(nextIdx).getTimestamp())) { ++nextIdx; } if (curIdx + 1 < nextIdx) { toConcat.add(seq.limit(curIdx).skip(lastGoodIdx)); TimeSeriesCollection replacement = new LazyMergedTSC(seq.limit(nextIdx).skip(curIdx)); toConcat.add(ObjectSequence.of(true, true, true, replacement)); lastGoodIdx = curIdx = nextIdx; } else { ++curIdx; } } if (lastGoodIdx < curIdx) toConcat.add(seq.skip(lastGoodIdx)); seq = ObjectSequence.concat(toConcat, true, true); } return seq; }  static long segmentLength(long dataLength); static ObjectSequence<TimeSeriesCollection> fixSequence(ObjectSequence<TimeSeriesCollection> seq); static ObjectSequence<TimeSeriesCollection> mergeSequences(ObjectSequence<TimeSeriesCollection>... tsSeq); static final int HDR_3_LEN; static final int ALL_HDR_CRC_LEN; }