private List<FrozenCell> makeChildrenCells() { FrozenGranularityLayer childLayer = layer.getChild(); if (childLayer == null) { return Collections.emptyList(); } List<TimeRange> ranges = childLayer.fillRange(range); List<FrozenCell> res = new ArrayList<FrozenCell>(ranges.size()); for (TimeRange childRange: ranges) { res.add(childLayer.getCell(childRange)); } return res; }
@Override public String toString() { return String.valueOf(getGranularity()); } }
/** * Returns the range that the children of this cell will occupy, or null if * there are no children. */ public TimeRange getChildrenRange() { FrozenGranularityLayer child = layer.getChild(); if (child == null) { return null; } return child.getTotalRange().intersect(range); }
/** * Returns true if children cells (of the next finer granularity) can fully contain * this cell. For instance, if this cell is @ gran=20, and the next finest gran=5, * then conceivably 4 children could contain a gran20. * * A cell cannot be contained by its children when it lies on the edges of the structure * (a parent may not have a full set of children) */ public boolean canBeContainedByChildren() { FrozenGranularityLayer childLayer = layer.getChild(); if (childLayer == null) { return false; } return childLayer.canFullyContain(range); }
/** * @param timeRange The {@link TimeRange} which defines the start and end time of the cell. * @return A {@link FrozenCell} within the given granularity. */ public FrozenCell getCell(TimeRange timeRange) { FrozenCell res = cells.get(timeRange); if (res != null) { return res; } Granularity gran = getGranularity(); Time rangeStart = timeRange.getStartTime(); if (rangeStart.alignsOnGranularity(gran) == false) { throw new IllegalArgumentException("Range [" + timeRange + "] does not belong to this granularity [" + gran + "]"); } if (!canFullyContain(timeRange)) { throw new IllegalArgumentException("Range [" + timeRange + "] is not currently in scope for granularity [" + gran + "] " + " which has a total range of [" + getTotalRange() + "]"); } res = new FrozenCell(this, timeRange); cells.put(timeRange, res); return res; }
/** * Returns a list of contiguous time ranges, which fully encapsulate the given * range, provided the range is within the total range of the rollup structure. * * In cases where the rollup structure cannot fully encompass the given range, * as much of the rollup structure as possible will be used to cover the range. * * The resulting ranges are all of the same duration (the largest granularity). */ List<TimeRange> getEncompassingRanges(TimeRange range) { List<FrozenGranularityLayer> l = struct.getFrozenLayers(); FrozenGranularityLayer largest = l.get(l.size() - 1); TimeRange fillRange = range.augmentToOverlapWith(largest.getGranularity()); return largest.fillRange(fillRange); } }
List<FrozenCell> splitRange(FrozenCell cell) { if (!cell.canBeContainedByChildren()) { return Collections.emptyList(); } Granularity childGran = cell.getLayer().getChild().getGranularity(); if (childGran.isSmallerThan(minGran)) { return Collections.emptyList(); } return cell.getChildren(); } }
/** * Returns a map from granularity to the oldest datapoint which should * exist for it. */ GranularityTimes getOldestAllowedTimeForGranularity() { Time now = timeSvc.nowNanoTime(); FrozenRollUpStructure frozenStruct = this.struct.freeze(now); GranularityTimes res = new GranularityTimes(); for (FrozenGranularityLayer layer : frozenStruct.getFrozenLayers()) { res.put(layer.getGranularity(), layer.getTotalRange().getStartTime()); } return res; }
/** * @param timeRange The {@link TimeRange} to be checked * @return <code>true</code> if this layer's time range fully encapsulates the given range */ public boolean canFullyContain(TimeRange timeRange) { return getTotalRange().containsOrAlignsWith(timeRange); }
Granularity gran = range.getDurationAsGranularity(); FrozenGranularityLayer layer = struct.getFrozenLayer(gran); toProcess.add(layer.getCell(range));
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + range.hashCode(); result = prime * result + layer.hashCode(); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; FrozenCell other = (FrozenCell) obj; return range.equals(other.range) && layer.equals(other.layer); }
private void initFrozenLayers() { this.layersAscending = new ArrayList<FrozenGranularityLayer>(); this.layersDescending = new LinkedList<FrozenGranularityLayer>(); this.frozenLayers = new HashMap<Granularity, FrozenGranularityLayer>(); FrozenGranularityLayer child = null; for (GranularityLayer layer : getLayers()) { FrozenGranularityLayer frozen = new FrozenGranularityLayer(layer, child, time); frozenLayers.put(layer.getGranularity(), frozen); layersAscending.add(frozen); layersDescending.add(0, frozen); child = frozen; } }
FrozenCell(FrozenGranularityLayer granLayer, TimeRange timeRange) { layer = granLayer; range = timeRange; if(timeRange.getDuration() != granLayer.getLayer().getGranularity().getNanos()) { throw new IllegalArgumentException("Cell with range [" + timeRange + "] does not exist in layer [" + granLayer + "]"); } }
public boolean containsTimeAtGranularity(Time t, Granularity g) { return getFrozenLayer(g).getTotalRange().contains(t); }
List<FrozenCell> toProcess = new LinkedList<FrozenCell>(); for (TimeRange root : roots) { toProcess.add(largestLayer.getCell(root));
TimeRange fillableRange = timeRange.intersect(getTotalRange()); if (fillableRange == null) { return Collections.emptyList();