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.tuple; 023 024import java.util.ArrayList; 025import java.util.List; 026import java.util.Map; 027import java.util.Properties; 028 029import cascading.property.Props; 030import cascading.util.Util; 031 032/** 033 * Class TupleEntrySchemeIteratorProps is a fluent helper class to set properties which control the behavior of the 034 * {@link cascading.tuple.TupleEntrySchemeIterator}. 035 */ 036public class TupleEntrySchemeIteratorProps extends Props 037 { 038 public static final String PERMITTED_EXCEPTIONS = "cascading.tuple.tupleentryiterator.exceptions.permit"; 039 040 private Class<? extends Exception>[] permittedExceptions = null; 041 042 /** 043 * Method setPermittedExceptions is used to set an array of exceptions, which are allowed to be ignored in the 044 * TupleEntySchemeInterator. If the array is null, it will be ignored. 045 * <p> 046 * Note that the array will be converted to a comma separated String. If you read the the property back, you can 047 * convert it back to classes via the asClasses method. 048 * 049 * @param properties a Map 050 * @param exceptions an array of exception classes. 051 */ 052 public static void setPermittedExceptions( Map<Object, Object> properties, Class<? extends Exception>... exceptions ) 053 { 054 if( exceptions != null ) 055 { 056 List<String> classNames = new ArrayList<String>(); 057 058 for( Class<? extends Exception> clazz : exceptions ) 059 classNames.add( clazz.getName() ); 060 061 properties.put( PERMITTED_EXCEPTIONS, Util.join( classNames, "," ) ); 062 } 063 } 064 065 /** 066 * Creates a new TupleEntrySchemeIteratorProps instance. 067 * 068 * @return TupleEntrySchemeIteratorProps instance 069 */ 070 public static TupleEntrySchemeIteratorProps tupleEntrySchemeIteratorProps() 071 { 072 return new TupleEntrySchemeIteratorProps(); 073 } 074 075 /** 076 * Constructs a new TupleEntrySchemeIteratorProps instance. 077 */ 078 public TupleEntrySchemeIteratorProps() 079 { 080 } 081 082 public Class<? extends Exception>[] getPermittedExceptions() 083 { 084 return permittedExceptions; 085 } 086 087 /** 088 * Method setPermittedExceptions is used to set an array of exceptions which are allowed to be ignored in the 089 * TupleEntrySchemeIterator. 090 * <p> 091 * If the array is null, it will be ignored. 092 * 093 * @param permittedExceptions an array of exception classes. 094 */ 095 public TupleEntrySchemeIteratorProps setPermittedExceptions( Class<? extends Exception>[] permittedExceptions ) 096 { 097 this.permittedExceptions = permittedExceptions; 098 return this; 099 } 100 101 @Override 102 protected void addPropertiesTo( Properties properties ) 103 { 104 setPermittedExceptions( properties, permittedExceptions ); 105 } 106 }