protected void ensureGeneratorInitialized() { if (timeBasedGenerator == null) { synchronized (StrongUuidGenerator.class) { if (timeBasedGenerator == null) { timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface()); } } } }
/** * Factory method for constructing UUID generator that uses default (shared) * random number generator for constructing UUIDs according to standard * method number 4. */ public static RandomBasedGenerator randomBasedGenerator() { return randomBasedGenerator(null); }
/** * Factory method for constructing UUID generator that uses specified * random number generator for constructing UUIDs according to standard * method number 5, but without using a namespace. * Digester to use will be SHA-1 as recommened by UUID spec. */ public static NameBasedGenerator nameBasedGenerator() { return nameBasedGenerator(null); }
noArgGenerator = Generators.timeBasedGenerator(addr); break; case 'r': // random-based System.out.print("(using secure random generator, info = '"+r.getProvider().getInfo()+"')"); noArgGenerator = Generators.randomBasedGenerator(r); nameArgGenerator = Generators.nameBasedGenerator(nsUUID); break;
/** * Factory method for constructing UUID generator that generates UUID using * variant 1 (time+location based), using specified Ethernet address * as the location part of UUID, and specified {@link UUIDTimer} instance * (which includes embedded synchronizer that defines synchronization behavior). */ public static TimeBasedGenerator timeBasedGenerator(EthernetAddress ethernetAddress, UUIDTimer timer) { if (timer == null) { timer = sharedTimer(); } return new TimeBasedGenerator(ethernetAddress, timer); }
noArgGenerator = Generators.timeBasedGenerator(addr); break; case 'r': // random-based System.out.print("(using secure random generator, info = '"+r.getProvider().getInfo()+"')"); noArgGenerator = Generators.randomBasedGenerator(r); nameArgGenerator = Generators.nameBasedGenerator(nsUUID); break;
/** * Factory method for constructing UUID generator that generates UUID using * variant 1 (time+location based), using specified Ethernet address * as the location part of UUID, and specified {@link UUIDTimer} instance * (which includes embedded synchronizer that defines synchronization behavior). */ public static TimeBasedGenerator timeBasedGenerator(EthernetAddress ethernetAddress, UUIDTimer timer) { if (timer == null) { timer = sharedTimer(); } return new TimeBasedGenerator(ethernetAddress, timer); }
/** * Factory method for constructing UUID generator that generates UUID using * variant 1 (time+location based), using specified Ethernet address * as the location part of UUID. * No additional external synchronization is used. */ public static TimeBasedGenerator timeBasedGenerator(EthernetAddress ethernetAddress) { return timeBasedGenerator(ethernetAddress, (UUIDTimer) null); }
/** * Factory method for constructing UUID generator that uses default (shared) * random number generator for constructing UUIDs according to standard * method number 4. */ public static RandomBasedGenerator randomBasedGenerator() { return randomBasedGenerator(null); }
/** * Factory method for constructing UUID generator that uses specified * random number generator for constructing UUIDs according to standard * method number 5, with specified namespace (or without one if null * is specified). * Digester to use will be SHA-1 as recommened by UUID spec. * * @param namespace UUID that represents namespace to use; see * {@link NameBasedGenerator} for 'standard' namespaces specified by * UUID specs */ public static NameBasedGenerator nameBasedGenerator(UUID namespace) { return nameBasedGenerator(namespace, null); }
/** * Factory method for constructing UUID generator that generates UUID using * variant 1 (time+location based). * Since no Ethernet address is passed, a bogus broadcast address will be * constructed for purpose of UUID generation; usually it is better to * instead access one of host's NIC addresses using * {@link EthernetAddress#fromInterface} which will use one of available * MAC (Ethernet) addresses available. */ public static TimeBasedGenerator timeBasedGenerator() { return timeBasedGenerator(null); }
public UUIDRandomIDGenerator() { generator = Generators.randomBasedGenerator(); }
/** * Factory method for constructing UUID generator that uses specified * random number generator for constructing UUIDs according to standard * method number 5, but without using a namespace. * Digester to use will be SHA-1 as recommened by UUID spec. */ public static NameBasedGenerator nameBasedGenerator() { return nameBasedGenerator(null); }
protected void ensureGeneratorInitialized() { if (timeBasedGenerator == null) { synchronized (StrongUuidGenerator.class) { if (timeBasedGenerator == null) { timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface()); } } } }
public UUIDRandomIDGenerator() { generator = Generators.randomBasedGenerator(); }
/** * Factory method for constructing UUID generator that uses specified * random number generator for constructing UUIDs according to standard * method number 5, with specified namespace (or without one if null * is specified). * Digester to use will be SHA-1 as recommened by UUID spec. * * @param namespace UUID that represents namespace to use; see * {@link NameBasedGenerator} for 'standard' namespaces specified by * UUID specs */ public static NameBasedGenerator nameBasedGenerator(UUID namespace) { return nameBasedGenerator(namespace, null); }
protected void ensureGeneratorInitialized() { if (timeBasedGenerator == null) { synchronized (StrongUuidGenerator.class) { if (timeBasedGenerator == null) { timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface()); } } } }
private NoArgGenerator newUuidStrategy(String strategy, String ethernet) { if (STRATEGY_TIME.equalsIgnoreCase(strategy)) { return newTimeBasedGenerator(ethernet); } if (STRATEGY_RANDOM.equalsIgnoreCase(strategy)) { return Generators.randomBasedGenerator(); } throw new IllegalArgumentException("Unknown strategy: " + strategy); }
/** * Generate short version UUID from given uri * * @param uri Uri/Url * @return UUID */ public static String shortUuid(URI uri) { NameBasedGenerator generator = Generators.nameBasedGenerator(NameBasedGenerator.NAMESPACE_URL); UUID uuid = generator.generate(uri.toString()); // https://gist.github.com/LeeSanghoon/5811136 long l = ByteBuffer.wrap(uuid.toString().getBytes()).getLong(); return Long.toString(l, Character.MAX_RADIX); }
/** * Factory method for constructing UUID generator that generates UUID using * variant 1 (time+location based), using specified Ethernet address * as the location part of UUID, and specified synchronizer (which may add * additional restrictions to guarantee system-wide uniqueness). * * @see com.fasterxml.uuid.ext.FileBasedTimestampSynchronizer */ public static TimeBasedGenerator timeBasedGenerator(EthernetAddress ethernetAddress, TimestampSynchronizer sync) { UUIDTimer timer; try { timer = new UUIDTimer(new Random(System.currentTimeMillis()), sync); } catch (IOException e) { throw new IllegalArgumentException("Failed to create UUIDTimer with specified synchronizer: "+e.getMessage(), e); } return timeBasedGenerator(ethernetAddress, timer); }