Interesting problem which can be explained with the node interna and auot-boxing in Java: the double is not a generic rather than a Object of type Double, calling col0 == col1 compares object references from col0 and col1. Two workarounds are possible, you either use col0.doubleValue() == col1.doubleValue() or col0.compareTo(col1) == 0.
This has to do with Java's unboxing of number objects. The variables are objects and not number, but Java is intelligent enough to use numeric comparators for < and >. But == is a valid operator for objects (reference identity) and therefore not automatically replaced by a numeric comparison. You could use col1.equals(col2) though (except if you have missing values in col1).
Thanks this makes it clear, but I still think KNIME should not treat my defined double variables as objects. I would expect to seem the same behavior in KNIME as I find in eclipse, so I class this as a bug.
But how would you represent missing values then? If you are using Number objects "null" is perfect for a missing value. If you use doubles, then what would be the equivalent of a missing entry?
Well, it behaves correctly, exactly as using Number objects in Java does. Also, throwing an error if there is a missing value in the input doesn't make much sense in general. In many cases you want to treat them somehow, if only just ignore them. Believe me, there are good reasons why it's working as it is.
I also face the same problem with equality when using Java Snippet. I find it very confusing that the Java Snippet nodes do not give same output for a code as excuted in Netbeans or Eclipse.
I understand that there might be some reasons for this. But I expect seeing that 'val_1' == 'val_1' is true. Or at least if Knime evaluates 'val_1' == 'val_1' to false then it should also evaluate 'val_2' == 'val_2' to false, too.
I have attached a figure demostrating this.
Another question related to this: in the column list the type ' i ' stands for int or Integer?
Actually it works similarly. Just try the following in Java:
new String("val1") == new String("val1")
Something similar happens behind the scenes. You should use the equals method when you are working with objects. (With integers you might face surprises when the absolute value is higher than 128 on Oracle JVM.)
Thanks for your prompt reply. I understand what you mean, but how do I know if "i" stands for the primitive int or for Integer? I assumed it stands for int. Ok, so if I use the class methods I guess I will be on the safe side.
Proabably a statically imported equals method would help to compare values for equality. Something which can handle the missing values:
/**
* Somewhat safe equals method.
*
* @param left An object.
* @param right Another object.
* @param <T> Common type of both objects.
* @return Both have the same values (assuming equals is properly defined on {@code left})?
*/
public static final <T> boolean equals(T left, T right) {
if (left == null) {
return right == null;
}
return right != null && left.equals(right);
}
Probably the T parameter is not so important, but might give further compile-time checks if specified. (For example this would fail to compile: equals<String>(myString, myInteger).) This has the advantage that it does not always compare NaNs as not equals (unlike ==). Do you think this would help reduce confusion?
need help regarding .I am using column filter and i want to compare entries in a same columns downwords...and i want to store there results also in columns...