    001    /*
    002     * Copyright (c) 2007-2014 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
    021    package cascading.flow.stream;
    022
    023    import org.jgrapht.EdgeFactory;
    024    import org.jgrapht.graph.SimpleDirectedGraph;
    025
    026    /**
    027     *
    028     */
    029    public class DuctGraph extends SimpleDirectedGraph<Duct, DuctGraph.Ordinal>
    030      {
    031      private static class DuctOrdinalEdgeFactory implements EdgeFactory<Duct, Ordinal>
    032        {
    033        int count = 0;
    034
    035        @Override
    036        public DuctGraph.Ordinal createEdge( Duct lhs, Duct rhs )
    037          {
    038          return makeOrdinal( 0 );
    039          }
    040
    041        public DuctGraph.Ordinal makeOrdinal( int ordinal )
    042          {
    043          return new DuctGraph.Ordinal( count++, ordinal );
    044          }
    045        }
    046
    047      public static class Ordinal
    048        {
    049        int count;
    050        int ordinal;
    051
    052        public Ordinal( int count, int ordinal )
    053          {
    054          this.count = count;
    055          this.ordinal = ordinal;
    056          }
    057
    058        @Override
    059        public boolean equals( Object object )
    060          {
    061          if( this == object )
    062            return true;
    063
    064          Ordinal ordinal = (Ordinal) object;
    065
    066          if( count != ordinal.count )
    067            return false;
    068
    069          return true;
    070          }
    071
    072        @Override
    073        public int hashCode()
    074          {
    075          return count;
    076          }
    077        }
    078
    079      public DuctGraph()
    080        {
    081        super( new DuctOrdinalEdgeFactory() );
    082        }
    083
    084      public synchronized DuctGraph.Ordinal makeOrdinal( int ordinal )
    085        {
    086        return ( (DuctOrdinalEdgeFactory) getEdgeFactory() ).makeOrdinal( ordinal );
    087        }
    088      }