public Object createGraph(GraphmlContext context, String id, String edgedefault) { Digraph digraph = new MapDigraph(MapDigraph.TREEMAP_FACTORY); context.setGraph(digraph); return digraph; }
public Object putArc(Object origin, Object destination, Object arc) { Map destinations = (Map)graph.get(origin); if (destinations == null) { destinations = createMap(); graph.put(origin, destinations); } addVertex(destination); Object oldArc = destinations.put(destination, arc); if (oldArc == null) size++; return oldArc; } public Object getArc(Object origin, Object destination) {
public ArcIterator outgoingIterator(Object vertex) { if (!containsVertex(vertex)) return ArcIterator.EMPTY_ITERATOR; return new OutgoingArcIterator(vertex); } private class OutgoingArcIterator implements ArcIterator {
public MapDigraph(Factory mapFactory) { this.mapFactory = mapFactory != null ? mapFactory : HASHMAP_FACTORY; graph = createMap(); }
public boolean isOutgoingEmpty(Object vertex) { return outgoingSize(vertex) == 0; } public boolean isIncomingEmpty(Object vertex) {
public boolean isIncomingEmpty(Object vertex) { return incomingSize(vertex) == 0; }
public boolean removeVertex(Object vertex) { Map dst = (Map)graph.remove(vertex); if (dst != null) size -= dst.size(); else return false; removeIncoming(vertex); return true; } public boolean removeAllVertices(Collection vertices) {
public boolean removeAllVertices(Collection vertices) { boolean modified = false; for (Iterator i = vertices.iterator(); i.hasNext();) modified |= removeVertex(i.next()); return modified; } public Object removeArc(Object origin, Object destination) {
public boolean addAllVertices(Collection vertices) { if (graph.keySet().containsAll(vertices)) return false; for (Iterator i = vertices.iterator(); i.hasNext();) addVertex(i.next()); return true; } public Object putArc(Object origin, Object destination, Object arc) {
public boolean addVertex(Object vertex) { if (graph.containsKey(vertex)) return false; graph.put(vertex, createMap()); return true; } public boolean addAllVertices(Collection vertices) {
public void generate() { schemaGraph = new MapDigraph(MapDigraph.HASHMAP_FACTORY); generateAcyclicSchema(); }
public ArcIterator incomingIterator(Object vertex) { if (!containsVertex(vertex)) return ArcIterator.EMPTY_ITERATOR; return new IncomingArcIterator(vertex); } private class IncomingArcIterator implements ArcIterator {
private static Digraph createDigraph4() { Digraph digraph = new MapDigraph(MapDigraph.HASHMAP_FACTORY); String[] vertices = new String[] { "A", "B", "C", "D", "E" }; digraph.addAllVertices(Arrays.asList(vertices)); digraph.putArc("A", "B", Boolean.TRUE); digraph.putArc("A", "C", Boolean.TRUE); digraph.putArc("B", "D", Boolean.TRUE); digraph.putArc("C", "E", Boolean.TRUE); return digraph; } }
private void init() { List dbEntitiesToResolve = collectAllDbEntities(); Digraph pkDependencyGraph = new MapDigraph(MapDigraph.HASHMAP_FACTORY); indexedDbEntities = new HashMap(dbEntitiesToResolve.size()); for (Iterator i = dbEntitiesToResolve.iterator(); i.hasNext();) { pkDependencyGraph, CollectionFactory.ARRAYLIST_FACTORY); Digraph contractedDigraph = new MapDigraph(MapDigraph.HASHMAP_FACTORY); contractor.contract(contractedDigraph, CollectionFactory.ARRAYLIST_FACTORY); IndegreeTopologicalSort sorter = new IndegreeTopologicalSort(
private void init() { List dbEntitiesToResolve = collectAllDbEntities(); Digraph pkDependencyGraph = new MapDigraph(MapDigraph.HASHMAP_FACTORY); indexedDbEntities = new HashMap(dbEntitiesToResolve.size()); for (Iterator i = dbEntitiesToResolve.iterator(); i.hasNext();) { pkDependencyGraph, CollectionFactory.ARRAYLIST_FACTORY); Digraph contractedDigraph = new MapDigraph(MapDigraph.HASHMAP_FACTORY); contractor.contract(contractedDigraph, CollectionFactory.ARRAYLIST_FACTORY); IndegreeTopologicalSort sorter = new IndegreeTopologicalSort(
referentialDigraph = new MapDigraph(MapDigraph.HASHMAP_FACTORY); DbUtils.buildReferentialDigraph(referentialDigraph, tables); StrongConnection contractor = new StrongConnection( referentialDigraph, CollectionFactory.ARRAYLIST_FACTORY); contractedReferentialDigraph = new MapDigraph(MapDigraph.HASHMAP_FACTORY); contractor.contract( contractedReferentialDigraph,
referentialDigraph = new MapDigraph(MapDigraph.HASHMAP_FACTORY); DbUtils.buildReferentialDigraph(referentialDigraph, tables); StrongConnection contractor = new StrongConnection( referentialDigraph, CollectionFactory.ARRAYLIST_FACTORY); contractedReferentialDigraph = new MapDigraph(MapDigraph.HASHMAP_FACTORY); contractor.contract( contractedReferentialDigraph,
private void createWrapperDigraph() { wrapperDigraph = new MapDigraph(MapDigraph.HASHMAP_FACTORY); vertexWrapperMap = new HashMap(digraph.order()); for (Iterator i = digraph.vertexIterator(); i.hasNext();) { Object vertex = i.next(); VertexWrapper wrapper = new VertexWrapper(vertex); vertexWrapperMap.put(vertex, wrapper); wrapperDigraph.addVertex(wrapper); } for (ArcIterator i = digraph.arcIterator(); i.hasNext();) { i.next(); Object wrapper1 = vertexWrapperMap.get(i.getOrigin()); Object wrapper2 = vertexWrapperMap.get(i.getDestination()); if (rootsUpwards) wrapperDigraph.putArc(wrapper1, wrapper2, Boolean.TRUE); else wrapperDigraph.putArc(wrapper2, wrapper1, Boolean.TRUE); } }
private void generateAcyclicSchema() { Digraph graph = new MapDigraph(MapDigraph.HASHMAP_FACTORY); Map vertexToTable = new HashMap(); GraphUtils.randomizeAcyclic(graph, tableCount, maxForeignKeysPerTable,
private static Digraph createDigraph2() { Digraph digraph = new MapDigraph(MapDigraph.HASHMAP_FACTORY); String[] vertices = new String[] { "A", "B", "C", "D", "E", "F" }; digraph.addAllVertices(Arrays.asList(vertices)); digraph.putArc("A", "B", Boolean.TRUE); digraph.putArc("A", "F", Boolean.TRUE); digraph.putArc("B", "C", Boolean.TRUE); digraph.putArc("F", "D", Boolean.TRUE); digraph.putArc("C", "D", Boolean.TRUE); digraph.putArc("E", "D", Boolean.TRUE); return digraph; }