This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.josefigueredo.patterns; | |
| import java.util.function.UnaryOperator; | |
| public class StrategyPatternRunner { | |
| public static void main(String[] args) { | |
| String originalText = "This is a test from December 8th, 2020"; | |
| String expectedText = "ThisisatestfromDecember8th,2020"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.josefigueredo.patterns; | |
| public class StrategyPatternRunner { | |
| public static void main(String[] args) { | |
| String originalText = "This is a test from December 8th, 2020"; | |
| String expectedText = "ThisisatestfromDecember8th,2020"; | |
| RemoveStrategy removeStrategy = s -> s.replace(" ", ""); | |
| noWhitespaces = Remover.remove(originalText, removeStrategy); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.josefigueredo.patterns; | |
| import com.josefigueredo.patterns.strategies.*; | |
| public class StrategyPatternRunner { | |
| public static void main(String[] args) { | |
| String originalText = "This is a test from December 8th, 2020"; | |
| String expectedText = "ThisisatestfromDecember8th,2020"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.josefigueredo.patterns.strategies; | |
| import com.josefigueredo.patterns.RemoveStrategy; | |
| import java.util.stream.Collectors; | |
| public class WhitespacesRemoverFunctionalByStdLib implements RemoveStrategy { | |
| @Override | |
| public String execute(String s) { | |
| return s.chars() | |
| .filter(c -> !Character.isWhitespace(c)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.josefigueredo.patterns.strategies; | |
| import com.josefigueredo.patterns.RemoveStrategy; | |
| public class WhitespacesRemoverImperative implements RemoveStrategy { | |
| @Override | |
| public String execute(String s) { | |
| StringBuilder sb = new StringBuilder(); | |
| for (int i = 0; i < s.length(); i++) { | |
| if (!Character.isWhitespace(s.charAt(i))) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.josefigueredo.patterns; | |
| import java.util.Objects; | |
| public final class Remover { | |
| private Remover() { | |
| throw new AssertionError("Remover cannot be instantiated"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.josefigueredo.patterns; | |
| @FunctionalInterface | |
| public interface RemoveStrategy { | |
| String execute(String s); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SRP | The Single Responsibility Principle | A class should have one and only one reason to change | |
|---|---|---|---|
| OCP | The Open Closed Principle | You should be able to extend a classes behavior without modifying it | |
| LSP | The Liskov Substitution Principle | Derived classes must be substitutable for their base classes | |
| ISP | The Interface Segregation Principle | Make fine grained interfaces that are client specific | |
| DIP | The Dependency Inversion Principle | Depend on abstractions not on concretions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| curl -H "Accept: text/event-stream" \ | |
| http://localhost:8080/stream |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| curl -X POST \ | |
| -H "Content-type: application/json" \ | |
| -d '{"text": "A simple tweet"}' \ | |
| http://localhost:8080/tweet |