RtYamlLine.java:35-38: Right now, at every call of trimmed() an...
See original GitHub issueThe puzzle 52-54ded80a
in src/main/java/com/amihaiemil/camel/RtYamlLine.java
(lines 35-38) has to be resolved: Right now, at every call of trimmed() and indentation() the values are calculated. This isn’t efficient, so we need a decorator to cache these values. Let’s name it CachedYamlLine. It should be used like this: YamlLine line = new CachedYamlLine(new RtYamlLine(…));
The puzzle was created by amihaiemil on 13-Feb-17.
Estimate: 30 minutes, role: IMP.
If you have any technical questions, don’t ask me, submit new tickets instead. The task will be “done” when the problem is fixed and the text of the puzzle is removed from the source code.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@SherifWaly About decorators (because in the last PR you made, it seemed that you have a misunderstanding):
For a standard example, see the wikipedia page. It has a good example with the drawing of a window… note that the classic pattern involves an abstract class behind and only adds behavior after the call to
origin
method. But it is no problem to simplify it by using only an interface and adding behavior/after before doing the actual action.A good example in our code is
WellIndentedLine
, which “decorates” a givenYamlLine
, in that it validates its indentation (see method indentation()). You see, the default RtYamlLine.indentation() is only supposed to fetch the indentation, nothing more. But we also want to validate the indentation, relative to the previous line - that’s whatWellIndentedLine.indentation()
does.Also, besides fetching the indentation and checking its validity relative to the previous line, we also want to check that it is even, so we have EvenlyIndentedLine.indentation() which gets the indentation and checks if it’s even or not.
See how those decorators are used to wrap the default
RtYamlLine
when its read, hereFinally, we also do not want to execute these validations every time
indentation()
is called, or whentrimmed()
is called we don’t want to execute thetrim()
operation every time. So that’s what this task is for. This decorator will have the attributesprivate YamlLine origin
,private String trimmed
andprivate int indentation
… then, method indentation() will look like this:Same for
trimmed()
If something is not clear, please don’t hesitate to ask 😃
P.S. Sorry for this wall of text 😄
@amihaiemil Can I do this one ?