Guest User

Untitled

a guest
Dec 13th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. //
  2. // CHALLENGE (work in pairs):
  3. // Move from f(o) -> o.f() and sure that the code is CQS compliant.
  4. //
  5.  
  6.  
  7. // 1
  8. // class CsvParser<T extends Lines> {
  9. // Collection<T> parse(File location) {
  10. // }
  11. // }
  12.  
  13. class Csv <T>{
  14. Collection<T extends Lines> content(File f);
  15. }
  16.  
  17. class CsvFile<T extends Lines>{
  18. public CsvFile(Path path);
  19. Collection<T> lines();
  20. //or return stream -> this means lazy and read only
  21. }
  22.  
  23.  
  24. // 2
  25. interface Ping {
  26. void send();
  27. }
  28.  
  29. or Endpoint{ (or antyhing)
  30. void ping();
  31. }
  32.  
  33.  
  34. // 3
  35. interface TcpSocket {
  36. Stream<Byte> read(); //verb so should return void
  37. Stream<Byte> stream(); // ok
  38. }
  39.  
  40.  
  41. // 4
  42. // Iovation - a company that maintains a blacklist of email addresses and corresponding IPs
  43. interface IovationClientRequest {
  44. String getEmail();
  45. String getIpAddress();
  46. boolean blockAccess();
  47. }
  48.  
  49.  
  50. this way:
  51.  
  52. interface IovationService {
  53. boolean shouldBlockWebsiteVisitor(WebsiteVisitor wv)
  54. }
  55.  
  56. interFACE WebsiteVisitor {
  57. String email();
  58. String ipAddress();
  59. }
  60.  
  61.  
  62.  
  63. // 5
  64. interface User{
  65. String username, password;
  66. Token authenticate() throws WrongUserCredentialsProvided
  67. }
  68.  
  69. this way:
  70.  
  71. interface Authentication{
  72. Authentication (String username, String password);
  73. Token token();
  74. void attempt();
  75. }
  76.  
  77. auth = new Authentication(...)
  78. auth.token();
  79.  
  80. // 6
  81. interface Test {
  82. interface Result {
  83. void prettyPrint();
  84. }
  85. boolean hasFinished();
  86. Collection<Test.Result> results();
  87. }
  88.  
  89. if (test.finished()) {
  90. //refactor into stream
  91. //test.results().forEach(Test.Result""prettyPrint)
  92. for (Test.Result testResult : test.results()) {
  93. testResult.prettyPrint();
  94. }
  95. }
  96.  
  97.  
  98. // 7
  99. boolean destroyButtonAvailable =
  100. widgets
  101. .stream()
  102. .filter(Widget::isButton)
  103. .filter(Buttonlabel::isRedButton)
  104. OR
  105. map Button::label
  106. filter "Destory the world"::equals
  107. OR anyMatch instead of filter
  108.  
  109. .isPresent();
  110.  
  111. class Buttonlabel implements Predicate<Button>{
  112. public static boolean isRedButton (Button b){
  113. return b.label().equals("Destroy The World");
  114. }
  115. }
  116.  
  117. // 8
  118. interface File {
  119. void openIfFound();
  120. }
Add Comment
Please, Sign In to add comment