001/* 002 * Copyright (c) 2016-2017 Chris K Wensel <chris@wensel.net>. All Rights Reserved. 003 * Copyright (c) 2007-2017 Xplenty, Inc. All Rights Reserved. 004 * 005 * Project and contact information: http://www.cascading.org/ 006 * 007 * This file is part of the Cascading project. 008 * 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 */ 021 022package cascading.cascade; 023 024import java.util.HashMap; 025import java.util.Map; 026 027import cascading.cascade.planner.FlowGraph; 028import cascading.cascade.planner.IdentifierGraph; 029import cascading.flow.FlowDef; 030import cascading.pipe.Pipe; 031import cascading.tap.Tap; 032 033/** 034 * Class Cascades provides useful utilities for use in constructing {@link Cascade} and {@link cascading.flow.Flow} 035 * instances via the {@link CascadeConnector} and {@link cascading.flow.FlowConnector}, respectively. 036 * <p> 037 * See the {@link FlowDef} for the recommended alternative to dealing with Maps of Taps. 038 */ 039public class Cascades 040 { 041 /** 042 * Method tapsMap creates a new Map for the given name and tap. 043 * 044 * @param name of type String 045 * @param tap of type Tap 046 * @return Map 047 */ 048 public static Map<String, Tap> tapsMap( String name, Tap tap ) 049 { 050 return tapsMap( new String[]{name}, Tap.taps( tap ) ); 051 } 052 053 /** 054 * Method tapsMap creates a new Map for each name and tap. 055 * 056 * @param names of type String[] 057 * @param taps of type Tap[] 058 * @return Map 059 */ 060 public static Map<String, Tap> tapsMap( String[] names, Tap[] taps ) 061 { 062 Map<String, Tap> map = new HashMap<String, Tap>(); 063 064 for( int i = 0; i < names.length; i++ ) 065 map.put( names[ i ], taps[ i ] ); 066 067 return map; 068 } 069 070 /** 071 * Method tapsMap creates a new Map using the given Pipe name and tap. 072 * 073 * @param pipe of type Pipe 074 * @param tap of type Tap 075 * @return Map 076 */ 077 public static Map<String, Tap> tapsMap( Pipe pipe, Tap tap ) 078 { 079 return tapsMap( Pipe.pipes( pipe ), Tap.taps( tap ) ); 080 } 081 082 /** 083 * Method tapsMap creates a new Map using the given pipes and taps. 084 * 085 * @param pipes of type Pipe[] 086 * @param taps of type Tap[] 087 * @return Map 088 */ 089 public static Map<String, Tap> tapsMap( Pipe[] pipes, Tap[] taps ) 090 { 091 Map<String, Tap> map = new HashMap<String, Tap>(); 092 093 for( int i = 0; i < pipes.length; i++ ) 094 map.put( pipes[ i ].getName(), taps[ i ] ); 095 096 return map; 097 } 098 099 public static FlowGraph getFlowGraphFrom( Cascade cascade ) 100 { 101 return ( (BaseCascade) cascade ).getFlowGraph(); 102 } 103 104 public static IdentifierGraph getTapGraphFrom( Cascade cascade ) 105 { 106 return ( (BaseCascade) cascade ).getIdentifierGraph(); 107 } 108 }