Navigation Menu

Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Improving scale transformation service #4439

Merged
merged 1 commit into from Oct 19, 2017

Conversation

clinique
Copy link
Contributor

@clinique clinique commented Oct 18, 2017

to ensure that they match in the same order than the scale definition file as discussed
in PR openhab/openhab-docs#486

Signed-off-by: Gaël L'hopital glhopital@gmail.com

@clinique
Copy link
Contributor Author

@martinvw here is the PR for the scale transformation service

@ThomDietrich
Copy link
Contributor

Related to openhab/openhab-docs#486

Thanks!

Copy link
Contributor

@martinvw martinvw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @clinique nice that you resolved it, I really like that is more deterministic now!

I added some remarks, if you have any questions please let me know.

private static final long serialVersionUID = 3860553217028220119L;
private final HashSet<Object> keys = new LinkedHashSet<Object>();

public OrderedProperties() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider leaving this constructor away, it will be added by the compiler anyway

}
Optional<Range> match = data.keySet().stream().filter(range -> range.contains(value)).findFirst();
if (match.isPresent()) {
return data.get(match.get());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can also do it like this:

return data.entrySet().stream().
    filter(e -> e.getKey().contains(value)).
    findFirst().
    map(Map.Entry::getValue).
    orElseThrow(() -> new TransformationException("No matching range for '" + source + "'"));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review @martinvw . So much left to do on so small changes :) I still have to progress.


String transformedResponse = processor.transform(evaluationorder, source);
Assert.assertEquals("first", transformedResponse);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe leave out this newline, note that it also is a notice in the (upcoming) release of the static code analysis.

}

public Iterable<Object> orderedKeys() {
return Collections.list(keys());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we can also return keys direct;ly I do not yet see the added value of the current solution:

Set<Object> orderedKeys() {
   return keys;
}

@@ -37,28 +41,50 @@
/** RegEx to extract a scale definition */
private static final Pattern LIMITS_PATTERN = Pattern.compile("(\\[|\\])(.*)\\.\\.(.*)(\\[|\\])");

class OrderedProperties extends Properties {
private static final long serialVersionUID = 3860553217028220119L;
private final HashSet<Object> keys = new LinkedHashSet<Object>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the diamond operator, ie replace the second occurrence of the same generic by <>


@Override
public Enumeration<Object> keys() {
return Collections.<Object> enumeration(keys);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the diamond operator, ie replace the second occurrence of the same generic by <>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diamond operator does not work here. So left it as is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, sorry then Intellij had some other complaint about that line but its not that important :-)

@@ -37,28 +41,50 @@
/** RegEx to extract a scale definition */
private static final Pattern LIMITS_PATTERN = Pattern.compile("(\\[|\\])(.*)\\.\\.(.*)(\\[|\\])");

class OrderedProperties extends Properties {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should add the author and goal for this inner class as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this inner class be static I see no reason to have a reference to the the outer class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we document that this implementation has limitations, eg iterating over the entryset will not be Ordered, removing elements will cause misery etc.

@Test
public void testEvaluationOrder() throws TransformationException {
// Ensures that only first matching scale as presented in the file is taken in account
String evaluationorder = "scale/evaluationorder.scale";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we name the variable evaluationOrder :-)

to ensure that they match in the same order than the scale definition file as discussed
in PR eclipse-archived#486
Corrections following code review

Signed-off-by: Gaël L'hopital <glhopital@gmail.com>
Copy link
Contributor

@martinvw martinvw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks great!

@sjsf sjsf merged commit a5330c0 into eclipse-archived:master Oct 19, 2017
@sjsf
Copy link
Contributor

sjsf commented Oct 19, 2017

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants