Guest User

Untitled

a guest
Jan 17th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. //
  2. // CHALLENGE (work in pairs):
  3. // Move from f(o) -> o.f() and make sure that the code is CQS compliant.
  4. //
  5.  
  6.  
  7. // 1
  8. //class CsvParser<T extends Line> {
  9. // Collection<T> parse(File location) {
  10. // }
  11. //}
  12.  
  13. class Csv<T extends Line> {
  14. private final File location;
  15.  
  16. Csv(File location){
  17. this.location = location;
  18. }
  19.  
  20. Collection<T> lines(){
  21. }
  22. }
  23.  
  24. // 2
  25. //interface Pinger {
  26. // void sendPing();
  27. //}
  28.  
  29. interface Ping {
  30. void send();
  31. }
  32.  
  33. // 3
  34. //interface TcpSocket {
  35. // Stream<Byte> startReading();
  36. //}
  37.  
  38. interface Content {
  39. Stream<Byte> bytes();
  40. String text();
  41. }
  42.  
  43. interface TcpSocket {
  44. Content content();
  45. }
  46.  
  47. // 4
  48. // Make me CQS friendly!
  49. //interface Input {
  50. // boolean validate();
  51. //}
  52.  
  53. interface Input {
  54. void validate();
  55. boolean isValid();
  56. }
  57.  
  58. // 5
  59. // Iovation - a company that maintains a blacklist of email addresses and corresponding IPs
  60. //interface IovationService {
  61. // boolean shouldBlockWebsiteVisitor(IovationClientRequest request);
  62. //}
  63.  
  64. //interface IovationClientRequest {
  65. // String getEmail();
  66. // String getIpAddress();
  67. //}
  68.  
  69. class IovationClient {
  70. private final IovationClientRequest request;
  71.  
  72. IovationClient(IovationClientRequest request){
  73. this.request = request;
  74. }
  75.  
  76. boolean blocked();
  77. }
  78.  
  79. interface IovationClientRequest {
  80. String email();
  81. String ip();
  82. }
  83.  
  84.  
  85. // 6
  86. //interface AnonymousUserAuthenticator {
  87. // Token authenticate(String username, String password) throws WrongAuthenticationCredentialsProvided;
  88. //}
  89.  
  90. interface AnonymousUser {
  91. private final String username;
  92. private final String password;
  93.  
  94. AnonymousUser(String username, String password){
  95. this.username = username;
  96. this.password = password;
  97. }
  98.  
  99. void authenticate() throws WrongAuthenticationCredentialsProvided;
  100.  
  101. AuthenticatedUser authenticatedUser();
  102. }
  103.  
  104. interface AuthenticatedUser {
  105. Token token();
  106. }
  107.  
  108. // 7
  109. //interface Suite {
  110. // interface SuiteTest {
  111. // void print();
  112. // boolean successful()
  113. // }
  114. // void runAndWait();
  115. // Collection<SuiteTest> listSuiteTests();
  116. //}
  117.  
  118. //suite.runAndWait()
  119. //for (SuiteTest suiteTest : suite.listSuiteTests()) {
  120. // if (!suiteTest.successful() ) {
  121. // // pretty printing
  122. // suiteTest.print();
  123. // }
  124. //}
  125.  
  126. interface TestsSuite {
  127. interface Test {
  128. void printPretty();
  129. boolean successful();
  130. boolean unsuccessful();
  131. }
  132. void run();
  133. Collection<Test> tests();
  134. }
  135.  
  136. testsSuite.run()
  137. testsSuite.tests()
  138. .stream()
  139. .filter(Test::unsuccessful)
  140. .forEach(Test::printPretty);
  141.  
  142.  
  143. // 8
  144. // Booleans are queries, but exception to the CQR rule naming. They are not nouns. Let's fix it (guess how).
  145. enum Severity {
  146. boolean major();
  147. }
  148.  
  149. class Specification {
  150. boolean satisfiedBy(Entity entity);
  151. }
  152.  
  153.  
  154. // 9
  155. //boolean destroyButtonAvailable =
  156. // widgets
  157. // .stream()
  158. // .filter(Widget::isButton)
  159. // .filter(button -> button.label().equals("Destroy The World"))
  160. // .isPresent();
  161.  
  162. boolean destroyButtonAvailable =
  163. widgets
  164. .stream()
  165. .filter(Widget::isButton)
  166. .map(Widget::label)
  167. .anyMatch(label -> label.equals("Destroy The World"));
  168.  
  169.  
  170. // 10 transform a full name into a twitter handle. Jack Ma must become @jack.ma
  171. class TwitterName{
  172. TwitterName(String fullname){
  173. }
  174.  
  175. String toString(){
  176. return @ + fullname;
  177. }
  178. }
  179.  
  180. String fullName = "Jack Ma";
  181. ...
  182. String twitterHandle =
Add Comment
Please, Sign In to add comment