private ConnectionGUID(UniqueIDGenerator generator) { guid = generator.getID(); }
/** * Get a new unique ID string. The string is always exactly 32 hex * characters. * * @return A new unique ID string. */ public String getID() { StringBuilder idBuffer = new StringBuilder(); idBuffer.append(getRandomComponent()); idBuffer.append(getJVMIdentityComponent()); idBuffer.append(getNetworkComponent()); idBuffer.append(getTimeComponent()); return idBuffer.toString(); }
private String getTimeComponent() { long now = System.currentTimeMillis(); return forceTo8Chars(Long.toHexString(now)); }
public static void main(String[] args) { UniqueIDGenerator uniqueIDGenerator = new UniqueIDGenerator(); long startTime = System.currentTimeMillis(); for (int n = 0; n < 1000; n++) { uniqueIDGenerator.getID(); } long time = System.currentTimeMillis() - startTime; System.out.println("1000 GUIDS generated in " + time + " ms"); System.out.println("Avarage " + time / 1000 + " ms / GUID"); }
instance = new Config(); instance.filename = tmpFilename; file = new File(tmpFilename); if (file.exists()) { try { instance.load(new FileInputStream(file)); } catch (IOException exc) { System.err.println("Unable to load configuration."); if (ins != null) { try { instance.load(ins); } catch (IOException exc) { System.err.println("Unable to load configuration.");
private String forceTo8Chars(String value) { String newValue = value; if (newValue.length() > 8) { newValue = newValue.substring(newValue.length() - 8); } if (newValue.length() < 8) { newValue = pad(newValue, 8); } return newValue; }
private ConnectionGUID(String guid) { if (guid == null) { throw new IllegalArgumentException("guid string can not be null"); } guid = generator.getID(); }
private String getJVMIdentityComponent() { String identityString = Integer.toHexString(System .identityHashCode(this)); return forceTo8Chars(identityString); }
public DirectoryObjectCutClipboardItem(DirectoryTreeObject sourceObject, Messages messages, Workbench workbench, DirectoryEventListenerRegistry eventRegistry) { super(); this.messages = messages; this.workbench = workbench; this.sourceObject = sourceObject; this.eventRegistry = eventRegistry; id = idGenerator.getID(); description = messages.format("clipboard.object.copy", sourceObject .getConnectionInformation().getDescription(), sourceObject .getDistinguishedName().toString()); }
private String getRandomComponent() { int randomNumber; if (randomGenerator == null) { try { randomGenerator = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException ex) { randomGenerator = null; } } if (randomGenerator == null) { randomNumber = (int) Math.random(); } else { randomNumber = randomGenerator.nextInt(); } return forceTo8Chars(Integer.toHexString(randomNumber)); }
public DirectoryObjectCopyClipboardItem(DirectoryTreeObject sourceObject, Messages messages, Workbench workbench, DirectoryEventListenerRegistry eventRegistry) { super(); this.messages = messages; this.workbench = workbench; this.sourceObject = sourceObject; this.eventRegistry = eventRegistry; id = idGenerator.getID(); description = messages.format("clipboard.object.copy", sourceObject .getConnectionInformation().getDescription(), sourceObject .getDistinguishedName().toString()); }
private String getNetworkComponent() { try { InetAddress localAddress = java.net.InetAddress.getLocalHost(); byte[] rawArray = localAddress.getAddress(); DataInputStream in = new DataInputStream(new ByteArrayInputStream( rawArray)); int rawAddress = in.readInt(); return forceTo8Chars(Integer.toHexString(rawAddress)); } catch (Exception ex) { return "00000000"; } }
action.putValue(Action.ACCELERATOR_KEY, stroke); if (component != null) { String actionName = idGenerator.getID(); component.getActionMap().put(actionName, action); component.getInputMap(JComponent.WHEN_FOCUSED).put(