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.stream.duct; 022 023import org.jgrapht.EdgeFactory; 024import org.jgrapht.graph.SimpleDirectedGraph; 025 026/** 027 * 028 */ 029public 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 public int getOrdinal() 059 { 060 return ordinal; 061 } 062 063 @Override 064 public boolean equals( Object object ) 065 { 066 if( this == object ) 067 return true; 068 069 Ordinal ordinal = (Ordinal) object; 070 071 if( count != ordinal.count ) 072 return false; 073 074 return true; 075 } 076 077 @Override 078 public int hashCode() 079 { 080 return count; 081 } 082 083 @Override 084 public String toString() 085 { 086 final StringBuilder sb = new StringBuilder( "Ordinal{" ); 087 sb.append( "count=" ).append( count ); 088 sb.append( ", ordinal=" ).append( ordinal ); 089 sb.append( '}' ); 090 return sb.toString(); 091 } 092 } 093 094 public DuctGraph() 095 { 096 super( new DuctOrdinalEdgeFactory() ); 097 } 098 099 public synchronized DuctGraph.Ordinal makeOrdinal( int ordinal ) 100 { 101 return ( (DuctOrdinalEdgeFactory) getEdgeFactory() ).makeOrdinal( ordinal ); 102 } 103 }