question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RtYamlLine.java:35-38: Right now, at every call of trimmed() an...

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
amihaiemilcommented, Mar 6, 2017

@SherifWaly About decorators (because in the last PR you made, it seemed that you have a misunderstanding):

  • A decorator is supposed to implement the same interface as the object being decorated and add behavior on top of it

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 given YamlLine, 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 what WellIndentedLine.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, here

Finally, we also do not want to execute these validations every time indentation() is called, or when trimmed() is called we don’t want to execute the trim() operation every time. So that’s what this task is for. This decorator will have the attributes private YamlLine origin, private String trimmed and private int indentation… then, method indentation() will look like this:

public int indentation() {
    if (this.indentation == null) {
        this.indentation = this.origin.indentation();
    }
    return this.indentation;
}

Same for trimmed()

If something is not clear, please don’t hesitate to ask 😃

P.S. Sorry for this wall of text 😄

1reaction
SherifWalycommented, Mar 5, 2017

@amihaiemil Can I do this one ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found