public TreeNodeOngoing(int clusterId, TimeInterval interval) throws Exception { this.clusterId = clusterId; this.interval = interval; if( interval.isOngoing() ) { this.mid = interval.getMin(); } else { throw new Exception("Must be providing an on-going time interval"); } }
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; } }
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 minStr = ""+nodeInterval.getMin(); String maxStr = "now"; if( !nodeInterval.isOngoing() ){ maxStr = ""+nodeInterval.getMax(null);
/** * Modifies a cluster tree as a result of adding a new elements in the * tree. * @param tree Tree where the element is inserted. * @param elements Elements to be inserted in the tree * @return Results of inserting the elements * @throws Exception */ static public Result insertElements(Tree tree, List<TreeElement> elements, NowReference now) throws Exception { ResultImpl result = new ResultImpl(tree); TreeNodeRegular regularRootNode = tree.getRegularRootNode(); TreeNodeOngoing ongoingRootNode = tree.getOngoingRootNode(); for(TreeElement element : elements){ TimeInterval elementInterval = element.getInterval(); if( elementInterval.isOngoing() ){ ongoingRootNode.insertElement(element, result, tree.getOperations(), now); } else { regularRootNode.insertElement(element, result, tree.getOperations(), now); } } return result; } }
static private void nodeToInfo(TreeNode node, TreeInfo treeInfo, int depth) throws Exception { treeInfo.nodeCount++; if( treeInfo.maxDepth < depth ){ treeInfo.maxDepth = depth; } if( node.getInterval().isOngoing() ) { ++treeInfo.ongoingNodeCount; } else { ++treeInfo.regularNodeCount; if( treeInfo.minInterval > node.getInterval().getSize(null) ){ treeInfo.minInterval = node.getInterval().getSize(null); } } if( null != node.getLowChildNode() ){ nodeToInfo(node.getLowChildNode(), treeInfo, depth+1); } if( null != node.getHighChildNode() ){ nodeToInfo(node.getHighChildNode(), treeInfo, depth+1); } }