public long getSize(NowReference now) throws Exception { return getMax(now)-min; }
public TreeNodeRegular(int clusterId, TimeInterval interval) throws Exception { this.clusterId = clusterId; this.interval = interval; if( interval.isOngoing() ) { throw new Exception("Must be providing a regular time interval"); } else { this.mid = (long)(interval.getMin() + interval.getMax(null)) / (long)2; } }
public TimeInterval getIntersection(TimeInterval interval, NowReference now) throws Exception { if( !this.intersectsWith(interval, now) ){ return null; }; if( this.isIncludedIn(interval, now) ) { return this; } else if(interval.isIncludedIn(this, now)) { return interval; } else { long min = this.min; long max = this.getMax(now); if( min < interval.min ){ min = interval.min; }; if( max > interval.getMax(now) ){ max = interval.max; }; return new TimeInterval(min,max); } }
static private JSONObject saveNode(TreeNode node) throws Exception { JSONObject jsonNode = new JSONObject(); TimeInterval nodeInterval = node.getInterval(); jsonNode.put("id", node.getClusterId()); jsonNode.put("min", nodeInterval.getMin()); if( nodeInterval.isOngoing() ){ jsonNode.put("ongoing", true); } else { jsonNode.put("max", node.getInterval().getMax(null)); } jsonNode.put("mid", node.getMidPoint()); TreeNode lowChildNode = node.getLowChildNode(); if( null != lowChildNode ){ JSONObject jsonChild = saveNode(lowChildNode); jsonNode.put("l",jsonChild); } TreeNode highChildNode = node.getHighChildNode(); if( null != highChildNode ){ JSONObject jsonChild = saveNode(highChildNode); jsonNode.put("h",jsonChild); } return jsonNode; }
String maxStr = "now"; if( !nodeInterval.isOngoing() ){ maxStr = ""+nodeInterval.getMax(null);
if( elemInt.getMax(now) <= this.getMidPoint() && null != this.getLowChildNode() ){ this.getLowChildNode().insertElement(element, result, operations, now); && elemInt.getMax(now) <= this.getMidPoint() ){ int count = 1; List<TreeElement> nodeElements = operations.getElementsForClusterId(this.getClusterId()); for(TreeElement nodeElement : nodeElements){ if( nodeElement.getInterval().getMax(now) <= this.getMidPoint() ){ ++count;