|
1 | 1 | /* |
2 | | - * Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
24 | 24 | */ |
25 | 25 | package sun.awt; |
26 | 26 |
|
27 | | -import java.util.Collections; |
28 | 27 | import java.util.HashMap; |
29 | 28 | import java.util.HashSet; |
30 | 29 | import java.awt.event.KeyEvent; |
31 | 30 |
|
32 | 31 | public class ExtendedKeyCodes { |
33 | 32 | /** |
34 | 33 | * ATTN: These are the readonly hashes with load factor == 1; |
35 | | - * adding a value, please set the inital capacity to exact number of items |
| 34 | + * adding a value, please set the initial capacity to exact number of items |
36 | 35 | * or higher. |
37 | 36 | */ |
38 | 37 | // Keycodes declared in KeyEvent.java with corresponding Unicode values. |
39 | | - private static final HashMap<Integer, Integer> regularKeyCodesMap = |
40 | | - new HashMap<Integer,Integer>(98, 1.0f); |
| 38 | + private static final HashMap<Integer, Integer> regularKeyCodesMap = |
| 39 | + new HashMap<>(98, 1.0f); |
41 | 40 |
|
42 | 41 | // Keycodes derived from Unicode values. Here should be collected codes |
43 | 42 | // for characters appearing on the primary layer of at least one |
44 | 43 | // known keyboard layout. For instance, sterling sign is on the primary layer |
45 | 44 | // of the Mac Italian layout. |
46 | 45 | private static final HashSet<Integer> extendedKeyCodesSet = |
47 | | - new HashSet<Integer>(496, 1.0f); |
48 | | - public static final int getExtendedKeyCodeForChar( int c ) { |
| 46 | + new HashSet<>(496, 1.0f); |
| 47 | + public static int getExtendedKeyCodeForChar( int c ) { |
49 | 48 | int uc = Character.toUpperCase( c ); |
50 | | - int lc = Character.toLowerCase( c ); |
51 | | - if (regularKeyCodesMap.containsKey( c )) { |
52 | | - if(regularKeyCodesMap.containsKey(uc)) { |
53 | | - return regularKeyCodesMap.get( uc ); |
54 | | - } |
55 | | - return regularKeyCodesMap.get( c ); |
| 49 | + Integer regularKeyCode = regularKeyCodesMap.get(c); |
| 50 | + if (regularKeyCode != null) { |
| 51 | + return regularKeyCodesMap.getOrDefault(uc, regularKeyCode); |
56 | 52 | } |
57 | 53 | uc += 0x01000000; |
58 | | - lc += 0x01000000; |
59 | 54 | if (extendedKeyCodesSet.contains( uc )) { |
60 | 55 | return uc; |
61 | | - }else if (extendedKeyCodesSet.contains( lc )) { |
| 56 | + } |
| 57 | + int lc = Character.toLowerCase( c ); |
| 58 | + lc += 0x01000000; |
| 59 | + if (extendedKeyCodesSet.contains( lc )) { |
62 | 60 | return lc; |
63 | 61 | } |
64 | 62 | return KeyEvent.VK_UNDEFINED; |
|
0 commit comments