other/inca-xml2csv/trunk/src/net/sf/basedb/inca/DateMasker.java

Code
Comments
Other
Rev Date Author Line
4191 31 Oct 16 nicklas 1 package net.sf.basedb.inca;
4191 31 Oct 16 nicklas 2
4191 31 Oct 16 nicklas 3 import java.util.regex.Pattern;
4191 31 Oct 16 nicklas 4
4191 31 Oct 16 nicklas 5 /**
4191 31 Oct 16 nicklas 6   Special masker implementation for dates that changes the day to
4191 31 Oct 16 nicklas 7   the 15th. The date must be written in YYYY-MM-DD format. If
4191 31 Oct 16 nicklas 8   the value can't be parsed as a date an empty string is returned
4191 31 Oct 16 nicklas 9   by the the masker. 
4191 31 Oct 16 nicklas 10   
4191 31 Oct 16 nicklas 11   @author nicklas
4191 31 Oct 16 nicklas 12   @since 1.1
4191 31 Oct 16 nicklas 13 */
4191 31 Oct 16 nicklas 14 public class DateMasker 
4191 31 Oct 16 nicklas 15   implements Masker
4191 31 Oct 16 nicklas 16 {
4191 31 Oct 16 nicklas 17   
4191 31 Oct 16 nicklas 18   private final Pattern datePattern;
4191 31 Oct 16 nicklas 19   
4191 31 Oct 16 nicklas 20   /**
4191 31 Oct 16 nicklas 21     Create a new date masker.
4191 31 Oct 16 nicklas 22   */
4191 31 Oct 16 nicklas 23   public DateMasker()
4191 31 Oct 16 nicklas 24   {
4191 31 Oct 16 nicklas 25     this.datePattern = Pattern.compile("\\d{4}\\-\\d{2}\\-\\d{2}");
4191 31 Oct 16 nicklas 26   }
4191 31 Oct 16 nicklas 27
4191 31 Oct 16 nicklas 28   /**
4191 31 Oct 16 nicklas 29     @return Always the 'maskedValue' given in the constructor
4191 31 Oct 16 nicklas 30   */
4191 31 Oct 16 nicklas 31   @Override
4191 31 Oct 16 nicklas 32   public String getMaskedValue(String value) 
4191 31 Oct 16 nicklas 33   {
4191 31 Oct 16 nicklas 34     String maskedValue = "";
4191 31 Oct 16 nicklas 35     if (datePattern.matcher(value).matches())
4191 31 Oct 16 nicklas 36     {
4191 31 Oct 16 nicklas 37       maskedValue = value.substring(0, 8) + "15";
4191 31 Oct 16 nicklas 38     }
4191 31 Oct 16 nicklas 39     return maskedValue;
4191 31 Oct 16 nicklas 40   }
4191 31 Oct 16 nicklas 41 }