Open GoogleCodeExporter opened 9 years ago
This is a good suggestion, thanks!
There is a subtle difference though in how contains might be implemented. In
your example above, "TO" was never added to the tree explicitly. So I'm not
sure that contains() should return true for that(?)
There are two options for how contains("TO") could be implemented:
Option 1:
return tree.getKeysStartingWith("TO").hasNext()
Option 2:
return tree.getValueForExactKey("TO") != null
TBH I'd probably lean towards the second option. But both options are possible.
Original comment by ni...@npgall.com
on 25 Sep 2014 at 2:16
If "TO" would return true (even if it was never added explicitly) this would
fit my need =)
Your option 1:
With my example above: return tree.getKeysStartingWith("TOAST").hasNext() would
return false, but should return true.
your option 2:
I'm not sure if this will work... tree.getValueForExactKey("TO") returns null,
right? So null != null will be false. But I ran an example: this case returns
true. But it also returns true for tree.getValueForExactKey("FOO") != null
Original comment by steffen...@web.de
on 25 Sep 2014 at 2:39
edit to my last comment: If contains("TO") would return true (even if it was
never added explicitly) this would fit my needs =)
Original comment by steffen...@web.de
on 25 Sep 2014 at 2:41
(Why can't I edit my comment? Sorry for multiposting...)
A combination of both would work:
return (tree.getKeysStartingWith("TO").hasNext() ||
tree.getValueForExactKey("TO"))
return (tree.getKeysStartingWith("TOAST").hasNext() ||
tree.getValueForExactKey("TOAST"))
both return true.
Maybe you can implement .contains() and .containsExact()
=D
Original comment by steffen...@web.de
on 25 Sep 2014 at 2:48
If tree.getValueForExactKey("TO") != null, then
tree.getKeysStartingWith("TO").hasNext() would return true also actually. So we
only need to evaluate getValueForExactKey() there.
I think there should be a contains() method, but I think it should indicate if
the key was added to the tree explicitly. So it would be more like your
containsExact() idea. That would be consistent with contains() in Java
collections framework. So the implementation might be:
public boolean contains(CharSequence key) {
return tree.getValueForExactKey(key) != null;
}
There is already a reasonably nice API to check if keys starting with "TO" are
contained in the tree:
tree.getKeysStartingWith("TOAST").hasNext()
So hopefully with those two APIs available people would have a choice.
Original comment by ni...@npgall.com
on 25 Sep 2014 at 5:44
Original issue reported on code.google.com by
steffen...@web.de
on 25 Sep 2014 at 1:34