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("Date mask matcher")
 @Description("Matches String values against a set of date masks, producing a corresponding set of output columns, specifying whether or not the strings could be interpreted as dates given those date masks")
 public class DateMaskMatcherTransformer implements Transformer {
 
 	public static final String[] DEFAULT_DATE_MASKS = new String[] { "yyyy-MM-dd""yyyy/MM/dd""dd.MM.yyyy""dd/MM/yyyy",
 			"MM/dd/yy""d MMM yyyy HH:mm:ss""yyyy-MM-dd HH:mm:ss.S" };
 
 
 
 
 
 		 = column;
 	}
 
 	}
 
 	public void init() {
 		for (int i = 0; i < .i++) {
 			try {
 				[i] = DateTimeFormat.forPattern([i]);
 			} catch (Exception e) {
 				// not a valid pattern!
 				[i] = null;
 			}
 		}
 	}
 
 		String columnName = .getName();
 		String[] names = new String[.];
 		for (int i = 0; i < names.lengthi++) {
 			names[i] = columnName + " '" + [i] + "'";
 		}
 		Class<?>[] types = new Class[.];
 		for (int i = 0; i < types.lengthi++) {
 			types[i] = .getOutputClass();
 		}
 		return new OutputColumns(namestypes);
 	}
 
 	public Object[] transform(InputRow inputRow) {
 		Object[] result = new Object[.];
 
 			Arrays.fill(resultfalse);
 		}
 
		String value = inputRow.getValue();
		if (value != null) {
			for (int i = 0; i < .i++) {
				DateTimeFormatter dateTimeFormatter = [i];
				if (dateTimeFormatter != null) {
					boolean match = false;
					try {
						// this will throw an exception if the value is not
						// complying to the pattern
						dateTimeFormatter.parseDateTime(value);
						match = true;
catch (Exception e) {
						// ignore, it doesn't match
					}
						result[i] = match;
						if (match) {
							result[i] = value;
else {
							result[i] = null;
						}
					}
				}
			}
		}
		return result;
	}
	public void setDateMasks(String[] dateMasks) {
		 = dateMasks;
	}
	public String[] getDateMasks() {
		return ;
	}
New to GrepCode? Check out our FAQ X