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 |
Special masker implementation for dates that changes the day to |
4191 |
31 Oct 16 |
nicklas |
the 15th. The date must be written in YYYY-MM-DD format. If |
4191 |
31 Oct 16 |
nicklas |
the value can't be parsed as a date an empty string is returned |
4191 |
31 Oct 16 |
nicklas |
by the the masker. |
4191 |
31 Oct 16 |
nicklas |
10 |
|
4191 |
31 Oct 16 |
nicklas |
@author nicklas |
4191 |
31 Oct 16 |
nicklas |
@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 |
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 |
@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 |
} |