Example usage for java.util UUID UUID

List of usage examples for java.util UUID UUID

Introduction

In this page you can find the example usage for java.util UUID UUID.

Prototype

public UUID(long mostSigBits, long leastSigBits) 

Source Link

Document

Constructs a new UUID using the specified data.

Usage

From source file:org.voltdb.hadoop.Digester.java

/**
 * Generate a {@code UUID} representation of the MD5 digest for the given content. This is possible because MD5
 * digests and UUIDs are both 128 bit long
 *
 * @param aContent//from w  ww . ja  v a 2 s . c  om
 *            a content {@code String}
 * @return a {@code UUID} representation of the computed MD5 digest
 * @throws DigesterException
 *             upon failed cryptographic operation
 */
public final static UUID digestMD5asUUID(String aContent) throws DigestException {
    if (aContent == null)
        return null;

    BigInteger bi = digestMD5asBigInteger(aContent);
    return new UUID(bi.shiftRight(64).longValue(), bi.and(LSB_MASK).longValue());
}

From source file:com.github.seqware.queryengine.util.SGID.java

/**
 * Back-end constructor, create a fully functional SGID
 *
 * @param mostSig a long.//from  w  ww . ja va  2s .  co  m
 * @param leastSig a long.
 * @param timestamp a long.
 * @param friendlyRowKey a {@link java.lang.String} object.
 */
public SGID(long mostSig, long leastSig, long timestamp, String friendlyRowKey) {
    uuid = new UUID(mostSig, leastSig);
    backendTimestamp = new Date(timestamp);
    this.friendlyRowKey = friendlyRowKey;
}

From source file:info.archinnov.achilles.it.TestEntityWithCompositePartitionKey.java

@Test
public void should_find() throws Exception {
    //Given// ww w .  j  a  v a2 s .c  o m
    final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    final UUID uuid = new UUID(1L, 1L);
    scriptExecutor.executeScriptTemplate("EntityWithCompositePartitionKey/insert_single_row.cql",
            ImmutableMap.of("id", id, "uuid", uuid, "value", "val"));

    //When
    final EntityWithCompositePartitionKey actual = manager.crud().findById(id, uuid).get();

    //Then

    assertThat(actual.getValue()).isEqualTo("val");
}

From source file:com.vmware.photon.controller.rootscheduler.simulator.CloudStoreLoader.java

/**
 * Creates host documents in cloudstore.
 *
 * @param cloudstore CloudStore test environment to create documents in.
 * @param numHosts The number of host documents to create.
 * @param hostConfigurations A map from {@link HostConfiguration} to the probability that this
 *                           host configuration is used in the deployment. The sum of all the
 *                           values of this map must be 1.
 * @param numDatastores The number of datastores.
 * @param numDatastoresDistribution Distribution for number of datastores on each host. This
 *                                  distribution is expected to generate samples in the range
 *                                  [0, numDatastores].
 * @throws Throwable//from  w  ww . j a  va  2s.  c o  m
 */
public static void loadHosts(TestEnvironment cloudstore, int numHosts,
        Map<HostConfiguration, Double> hostConfigurations, int numDatastores,
        IntegerDistribution numDatastoresDistribution) throws Throwable {
    int[] indices = new int[hostConfigurations.size()];
    HostConfiguration[] configs = new HostConfiguration[hostConfigurations.size()];
    double[] probabilities = new double[hostConfigurations.size()];
    int i = 0;
    for (Map.Entry<HostConfiguration, Double> entry : hostConfigurations.entrySet()) {
        indices[i] = i;
        configs[i] = entry.getKey();
        probabilities[i] = entry.getValue();
        i++;
    }
    EnumeratedIntegerDistribution configDistribution = new EnumeratedIntegerDistribution(indices,
            probabilities);
    for (i = 0; i < numHosts; i++) {
        HostService.State host = new HostService.State();
        host.hostAddress = "host" + i;
        host.state = HostState.READY;
        host.userName = "username";
        host.password = "password";
        host.reportedDatastores = new HashSet<>();
        int numDatastoresPerHost = numDatastoresDistribution.sample();
        assertThat(numDatastoresPerHost >= 0, is(true));
        assertThat(numDatastoresPerHost <= numDatastores, is(true));
        while (host.reportedDatastores.size() < numDatastoresPerHost) {
            int randomInt = random.nextInt(numDatastores);
            host.reportedDatastores.add(new UUID(0, randomInt).toString());
        }
        host.reportedNetworks = new HashSet<>();
        host.usageTags = new HashSet<>(Arrays.asList(UsageTag.CLOUD.name()));
        int configIndex = configDistribution.sample();
        host.cpuCount = configs[configIndex].numCpus;
        host.memoryMb = configs[configIndex].memoryMb;
        host.documentSelfLink = new UUID(0, i).toString();
        // TODO(mmutsuzaki) Support availability zones.
        Operation result = cloudstore.sendPostAndWait(HostServiceFactory.SELF_LINK, host);
        assertThat(result.getStatusCode(), is(200));
        logger.debug("Created a host document: {}", Utils.toJson(true, false, host));
    }
}

