/** * */ package com.perforce.p4java.impl.mapbased.rpc.func.helper; import java.util.Random; /** * Mildly-useful String and String-related helper methods that * should probably be factored out elsewhere... */ public class StringHelper { private static final Random rand = new Random(System.currentTimeMillis()); /** * Return the integer value of the passed-in char interpreted * as a hex digit. * * FIXME: return -1 on bad conversion -- HR. */ public static int hexcharToInt(char c) { return c - ( c > '9' ? ( c >= 'a' ? 'a' - 10 : 'A' - 10 ) : '0' ); } /** * Return a plausibly-random number string in hex form. * Used mostly for temp filename generation.<p> * * Not (yet) synchronised as unlikely to be problem * with threads and contention. */ public static String getRandomHexString() { long n = rand.nextLong(); if (n == Long.MIN_VALUE) { n = 0; // corner case } else { n = Math.abs(n); } return Long.toString(n, 16); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19903 | stuartrowe |
Branching //guest/perforce_software/p4java/... to //guest/stuartrowe/p4java/... |
||
//guest/perforce_software/p4java/r14.1/src/main/java/com/perforce/p4java/impl/mapbased/rpc/func/helper/StringHelper.java | |||||
#1 | 12541 | Matt Attaway | Initial add of the 14.1 p4java source code |