@Override public boolean hasNext() { return current.before(end); }
@Override public boolean hasNext() { return current.before(end); }
public boolean isValidAndNonEmpty() { return begin.before(end); }
public boolean isValidAndNonEmpty() { return begin.before(end); }
@Override public boolean isConsistent() { if (first == null && latest != null) { return false; } if (latest == null && first != null) { return false; } for (TimePartition hole : holes) { if (!hole.after(first) || !hole.before(latest)) { return false; } } return true; }
@Override public boolean isConsistent() { if (first == null && latest != null) { return false; } if (latest == null && first != null) { return false; } for (TimePartition hole : holes) { if (!hole.after(first) || !hole.before(latest)) { return false; } } return true; }
@Override public boolean exists(TimePartition toCheck) { return !isEmpty() && !toCheck.before(first) && !toCheck.after(latest) && !holes.contains(toCheck); }
@Override public boolean exists(TimePartition toCheck) { return !isEmpty() && !toCheck.before(first) && !toCheck.after(latest) && !holes.contains(toCheck); }
public TimePartitionRange(TimePartition begin, TimePartition end) throws LensException { if (end.before(begin)) { throw new LensException("condition of creation of timepartition failed: end>=begin"); } if (end.getUpdatePeriod() != begin.getUpdatePeriod()) { throw new LensException("update periods are not same"); } this.begin = begin; this.end = end; }
public TimePartitionRange(TimePartition begin, TimePartition end) throws LensException { if (end.before(begin)) { throw new LensException("condition of creation of timepartition failed: end>=begin"); } if (end.getUpdatePeriod() != begin.getUpdatePeriod()) { throw new LensException("update periods are not same"); } this.begin = begin; this.end = end; }
@Override public boolean add(@NonNull TimePartition partition) throws LensException { if (isEmpty()) { // First partition being added first = partition; latest = partition; return true; } if (partition.before(first)) { addHolesBetween(partition, first, partition.getUpdatePeriod()); first = partition; return true; } else if (partition.after(latest)) { addHolesBetween(latest, partition, partition.getUpdatePeriod()); latest = partition; return true; } else { return holes.remove(partition); } }
@Override public boolean add(@NonNull TimePartition partition) throws LensException { if (isEmpty()) { // First partition being added first = partition; latest = partition; return true; } if (partition.before(first)) { addHolesBetween(partition, first, partition.getUpdatePeriod()); first = partition; return true; } else if (partition.after(latest)) { addHolesBetween(latest, partition, partition.getUpdatePeriod()); latest = partition; return true; } else { return holes.remove(partition); } }
@Override public boolean isConsistent() { if (isEmpty()) { return true; } if (!ranges.get(0).getBegin().before(ranges.get(0).getEnd())) { return false; } for (int i = 0; i < ranges.size() - 1; i++) { if (!ranges.get(i).getEnd().before(ranges.get(i + 1).getBegin())) { return false; } if (!ranges.get(i + 1).getBegin().before(ranges.get(i + 1).getEnd())) { return false; } } return true; }
@Override public boolean isConsistent() { if (isEmpty()) { return true; } if (!ranges.get(0).getBegin().before(ranges.get(0).getEnd())) { return false; } for (int i = 0; i < ranges.size() - 1; i++) { if (!ranges.get(i).getEnd().before(ranges.get(i + 1).getBegin())) { return false; } if (!ranges.get(i + 1).getBegin().before(ranges.get(i + 1).getEnd())) { return false; } } return true; }
if (values[i] == null || values[i].before(tp)) { values[i] = tp;
@Test(dataProvider = "update-periods") public void test(UpdatePeriod up) throws LensException { // Normal date object parsable String nowStr = up.format(NOW); // Create partition by date object or it's string representation -- both should be same. TimePartition nowPartition = TimePartition.of(up, NOW); TimePartition nowStrPartition = TimePartition.of(up, nowStr); assertEquals(nowPartition, nowStrPartition); // Test next and previous assertTrue(nowPartition.next().after(nowPartition)); assertTrue(nowPartition.previous().before(nowPartition)); // date parse failures should give lens exception assertEquals(getLensExceptionFromPartitionParsing(up, "garbage").getMessage(), TimePartition.getWrongUpdatePeriodMessage(up, "garbage")); getLensExceptionFromPartitionParsing(up, (Date) null); getLensExceptionFromPartitionParsing(up, (String) null); getLensExceptionFromPartitionParsing(up, ""); // parse with other update periods for (UpdatePeriod up2 : UpdatePeriod.values()) { // handles the equality case and the case where monthly-quarterly have same format strings. if (up.formatStr().equals(up2.formatStr())) { continue; } // Parsing a string representation with differnet update period should give lens exception. assertEquals(getLensExceptionFromPartitionParsing(up2, nowStr).getMessage(), TimePartition.getWrongUpdatePeriodMessage(up2, nowStr)); } }
@Override public boolean add(TimePartitionRange partitionRange) throws LensException { // Adding partition range to the timeline. Will have to find if any of the sub ranges // intersects. If yes, add only remaining sub ranges, else add the given range as a new sub range. int strictlyAfterIndex = getStrictlyAfterIndex(partitionRange.getBegin()); while (strictlyAfterIndex < ranges.size() && partitionRange.isValidAndNonEmpty()) { if (partitionRange.getEnd().before(ranges.get(strictlyAfterIndex).getBegin())) { // partition begin and end both are strictly before ranges[strictlyAfterIndex]. Add as new sub range. ranges.add(strictlyAfterIndex, partitionRange); partitionRange = partitionRange.getEnd().emptyRange(); break; } else { // begin is before ranges[strictlyAfterIndex], end is not. // extend ranges[strictlyAfterIndex] and add remaining range, if any. ranges.get(strictlyAfterIndex).setBegin(partitionRange.getBegin()); if (ranges.get(strictlyAfterIndex).getEnd().before(partitionRange.getEnd())) { partitionRange = ranges.get(strictlyAfterIndex).getEnd().rangeUpto(partitionRange.getEnd()); } else { // No remaining range, end was before ranges[strictlyAfterIndex].end partitionRange = ranges.get(strictlyAfterIndex).getEnd().emptyRange(); } strictlyAfterIndex++; } } if (strictlyAfterIndex == ranges.size() && partitionRange.isValidAndNonEmpty()) { ranges.add(partitionRange); } mergeRanges(); return true; }
@Override public boolean add(TimePartitionRange partitionRange) throws LensException { // Adding partition range to the timeline. Will have to find if any of the sub ranges // intersects. If yes, add only remaining sub ranges, else add the given range as a new sub range. int strictlyAfterIndex = getStrictlyAfterIndex(partitionRange.getBegin()); while (strictlyAfterIndex < ranges.size() && partitionRange.isValidAndNonEmpty()) { if (partitionRange.getEnd().before(ranges.get(strictlyAfterIndex).getBegin())) { // partition begin and end both are strictly before ranges[strictlyAfterIndex]. Add as new sub range. ranges.add(strictlyAfterIndex, partitionRange); partitionRange = partitionRange.getEnd().emptyRange(); break; } else { // begin is before ranges[strictlyAfterIndex], end is not. // extend ranges[strictlyAfterIndex] and add remaining range, if any. ranges.get(strictlyAfterIndex).setBegin(partitionRange.getBegin()); if (ranges.get(strictlyAfterIndex).getEnd().before(partitionRange.getEnd())) { partitionRange = ranges.get(strictlyAfterIndex).getEnd().rangeUpto(partitionRange.getEnd()); } else { // No remaining range, end was before ranges[strictlyAfterIndex].end partitionRange = ranges.get(strictlyAfterIndex).getEnd().emptyRange(); } strictlyAfterIndex++; } } if (strictlyAfterIndex == ranges.size() && partitionRange.isValidAndNonEmpty()) { ranges.add(partitionRange); } mergeRanges(); return true; }