Hi Andy and List,
I did some checking on the internal KeyBinding, and I think it has a
broken hashCode/equals implementation, which if used as part of a map (I
think they aren't currently) would mean it won't find always find the
correct (or any) match with a simple Map#get.
This is because the hashCode for modifiers returns unique values for
TRUE, FALSE and ANY, but equals accepts that ANY can match TRUE or
FALSE. So, if you look up a binding, the hash code generated may not be
the same for a binding for the same KeyCode depending on the modifier
state, even though equals would consider it matching -- the map would
then look in the wrong bucket, and may miss the match.
Therefore, I simpy only put KeyCode in a Map as key, then do further
specific checking for modifiers.
I haven't checked your implementation, but it might be something you
need to be aware of.
Anyway, as I lookup by KeyCode, and then look through a list for which I
call KeyCodeCombination#match, I have no problems reusing
KeyCodeCombination.
--John
On 30/11/2023 00:09, Andy Goryachev wrote:
The rationale was this: I wanted KeyBinding to be a key in a hash
map. KeyCodeCombination cannot be used as keys since they might
correspond to multiple key combinations, as far as I can tell. Also,
it would necessitate the use of a linear search in some cases.
I did not like the internal KeyBinding as it wasn’t convenient enough
for my taste. I wanted something that can be easily created. There
were some early ideas about coding platform specificity into the KB,
but either you or Michael mentioned that this isn’t really necessary.
KeyBinding also deals with shortcut, meta, and option modifiers to get
what I want.
Can I copy my response to the list?
Sorry, I copied it now.
--John
Cheers,
-andy
*From: *John Hendrikx <john.hendr...@gmail.com>
*Date: *Wednesday, November 29, 2023 at 14:57
*To: *Andy Goryachev <andy.goryac...@oracle.com>
*Subject: *[External] : KeyCodeCombination
Hi Andy,
I think you mentioned there was a reason for introducing a new
KeyBinding type class (or at least copying part of the internal one).
I've used KeyCodeCombination now, and this seems to do everything I
really want (including having a `match` method that can match it against
a KeyEvent).
What were problems you encountered using this class, or what was the
reasoning for introducing a new class for key bindings?
--John