List of utility methods to do ID Value Create
String | generateSalt() generate Salt StringBuilder builder = new StringBuilder(); Random random = new Random(); final char[] chars = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz+/1234567890".toCharArray(); for (int i = 0; i < 32; i++) { builder.append(chars[random.nextInt(chars.length)]); return builder.toString(); |
String | generateSalt() Generates a random string return Long.toHexString(new Random(System.nanoTime()).nextLong()); |
String | generateSalt() Return a randomly-generated 16 character alphanumeric value (a-z, A-Z, 0-9) String validChars = "abcdefghijlmnopqrstuvwxyzABCDEFGHIKJLMNOPQRSTUVWXYZ0123456789"; int length = 16; Random rand = new Random(); StringBuilder sb = new StringBuilder(length); while (sb.length() != length) sb.append(validChars.charAt(rand.nextInt(validChars.length()))); return sb.toString(); |
String | generateUniqueId() generate Unique Id StringBuilder sb = new StringBuilder(UNIQUEID_DEFAULTSIZE); Random random = new Random(); for (int i = 0; i < UNIQUEID_DEFAULTSIZE; i++) { sb.append(UNIQUEID_LETTERS.charAt(random.nextInt(UNIQUEID_LETTERS.length()))); return sb.toString().toLowerCase(Locale.US); |
String | generateUniqueId() generate Unique Id long curTime = System.currentTimeMillis(); int random = secureRand.nextInt(); if (random < 0) { random = -random; return Long.toString(curTime, Character.MAX_RADIX) + Integer.toString(random, Character.MAX_RADIX); |
String | generateUniqueIdentity() generate Unique Identity StringBuilder builder = new StringBuilder(); for (int j = 0; j < 2; j++) { for (int i = 0; i < 4; i++) { builder.append(nextChar()); if (j == 0) { builder.append('-'); return builder.toString(); |
String | generateUniqueName(String kind) generate Unique Name return String.format("%s%d", kind, new Random().nextInt()); |
String | generateUniqueString(int maxLength) generate Unique String String str = String.valueOf(Math.abs(new Random().nextLong())); if (maxLength < str.length()) return str.substring(0, maxLength); else return str; |
String | toId(String id) to Id String fixStart = id; if (!Character.isJavaIdentifierStart(fixStart.charAt(0))) { fixStart = "_" + fixStart; fixStart = fixStart.replaceAll("_", "__"); StringBuilder result = new StringBuilder(); char[] cs = fixStart.toCharArray(); for (char c : cs) { ... |
String | toId(String name) Convert a normal name with spaces into an Id: with underscores replacing the spaces, etc. if (name == null) { return name; name = name.replaceAll("[ .,:(){}\\[\\]]", "_"); name = name.replaceAll("[\"`']", ""); name = name.replaceAll("[*]", "_TIMES_"); name = name.replaceAll("[/]", "_DIVIDED_BY_"); name = name.replaceAll("[+]", "_PLUS_"); ... |