X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTKeypress.java;fp=src%2Fjexer%2FTKeypress.java;h=8143f151006af3fc656a8188d66b6d660c576802;hb=e826b451baf0d1e66d09ce03a6fefee2eb8386f5;hp=54be5d3e24b7df43bc37fb26378a5516355a6624;hpb=2b9c27db318b916730aa04f2b41bd3bff795a5dc;p=fanfix.git diff --git a/src/jexer/TKeypress.java b/src/jexer/TKeypress.java index 54be5d3..8143f15 100644 --- a/src/jexer/TKeypress.java +++ b/src/jexer/TKeypress.java @@ -298,6 +298,25 @@ public final class TKeypress { && (shift == that.shift)); } + /** + * Hashcode uses all fields in equals(). + * + * @return the hash + */ + @Override + public int hashCode() { + int A = 13; + int B = 23; + int hash = A; + hash = (B * hash) + (isKey ? 1 : 0); + hash = (B * hash) + fnKey; + hash = (B * hash) + (int)ch; + hash = (B * hash) + (alt ? 1 : 0); + hash = (B * hash) + (ctrl ? 1 : 0); + hash = (B * hash) + (shift ? 1 : 0); + return hash; + } + /** * Make human-readable description of this TKeypress. * @@ -471,16 +490,14 @@ public final class TKeypress { } /** - * Convert a keypress to lowercase. Function keys and ctrl keys are not - * converted. + * Convert a keypress to lowercase. Function keys and alt/ctrl keys are + * not converted. * - * @param key keypress to convert * @return a new instance with the key converted */ - public static TKeypress toLower(final TKeypress key) { - TKeypress newKey = new TKeypress(key.isKey, key.fnKey, key.ch, - key.alt, key.ctrl, key.shift); - if (!(key.isKey) && (key.ch >= 'A') && (key.ch <= 'Z') && (!key.ctrl)) { + public TKeypress toLowerCase() { + TKeypress newKey = new TKeypress(isKey, fnKey, ch, alt, ctrl, shift); + if (!isKey && (ch >= 'A') && (ch <= 'Z') && !ctrl && !alt) { newKey.shift = false; newKey.ch += 32; } @@ -488,16 +505,14 @@ public final class TKeypress { } /** - * Convert a keypress to uppercase. Function keys and ctrl keys are not - * converted. + * Convert a keypress to uppercase. Function keys and alt/ctrl keys are + * not converted. * - * @param key keypress to convert * @return a new instance with the key converted */ - public static TKeypress toUpper(final TKeypress key) { - TKeypress newKey = new TKeypress(key.isKey, key.fnKey, key.ch, - key.alt, key.ctrl, key.shift); - if (!(key.isKey) && (key.ch >= 'a') && (key.ch <= 'z') && (!key.ctrl)) { + public TKeypress toUpperCase() { + TKeypress newKey = new TKeypress(isKey, fnKey, ch, alt, ctrl, shift); + if (!isKey && (ch >= 'a') && (ch <= 'z') && !ctrl && !alt) { newKey.shift = true; newKey.ch -= 32; }