Skip to content

Commit 06f5957

Browse files
committed
Issue-112 update javadoc and reformat the code
1 parent 4a111c1 commit 06f5957

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

3-0-java-core/3-6-3-crazy-regex/src/main/java/com/bobocode/se/CrazyRegex.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
* {@link CrazyRegex} is an exercise class. Each method returns Pattern class which
99
* should be created using regex expression. Every method that is not implemented yet
1010
* throws {@link ExerciseNotCompletedException}
11+
* <p>
12+
* TODO: remove exception and implement each method of this class using {@link Pattern}
13+
*
1114
* @author Andriy Paliychuk
12-
* TODO: remove exception and implement each method of this class using java.util.regex.Pattern
1315
*/
1416
public class CrazyRegex {
1517

@@ -23,7 +25,7 @@ public Pattern findSpecificWord() {
2325
}
2426

2527
/**
26-
* A Pattern that finds first word in text
28+
* A Pattern that finds first word in text
2729
*
2830
* @return a pattern that looks for the first word in text
2931
*/
@@ -103,8 +105,8 @@ public Pattern findSimplePhoneNumber() {
103105

104106
/**
105107
* A Pattern that finds numbers with following requirements:
106-
* - inside the number can be only digits from 0 to 5
107-
* - length 3
108+
* - inside the number can be only digits from 0 to 5
109+
* - length 3
108110
*
109111
* @return a pattern that looks for numbers with length 3 and digits from 0 to 5 in the middle
110112
*/
@@ -123,8 +125,8 @@ public Pattern findAllWordsWithFiveLength() {
123125

124126
/**
125127
* A Pattern that finds words and numbers with following constraints:
126-
* - not shorter than two symbols
127-
* - not longer than three symbols
128+
* - not shorter than two symbols
129+
* - not longer than three symbols
128130
*
129131
* @return a pattern that looks for words and numbers that not shorter 2 and not longer 3
130132
*/
@@ -143,7 +145,7 @@ public Pattern findAllWordsWhichBeginWithCapitalLetter() {
143145

144146
/**
145147
* A Pattern that finds only the following abbreviation:
146-
* - AK, AL, AR, AZ, CA, CO, CT, PR, PA, PD
148+
* - AK, AL, AR, AZ, CA, CO, CT, PR, PA, PD
147149
*
148150
* @return a pattern that looks for the abbreviations above
149151
*/
@@ -198,9 +200,9 @@ public Pattern findAllEmails() {
198200

199201
/**
200202
* A Pattern that finds the following examples of phone numbers:
201-
* - 555-555-5555
202-
* - 555.555.5555
203-
* - (555)555-5555
203+
* - 555-555-5555
204+
* - 555.555.5555
205+
* - (555)555-5555
204206
*
205207
* @return a pattern that looks for phone numbers patterns above
206208
*/
@@ -220,7 +222,7 @@ public Pattern findOnlyDuplicates() {
220222
/**
221223
* You have a text where all names recorded as first name, last name.
222224
* Create matcher and use method replaceAll to record that names as:
223-
* - last name first name
225+
* - last name first name
224226
*
225227
* @return String where all names recorded as last name first name
226228
*/
@@ -231,7 +233,7 @@ public String replaceFirstAndLastNames(String names) {
231233
/**
232234
* You have a text with phone numbers.
233235
* Create matcher and use method replaceAll to replace last digits:
234-
* - 555-XXX-XXXX
236+
* - 555-XXX-XXXX
235237
*
236238
* @return String where in all phone numbers last 7 digits replaced to X
237239
*/
@@ -241,9 +243,9 @@ public String replaceLastSevenDigitsOfPhoneNumberToX(String phones) {
241243

242244
/**
243245
* You have a text with resources and links to those resources:
244-
* - [Bobocode](https://www.bobocode.com)
246+
* - [Bobocode](https://www.bobocode.com)
245247
* Create matcher and use method replaceAll to get the following result:
246-
* - <a href="https://www.bobocode.com">Bobocode</a>
248+
* - <a href="https://www.bobocode.com">Bobocode</a>
247249
*
248250
* @return String where all resources embraced in href
249251
*/

3-0-java-core/3-6-3-crazy-regex/src/test/java/com/bobocode/se/CrazyRegexTest.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
import static java.util.stream.Collectors.joining;
1717
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
1818

19+
/**
20+
* A test class for {@link CrazyRegex}.
21+
*
22+
* @author Andriy Paliychuk
23+
*/
1924
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
2025
public class CrazyRegexTest {
2126

@@ -55,15 +60,15 @@ void findLastWord() {
5560
void findAllNumbers() {
5661
String result = regexChecker(crazyRegex.findAllNumbers(), text);
5762
assertThat(result).isEqualTo("\n01001\n03148\n02132\n412\n555\n1212\n412\n555" +
58-
"\n1234\n412\n555\n1234\n646\n555\n1234\n1");
63+
"\n1234\n412\n555\n1234\n646\n555\n1234\n1");
5964
}
6065

6166
@Test
6267
@Order(5)
6368
void findDates() {
6469
String result = regexChecker(crazyRegex.findDates(), json);
6570
assertThat(result).isEqualTo("\n2015-05-30\n2012-08-06\n2011-11-26\n2015-05-30\n2012-08-06\n" +
66-
"2011-11-26\n2015-05-30\n2012-08-06\n2011-11-26");
71+
"2011-11-26\n2015-05-30\n2012-08-06\n2011-11-26");
6772
}
6873

6974
@Test
@@ -99,7 +104,7 @@ void findSimplePhoneNumber() {
99104
void findNumbersFromZeroToFiveWithLengthThree() {
100105
String result = regexChecker(crazyRegex.findNumbersFromZeroToFiveWithLengthThree(), text);
101106
assertThat(result).isEqualTo("\n010\n031\n021\n412\n555\n121\n412" +
102-
"\n555\n123\n412\n555\n123\n555\n123");
107+
"\n555\n123\n412\n555\n123\n555\n123");
103108
}
104109

105110
@Test
@@ -114,16 +119,16 @@ void findAllWordsWithFiveLength() {
114119
void findAllLettersAndDigitsWithLengthThree() {
115120
String result = regexChecker(crazyRegex.findAllLettersAndDigitsWithLengthThree(), text);
116121
assertThat(result).isEqualTo("\nThe\nof\nthe\nand\nthe\nnot\nThe\nis\ndon\nyou\nnk\nnk\nThe\nCA\nAK\nPA\n412" +
117-
"\n555\ncom\n412\n555\n412\n555\n646\n555\nof\ncom\nnet\nor\nnyu\nedu\n1Z\naaa\nOf\nwww\ncom\ncom\nwww\ncom" +
118-
"\nis\nis\nam\nnot\nnot\nwhy\nwhy\nam\nok\ncat\ncat\ndog\ndog");
122+
"\n555\ncom\n412\n555\n412\n555\n646\n555\nof\ncom\nnet\nor\nnyu\nedu\n1Z\naaa\nOf\nwww\ncom\ncom\nwww\ncom" +
123+
"\nis\nis\nam\nnot\nnot\nwhy\nwhy\nam\nok\ncat\ncat\ndog\ndog");
119124
}
120125

121126
@Test
122127
@Order(13)
123128
void findAllWordsWhichBeginWithCapitalLetter() {
124129
String result = regexChecker(crazyRegex.findAllWordsWhichBeginWithCapitalLetter(), json);
125130
assertThat(result).isEqualTo("\nFront\nHazard\nAvoidance\nCamera" +
126-
"\nCuriosity\nFront\nHazard\nAvoidance\nCamera\nCuriosity\nRear\nHazard\nAvoidance\nCamera\nCuriosity");
131+
"\nCuriosity\nFront\nHazard\nAvoidance\nCamera\nCuriosity\nRear\nHazard\nAvoidance\nCamera\nCuriosity");
127132
}
128133

129134
@Test
@@ -160,8 +165,8 @@ void findOnlyLinksInJson() {
160165
String result = regexChecker(crazyRegex.findOnlyLinksInJson(), json);
161166
assertThat(result).isEqualTo(
162167
"\nhttp://mars.jpl.nasa.gov/msl-raw-images/proj/msl/redops/ods/surface/sol/01000/opgs/edr/fcam/FLB_486265257EDR_F0481570FHAZ00323M_.JPG\n" +
163-
"http://mars.jpl.nasa.gov/msl-raw-images/proj/msl/redops/ods/surface/sol/01000/opgs/edr/fcam/FRB_486265257EDR_F0481570FHAZ00323M_.JPG\n" +
164-
"http://mars.jpl.nasa.gov/msl-raw-images/proj/msl/redops/ods/surface/sol/01000/opgs/edr/rcam/RLB_486265291EDR_F0481570RHAZ00323M_.JPG"
168+
"http://mars.jpl.nasa.gov/msl-raw-images/proj/msl/redops/ods/surface/sol/01000/opgs/edr/fcam/FRB_486265257EDR_F0481570FHAZ00323M_.JPG\n" +
169+
"http://mars.jpl.nasa.gov/msl-raw-images/proj/msl/redops/ods/surface/sol/01000/opgs/edr/rcam/RLB_486265291EDR_F0481570RHAZ00323M_.JPG"
165170
);
166171
}
167172

@@ -170,7 +175,7 @@ void findOnlyLinksInJson() {
170175
void findAllEmails() {
171176
String result = regexChecker(crazyRegex.findAllEmails(), text);
172177
assertThat(result).isEqualTo("\njohnsmith@yahoo.com\nterek.koval@gmail.com\nterek@koval.net" +
173-
"\nterek.koval@nyu.edu");
178+
"\nterek.koval@nyu.edu");
174179
}
175180

176181
@Test
@@ -185,7 +190,7 @@ void findAllPatternsForPhoneNumbers() {
185190
void findOnlyDuplicates() {
186191
String result = regexChecker(crazyRegex.findOnlyDuplicates(), text);
187192
assertThat(result).isEqualTo("\nis is\ntext text\ndouble double\nI I\nnot not\nwhy why" +
188-
"\ncat cat\ndog\ndog\nfish fish");
193+
"\ncat cat\ndog\ndog\nfish fish");
189194
}
190195

191196
@Test
@@ -208,21 +213,21 @@ void replaceLastSevenDigitsOfPhoneNumberToX() {
208213
@Order(24)
209214
void insertLinksAndResourcesIntoHref() {
210215
String links = "[Bobocode](https://www.bobocode.com)" +
211-
"\n[LinkedIn](https://www.linkedin.com)" +
212-
"\n[Netflix](https://www.netflix.com)";
216+
"\n[LinkedIn](https://www.linkedin.com)" +
217+
"\n[Netflix](https://www.netflix.com)";
213218
String result = crazyRegex.insertLinksAndResourcesIntoHref(links);
214219
assertThat(result).isEqualTo(
215220
"<a href=\"https://www.bobocode.com\">Bobocode</a>\n" +
216-
"<a href=\"https://www.linkedin.com\">LinkedIn</a>\n" +
217-
"<a href=\"https://www.netflix.com\">Netflix</a>"
221+
"<a href=\"https://www.linkedin.com\">LinkedIn</a>\n" +
222+
"<a href=\"https://www.netflix.com\">Netflix</a>"
218223
);
219224
}
220225

221226
private String regexChecker(Pattern pattern, String str2WorkWith) {
222227
Matcher matcher = pattern.matcher(str2WorkWith);
223228
StringBuilder stringBuilder = new StringBuilder();
224229
while (matcher.find()) {
225-
if(matcher.group().length() != 0) {
230+
if (matcher.group().length() != 0) {
226231
stringBuilder.append("\n").append(matcher.group());
227232
}
228233
}

0 commit comments

Comments
 (0)