ShortcutEvent extends EventObject implements Serializable { public boolean matches(Key key, KeyModifier... keyModifiers) { if (key == null) { return false; } if (keyModifiers.length != this.keyModifiers.size()) { return false; } List<String> keyStrings = Stream.of(keyModifiers) .map(k -> k.getKeys().get(0)).collect(Collectors.toList()); return key.matches(this.key.getKeys().get(0)) && this.keyModifiers .stream().allMatch(k -> keyStrings.stream() .anyMatch(k::matches)); } ShortcutEvent(Component source, Component lifecycleOwner, Key key,
                         Set<KeyModifier> keyModifiers); @Override Component getSource(); Component getLifecycleOwner(); Key getKey(); Set<KeyModifier> getKeyModifiers(); boolean matches(Key key, KeyModifier... keyModifiers);  }
@Test public void matches() { assertFalse("Null key should return false", eventNoModifiers.matches(null)); assertFalse("Extra modifier should return false", eventNoModifiers.matches(Key.KEY_F, KeyModifier.ALT)); assertFalse("Missing modifier should return false", eventOneModifier.matches(Key.KEY_F)); assertTrue("Matching key should return true", eventNoModifiers.matches(Key.KEY_F)); assertTrue("Matching key and modifier should return true", eventOneModifier.matches(Key.KEY_F, KeyModifier.ALT)); assertTrue("Matching key and two modifiers should return true", eventTwoModifiers.matches(Key.KEY_F, KeyModifier.ALT, KeyModifier.CONTROL)); }