1 32 33 package com.jeantessier.dependency; 34 35 import java.util.*; 36 37 44 public class TransitiveClosure { 45 public static long DO_NOT_FOLLOW = -1; 46 public static long UNBOUNDED_DEPTH = Long.MAX_VALUE; 47 48 private long maximumInboundDepth = DO_NOT_FOLLOW; 49 private long maximumOutboundDepth = UNBOUNDED_DEPTH; 50 51 private SelectionCriteria startCriteria; 52 private SelectionCriteria stopCriteria; 53 54 private NodeFactory factory = new NodeFactory(); 55 56 public TransitiveClosure(SelectionCriteria startCriteria, SelectionCriteria stopCriteria) { 57 this.startCriteria = startCriteria; 58 this.stopCriteria = stopCriteria; 59 } 60 61 public NodeFactory getFactory() { 62 return factory; 63 } 64 65 public void setMaximumInboundDepth(long maximumInboundDepth) { 66 this.maximumInboundDepth = maximumInboundDepth; 67 } 68 69 public void setMaximumOutboundDepth(long maximumOutboundDepth) { 70 this.maximumOutboundDepth = maximumOutboundDepth; 71 } 72 73 public void traverseNodes(Collection nodes) { 74 if (maximumInboundDepth != DO_NOT_FOLLOW) { 75 compute(nodes, maximumInboundDepth, new ClosureInboundSelector()); 76 } 77 78 if (maximumOutboundDepth != DO_NOT_FOLLOW) { 79 compute(nodes, maximumOutboundDepth, new ClosureOutboundSelector()); 80 } 81 } 82 83 private void compute(Collection nodes, long depth, ClosureLayerSelector layerSelector) { 84 TransitiveClosureEngine engine = new TransitiveClosureEngine(factory, nodes, startCriteria, stopCriteria, layerSelector); 85 86 if (depth == UNBOUNDED_DEPTH) { 87 engine.computeAllLayers(); 88 } else { 89 engine.computeLayers(depth); 90 } 91 } 92 } 93 | Popular Tags |