Skip to content

Commit ebe4b26

Browse files
Shared libs for regEx (#16)
* shared libs for regEx * stepping the version
1 parent df2f74d commit ebe4b26

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.github.ericsson</groupId>
66
<artifactId>eiffel-commons-java</artifactId>
7-
<version>0.0.6</version>
7+
<version>0.0.7</version>
88
<name>eiffel commons java</name>
99
<description>A shared library for eiffel components</description>
1010

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.ericsson.eiffelcommons.utils;
2+
3+
import java.io.IOException;
4+
5+
import org.json.JSONObject;
6+
7+
public class RegExProvider {
8+
private static final String REGULAR_EXPRESSIONS_PATH = "regExs.json";
9+
10+
/**
11+
* This method returns Json Object for regular expressions
12+
*
13+
* @return JSONObject
14+
*/
15+
public static JSONObject getRegExs() throws IOException {
16+
17+
return Utils.getResourceFileAsJsonObject(REGULAR_EXPRESSIONS_PATH);
18+
}
19+
}

src/main/resources/regExs.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"invalidName" : "(\\W)",
3+
"validEmail" : "^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$"
4+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.ericsson.eiffelcommons.Utilstest;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.io.IOException;
6+
7+
import org.json.JSONException;
8+
import org.junit.Test;
9+
10+
import com.ericsson.eiffelcommons.utils.RegExProvider;
11+
12+
public class RegExProviderTest {
13+
14+
@Test
15+
public void test() {
16+
String regExForInvalidName = getValue("invalidName");
17+
String regExForValidEmail = getValue("validEmail");
18+
19+
assertEquals(regExForInvalidName, "(\\W)");
20+
assertEquals(regExForValidEmail,
21+
"^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$");
22+
}
23+
24+
/**
25+
* This function takes a key and returns the corresponding value from the
26+
* JSONObject
27+
*
28+
* @param String
29+
* key
30+
* @return String value
31+
*/
32+
public String getValue(String key) {
33+
String value = null;
34+
try {
35+
value = (String) RegExProvider.getRegExs().get(key);
36+
} catch (JSONException | IOException e) {
37+
e.printStackTrace();
38+
}
39+
return value;
40+
}
41+
}

0 commit comments

Comments
 (0)