Here you can find the source of toString(int[] codes)
Parameter | Description |
---|---|
codes | a parameter |
public static String toString(int[] codes)
//package com.java2s; //License from project: Apache License import java.util.HashMap; import java.util.Map; public class Main { private static final char separator = '+'; private static final Map<Integer, String> codeToName = new HashMap<>(); private static final Map<String, String> internalToExternalName = new HashMap<>(); /**/*from w w w . j a va 2s . c o m*/ * Translates array of key codes into corresponding string representation. * @param codes * @return string representation of given key codes */ public static String toString(int[] codes) { if (codes.length == 0) { return ""; } StringBuffer buffer = new StringBuffer(); buffer.append(toString(codes[0])); for (int i = 1; i < codes.length; i++) { String s = toString(codes[i]); if (s != null) { buffer.append(separator).append(s); } } return buffer.toString(); } /** * Creates string representation of separate character (e.g. {@code Ctrl}, {@code Alt} etc). * @param code - code of the character * @return string representation. */ public static String toString(int code) { String internalName = codeToName.get(code); if (internalName == null) { return null; } String externalName = internalToExternalName.get(internalName); if (externalName == null) { externalName = internalName; } return capitalize(externalName); } private static String capitalize(String str) { String prefix = str.substring(0, 1).toUpperCase(); String suffix = str.length() > 1 ? str.substring(1).toLowerCase() : ""; return prefix + suffix; } }