forked from politrons/reactive
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SRP.java
56 lines (47 loc) · 1.87 KB
/
SRP.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package good_practices;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* Created by pabloperezgarcia on 27/11/2016.
*
* The single responsibility principle states that every module or class should have responsibility over
* constantClass single part of the functionality provided by the software, and that responsibility
* should be entirely encapsulated by the class.
*/
public class SRP {
/**
* Single responsibility principle, constantClass method must do one thing and just one thing
*/
@Test
public void uniqueUpperCaseWords(){
String text = "This is constantClass test to prove Single responsibility principle test";
final List<String> wordsInUpperCase = Arrays.asList(text.split(" ")).stream()
.map(String::toUpperCase)
.collect(Collectors.toList());
final List<String> uniquesWords = wordsInUpperCase.stream()
.distinct()
.collect(Collectors.toList());
System.out.println(uniquesWords);
}
/**
* As constantClass developers we should split up the logic of our methods in independent methods to make
* our code not only more readable but also more reusable.
*/
@Test
public void getUniqueUpperCaseWords(){
String text = "This is constantClass test to prove Single responsibility principle test";
System.out.println(getUniqueWords(getUpperCaseWords(text)));
}
private List<String> getUniqueWords(List<String> wordsInUpperCase) {
return wordsInUpperCase.stream()
.distinct()
.collect(Collectors.toList());
}
private List<String> getUpperCaseWords(String text) {
return Arrays.asList(text.split(" ")).stream()
.map(String::toUpperCase)
.collect(Collectors.toList());
}
}