Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
DataCleaner (community edition) Copyright (C) 2014 Neopost - Customer Information Management This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the GNU Lesser General Public License, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this distribution; if not, write to: Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA
 
 package org.datacleaner.beans.transform;
 
 
 
 @Named("String pattern matcher")
 @Description("Matches string values against a set of string patterns, producing a corresponding set of output columns specifying whether or not the values matched those string patterns")
 public class StringPatternMatcherTransformer implements Transformer {
 
 
 
 
 	public StringPatternMatcherTransformer(InputColumn<?> columnStringPattern[] stringPatterns) {
 		this();
 		 = column;
 		 = stringPatterns;
 	}
 
 	}
 
 		String columnName = .getName();
 		String[] names = new String[.];
 		for (int i = 0; i < names.lengthi++) {
 			names[i] = columnName + " '" + [i].getName() + "'";
 		}
 		Class<?>[] types = new Class[.];
 		for (int i = 0; i < types.lengthi++) {
 			types[i] = .getOutputClass();
 		}
 		return new OutputColumns(namestypes);
 	}
 
 	public Object[] transform(InputRow inputRow) {
 		Object value = inputRow.getValue();
 		Object[] result = doMatching(value);
 		return result;
 	}
 
 	public Object[] doMatching(Object value) {
 		Object[] result = new Object[.];
 		String stringValue = ConvertToStringTransformer.transformValue(value);
 
 		for (int i = 0; i < result.lengthi++) {
 			boolean matches = [i].matches(stringValue);
 				result[i] = matches;
 			} else if ( == .) {
 				if (matches) {
 					result[i] = stringValue;
 				} else {
 					result[i] = null;
 				}
 			}
 		}
 		return result;
 	}
 
 	public void setStringPatterns(StringPattern[] stringPatterns) {
 		 = stringPatterns;
	}
	public void setColumn(InputColumn<?> column) {
		 = column;
	}
New to GrepCode? Check out our FAQ X