001/*
002 * Copyright (c) 2007-2017 Xplenty, 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.cascade;
022
023import java.util.HashMap;
024import java.util.Map;
025
026import cascading.cascade.planner.FlowGraph;
027import cascading.cascade.planner.IdentifierGraph;
028import cascading.flow.FlowDef;
029import cascading.pipe.Pipe;
030import cascading.tap.Tap;
031
032/**
033 * Class Cascades provides useful utilities for use in constructing {@link Cascade} and {@link cascading.flow.Flow}
034 * instances via the {@link CascadeConnector} and {@link cascading.flow.FlowConnector}, respectively.
035 * <p/>
036 * See the {@link FlowDef} for the recommended alternative to dealing with Maps of Taps.
037 */
038public class Cascades
039  {
040  /**
041   * Method tapsMap creates a new Map for the given name and tap.
042   *
043   * @param name of type String
044   * @param tap  of type Tap
045   * @return Map
046   */
047  public static Map<String, Tap> tapsMap( String name, Tap tap )
048    {
049    return tapsMap( new String[]{name}, Tap.taps( tap ) );
050    }
051
052  /**
053   * Method tapsMap creates a new Map for each name and tap.
054   *
055   * @param names of type String[]
056   * @param taps  of type Tap[]
057   * @return Map
058   */
059  public static Map<String, Tap> tapsMap( String[] names, Tap[] taps )
060    {
061    Map<String, Tap> map = new HashMap<String, Tap>();
062
063    for( int i = 0; i < names.length; i++ )
064      map.put( names[ i ], taps[ i ] );
065
066    return map;
067    }
068
069  /**
070   * Method tapsMap creates a new Map using the given Pipe name and tap.
071   *
072   * @param pipe of type Pipe
073   * @param tap  of type Tap
074   * @return Map
075   */
076  public static Map<String, Tap> tapsMap( Pipe pipe, Tap tap )
077    {
078    return tapsMap( Pipe.pipes( pipe ), Tap.taps( tap ) );
079    }
080
081  /**
082   * Method tapsMap creates a new Map using the given pipes and taps.
083   *
084   * @param pipes of type Pipe[]
085   * @param taps  of type Tap[]
086   * @return Map
087   */
088  public static Map<String, Tap> tapsMap( Pipe[] pipes, Tap[] taps )
089    {
090    Map<String, Tap> map = new HashMap<String, Tap>();
091
092    for( int i = 0; i < pipes.length; i++ )
093      map.put( pipes[ i ].getName(), taps[ i ] );
094
095    return map;
096    }
097
098  public static FlowGraph getFlowGraphFrom( Cascade cascade )
099    {
100    return ( (BaseCascade) cascade ).getFlowGraph();
101    }
102
103  public static IdentifierGraph getTapGraphFrom( Cascade cascade )
104    {
105    return ( (BaseCascade) cascade ).getIdentifierGraph();
106    }
107  }