    001/*
    002 * Copyright (c) 2007-2016 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.Collection;
    024import java.util.Collections;
    025import java.util.IdentityHashMap;
    026import java.util.List;
    027import java.util.Set;
    028
    029import cascading.flow.FlowElement;
    030import cascading.flow.planner.Scope;
    031import cascading.util.Util;
    032
    033/**
    034 *
    035 */
    036public class DecoratedElementGraph implements ElementGraph
    037  {
    038  ElementGraph decorated;
    039
    040  public DecoratedElementGraph( ElementGraph decorated )
    041    {
    042    this.decorated = decorated;
    043    }
    044
    045  public ElementGraph getDecorated()
    046    {
    047    return decorated;
    048    }
    049
    050  @Override
    051  public ElementGraph copyElementGraph()
    052    {
    053    return decorated.copyElementGraph();
    054    }
    055
    056  @Override
    057  public void writeDOT( String filename )
    058    {
    059    boolean success = ElementGraphs.printElementGraph( filename, this, null );
    060
    061    if( success )
    062      Util.writePDF( filename );
    063    }
    064
    065  @Override
    066  public int inDegreeOf( FlowElement vertex )
    067    {
    068    return decorated.inDegreeOf( vertex );
    069    }
    070
    071  @Override
    072  public Set<Scope> incomingEdgesOf( FlowElement vertex )
    073    {
    074    return decorated.incomingEdgesOf( vertex );
    075    }
    076
    077  @Override
    078  public int outDegreeOf( FlowElement vertex )
    079    {
    080    return decorated.outDegreeOf( vertex );
    081    }
    082
    083  @Override
    084  public Set<Scope> outgoingEdgesOf( FlowElement vertex )
    085    {
    086    return decorated.outgoingEdgesOf( vertex );
    087    }
    088
    089  @Override
    090  public List<FlowElement> predecessorListOf( FlowElement flowElement )
    091    {
    092    return decorated.predecessorListOf( flowElement );
    093    }
    094
    095  @Override
    096  public List<FlowElement> successorListOf( FlowElement flowElement )
    097    {
    098    return decorated.successorListOf( flowElement );
    099    }
    100
    101  @Override
    102  public Set<Scope> getAllEdges( FlowElement sourceVertex, FlowElement targetVertex )
    103    {
    104    return decorated.getAllEdges( sourceVertex, targetVertex );
    105    }
    106
    107  @Override
    108  public Scope getEdge( FlowElement sourceVertex, FlowElement targetVertex )
    109    {
    110    return decorated.getEdge( sourceVertex, targetVertex );
    111    }
    112
    113  @Override
    114  public Scope addEdge( FlowElement sourceVertex, FlowElement targetVertex )
    115    {
    116    return decorated.addEdge( sourceVertex, targetVertex );
    117    }
    118
    119  @Override
    120  public boolean addEdge( FlowElement sourceVertex, FlowElement targetVertex, Scope scope )
    121    {
    122    return decorated.addEdge( sourceVertex, targetVertex, scope );
    123    }
    124
    125  @Override
    126  public boolean addHeadVertex( FlowElement flowElement )
    127    {
    128    return decorated.addHeadVertex( flowElement );
    129    }
    130
    131  @Override
    132  public boolean addTailVertex( FlowElement flowElement )
    133    {
    134    return decorated.addTailVertex( flowElement );
    135    }
    136
    137  @Override
    138  public boolean addVertex( FlowElement flowElement )
    139    {
    140    return decorated.addVertex( flowElement );
    141    }
    142
    143  @Override
    144  public boolean containsEdge( FlowElement sourceVertex, FlowElement targetVertex )
    145    {
    146    return decorated.containsEdge( sourceVertex, targetVertex );
    147    }
    148
    149  @Override
    150  public boolean containsEdge( Scope scope )
    151    {
    152    return decorated.containsEdge( scope );
    153    }
    154
    155  @Override
    156  public boolean containsVertex( FlowElement flowElement )
    157    {
    158    return decorated.containsVertex( flowElement );
    159    }
    160
    161  @Override
    162  public Set<Scope> edgeSet()
    163    {
    164    return decorated.edgeSet();
    165    }
    166
    167  @Override
    168  public Set<Scope> edgesOf( FlowElement vertex )
    169    {
    170    return decorated.edgesOf( vertex );
    171    }
    172
    173  @Override
    174  public boolean removeAllEdges( Collection<? extends Scope> edges )
    175    {
    176    return decorated.removeAllEdges( edges );
    177    }
    178
    179  @Override
    180  public Set<Scope> removeAllEdges( FlowElement sourceVertex, FlowElement targetVertex )
    181    {
    182    return decorated.removeAllEdges( sourceVertex, targetVertex );
    183    }
    184
    185  @Override
    186  public boolean removeAllVertices( Collection<? extends FlowElement> vertices )
    187    {
    188    return decorated.removeAllVertices( vertices );
    189    }
    190
    191  @Override
    192  public Scope removeEdge( FlowElement sourceVertex, FlowElement targetVertex )
    193    {
    194    return decorated.removeEdge( sourceVertex, targetVertex );
    195    }
    196
    197  @Override
    198  public boolean removeEdge( Scope scope )
    199    {
    200    return decorated.removeEdge( scope );
    201    }
    202
    203  @Override
    204  public boolean removeVertex( FlowElement flowElement )
    205    {
    206    return decorated.removeVertex( flowElement );
    207    }
    208
    209  @Override
    210  public Set<FlowElement> vertexSet()
    211    {
    212    return decorated.vertexSet();
    213    }
    214
    215  @Override
    216  public Set<FlowElement> vertexSetCopy()
    217    {
    218    Set<FlowElement> result = Collections.newSetFromMap( new IdentityHashMap<FlowElement, Boolean>() );
    219
    220    result.addAll( vertexSet() );
    221
    222    return result;
    223    }
    224
    225  @Override
    226  public FlowElement getEdgeSource( Scope scope )
    227    {
    228    return decorated.getEdgeSource( scope );
    229    }
    230
    231  @Override
    232  public FlowElement getEdgeTarget( Scope scope )
    233    {
    234    return decorated.getEdgeTarget( scope );
    235    }
    236
    237  @Override
    238  public boolean equals( Object object )
    239    {
    240    return ElementGraphs.equals( this, (ElementGraph) object );
    241    }
    242
    243  @Override
    244  public int hashCode()
    245    {
    246    int result = decorated.hashCode();
    247    result = 31 * result; // parity with AnnotatedGraph types
    248    return result;
    249    }
    250  }