|
1
|
|
|
/* |
|
2
|
|
|
* Copyright 2014, Armenak Grigoryan, and individual contributors as indicated |
|
3
|
|
|
* by the @authors tag. See the copyright.txt in the distribution for a |
|
4
|
|
|
* full listing of individual contributors. |
|
5
|
|
|
* |
|
6
|
|
|
* This is free software; you can redistribute it and/or modify it |
|
7
|
|
|
* under the terms of the GNU Lesser General Public License as |
|
8
|
|
|
* published by the Free Software Foundation; either version 2.1 of |
|
9
|
|
|
* the License, or (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* This software is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14
|
|
|
* Lesser General Public License for more details. |
|
15
|
|
|
*/ |
|
16
|
|
|
package com.strider.datadefender.anonymizer.functions; |
|
17
|
|
|
|
|
18
|
|
|
import java.io.IOException; |
|
19
|
|
|
|
|
20
|
|
|
import org.apache.commons.lang3.RandomUtils; |
|
21
|
|
|
|
|
22
|
|
|
import lombok.extern.log4j.Log4j2; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Built-in anonymization helper functions for address field anonymization. |
|
26
|
|
|
* |
|
27
|
|
|
* @author Armenak Grigoryan |
|
28
|
|
|
*/ |
|
29
|
|
|
@Log4j2 |
|
30
|
|
|
public class Address extends Core { |
|
31
|
|
|
|
|
32
|
|
|
public String randomCountry() throws IOException { |
|
33
|
|
|
return randomStringFromStream( |
|
34
|
|
|
"resource:countries.txt", |
|
35
|
|
|
() -> Lipsum.class.getResourceAsStream("countries.txt") |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public String randomCity() throws IOException { |
|
40
|
|
|
return randomStringFromStream( |
|
41
|
|
|
"resource:cities.txt", |
|
42
|
|
|
() -> Lipsum.class.getResourceAsStream("cities.txt") |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public String randomStreet() throws IOException { |
|
47
|
|
|
return randomStringFromStream( |
|
48
|
|
|
"resource:streets.txt", |
|
49
|
|
|
() -> Lipsum.class.getResourceAsStream("streets.txt") |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public String randomProvinceState() throws IOException { |
|
54
|
|
|
return randomStringFromStream( |
|
55
|
|
|
"resource:provinces_states.txt", |
|
56
|
|
|
() -> Lipsum.class.getResourceAsStream("provinces_states.txt") |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public String randomProvinceStateCode() throws IOException { |
|
61
|
|
|
return randomStringFromStream( |
|
62
|
|
|
"resource:provinces_states_codes.txt", |
|
63
|
|
|
() -> Lipsum.class.getResourceAsStream("provinces_states_codes.txt") |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public String randomCanadianPostalCode() { |
|
68
|
|
|
return randomStringFromPattern("[A-Z][0-9][A-Z] [0-9][A-Z][0-9]"); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public String randomUsZipCode() { |
|
72
|
|
|
return randomStringFromPattern("[0-9]{5}"); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public String randomUsZipCodeNineDigit() { |
|
76
|
|
|
return randomStringFromPattern("[0-9]{5}-[0-9]{4}"); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public String randomCanadianOrUsFiveDigitPostalCode() { |
|
80
|
|
|
if (RandomUtils.nextBoolean()) { |
|
81
|
|
|
return randomCanadianPostalCode(); |
|
82
|
|
|
} |
|
83
|
|
|
return randomUsZipCode(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public String randomCanadianOrUsFiveOrNineDigitPostalCode() { |
|
87
|
|
|
if (RandomUtils.nextBoolean()) { |
|
88
|
|
|
return randomCanadianPostalCode(); |
|
89
|
|
|
} else if (RandomUtils.nextBoolean()) { |
|
90
|
|
|
return randomUsZipCode(); |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
return randomUsZipCodeNineDigit(); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|