From source file:org.lilyproject.repository.impl.DFSBlobStoreAccess.java

private UUID decode(byte[] blobKey) {
    return new UUID(Bytes.toLong(blobKey), Bytes.toLong(blobKey, Bytes.SIZEOF_LONG));
}

From source file:com.nesscomputing.jackson.datatype.TestCustomUuidModule.java

@Test
public void testCustomUUIDSerialization() throws Exception {
    final AtomicBoolean called = new AtomicBoolean(false);
    ObjectMapper mapper = getObjectMapper(new AbstractModule() {
        @Override//from  ww w  .  j  av  a 2 s  . co  m
        protected void configure() {
            bind(new TypeLiteral<JsonSerializer<UUID>>() {
            }).toInstance(new CustomUuidSerializer() {
                @Override
                public void serialize(UUID value, JsonGenerator jgen, SerializerProvider provider)
                        throws IOException, JsonGenerationException {
                    called.set(true);
                    super.serialize(value, jgen, provider);
                }
            });
        }
    });
    final UUID id = new UUID(9, 9);
    Assert.assertEquals('"' + id.toString() + '"', mapper.writeValueAsString(id));
    Assert.assertTrue(called.get());
}

From source file:org.springframework.integration.MessageHeaders.java

public MessageHeaders(Map<String, Object> headers) {
    this.headers = (headers != null) ? new HashMap<String, Object>(headers) : new HashMap<String, Object>();
    if (MessageHeaders.idGenerator == null) {
        UUID uuid = new UUID(UUIDGen.newTime(), UUIDGen.getClockSeqAndNode());
        this.headers.put(ID, uuid);
    } else {/*from   www . ja  v  a2  s . com*/
        this.headers.put(ID, MessageHeaders.idGenerator.generateId());
    }

    this.headers.put(TIMESTAMP, new Long(System.currentTimeMillis()));
}

From source file:com.intellectualcrafters.plot.uuid.UUIDFetcher.java

@SuppressWarnings("unused")
public static UUID fromBytes(final byte[] array) {
    if (array.length != 16) {
        throw new IllegalArgumentException("Illegal byte array length: " + array.length);
    }/*  w  w  w. j  a  va2  s.co m*/
    final ByteBuffer byteBuffer = ByteBuffer.wrap(array);
    final long mostSignificant = byteBuffer.getLong();
    final long leastSignificant = byteBuffer.getLong();
    return new UUID(mostSignificant, leastSignificant);
}

From source file:com.simpsonwil.strongquests.util.UUIDFetcher.java

public static UUID fromBytes(byte[] array) {
    if (array.length != 16)
        throw new IllegalArgumentException("Illegal byte array length: " + array.length);

    ByteBuffer byteBuffer = ByteBuffer.wrap(array);
    long mostSignificant = byteBuffer.getLong();
    long leastSignificant = byteBuffer.getLong();

    return new UUID(mostSignificant, leastSignificant);
}

From source file:com.cnaude.mutemanager.UUIDFetcher.java

public static UUID fromBytes(byte[] array) {
    if (array.length != 16) {
        throw new IllegalArgumentException("Illegal byte array length: " + array.length);
    }//from  www.j a v  a 2s. c o m
    ByteBuffer byteBuffer = ByteBuffer.wrap(array);
    long mostSignificant = byteBuffer.getLong();
    long leastSignificant = byteBuffer.getLong();
    return new UUID(mostSignificant, leastSignificant);
}