001/* 002 * Copyright (c) 2007-2015 Concurrent, Inc. All Rights Reserved. 003 * 004 * Project and contact information: http://www.cascading.org/ 005 * 006 * This file is part of the Cascading project. 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020 021package cascading.flow.planner.graph; 022 023import java.util.IdentityHashMap; 024 025import cascading.flow.FlowElement; 026import cascading.flow.planner.Scope; 027import cascading.util.EnumMultiMap; 028import org.jgrapht.Graphs; 029import org.jgrapht.graph.SimpleDirectedGraph; 030 031import static cascading.flow.planner.graph.ElementGraphs.directed; 032 033/** 034 * 035 */ 036public class ElementDirectedGraph extends BaseAnnotatedElementGraph implements AnnotatedGraph 037 { 038 public ElementDirectedGraph() 039 { 040 this.graph = new DirectedGraph(); 041 } 042 043 public ElementDirectedGraph( ElementGraph parent ) 044 { 045 if( parent == null ) 046 { 047 this.graph = new DirectedGraph(); 048 return; 049 } 050 051 this.graph = new DirectedGraph( directed( parent ) ); 052 053 addParentAnnotations( parent ); 054 } 055 056 public ElementDirectedGraph( ElementGraph parent, EnumMultiMap annotations ) 057 { 058 this( parent ); 059 060 getAnnotations().addAll( annotations ); 061 } 062 063 @Override 064 public ElementGraph copyElementGraph() 065 { 066 return new ElementDirectedGraph( this ); 067 } 068 069 private class DirectedGraph extends SimpleDirectedGraph<FlowElement, Scope> 070 { 071 public DirectedGraph() 072 { 073 super( Scope.class ); 074 } 075 076 public DirectedGraph( org.jgrapht.DirectedGraph<FlowElement, Scope> parent ) 077 { 078 this(); 079 080 Graphs.addGraph( this, parent ); 081 } 082 083 @Override 084 protected DirectedSpecifics createDirectedSpecifics() 085 { 086 return new DirectedSpecifics( new IdentityHashMap<FlowElement, DirectedEdgeContainer<FlowElement, Scope>>() ); 087 } 088 } 089 }