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;
022
023import java.util.Map;
024import java.util.Set;
025
026import cascading.flow.planner.FlowStepJob;
027import cascading.flow.planner.graph.FlowElementGraph;
028import cascading.flow.planner.process.FlowStepGraph;
029import cascading.tap.Tap;
030
031/** Flows is a utility helper class. */
032public final class Flows
033  {
034  private Flows()
035    {
036    }
037
038  public static Map<String, FlowStepJob> getJobsMap( Flow flow )
039    {
040    return ( (BaseFlow) flow ).getJobsMap();
041    }
042
043  public static FlowElementGraph getFlowElementGraphFrom( Flow flow )
044    {
045    return ( (BaseFlow) flow ).getFlowElementGraph();
046    }
047
048  public static FlowStepGraph getStepGraphFrom( Flow flow )
049    {
050    return ( (BaseFlow) flow ).getFlowStepGraph();
051    }
052
053  public static String getNameOrID( Flow flow )
054    {
055    if( flow == null )
056      return null;
057
058    if( flow.getName() != null )
059      return flow.getName();
060
061    return flow.getID().substring( 0, 6 );
062    }
063
064  public static Tap getTapForID( Set<Tap> taps, String id )
065    {
066    for( Tap tap : taps )
067      {
068      if( Tap.id( tap ).equals( id ) )
069        return tap;
070      }
071
072    return null;
073    }
074
075  public static FlowElement getFlowElementForID( Set<FlowElement> flowElements, String id )
076    {
077    for( FlowElement flowElement : flowElements )
078      {
079      if( FlowElements.id( flowElement ).equals( id ) )
080        return flowElement;
081      }
082
083    return null;
084    }
085
086  public static FlowDef copy( FlowDef flowDef, Map<String, Tap> sources, Map<String, Tap> sinks, Map<String, Tap> traps, Map<String, Tap> checkpoints )
087    {
088    return new FlowDef( flowDef, sources, sinks, traps, checkpoints );
089    }
090
091  public static void fireOnCompleted( Flow flow )
092    {
093    if( flow instanceof BaseFlow )
094      ( (BaseFlow) flow ).fireOnCompleted();
095    }
096  }