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.usergrid.persistence.cassandra.EntityManagerFactoryImplTest.java

@Test
public void testCreateAndGet() throws Exception {
    logger.info("EntityDaoTest.testCreateAndGet");

    UUID applicationId = createApplication("testCreateAndGet");
    logger.info("Application id " + applicationId);

    EntityManager em = emf.getEntityManager(applicationId);

    int i = 0;/*  w  ww  .jav  a 2s.com*/
    List<Entity> things = new ArrayList<Entity>();
    for (i = 0; i < 10; i++) {
        Map<String, Object> properties = new LinkedHashMap<String, Object>();
        properties.put("name", "thing" + i);

        Entity thing = em.create("thing", properties);
        assertNotNull("thing should not be null", thing);
        assertFalse("thing id not valid", thing.getUuid().equals(new UUID(0, 0)));
        assertEquals("name not expected value", "thing" + i, thing.getProperty("name"));

        things.add(thing);
    }
    assertEquals("should be ten entities", 10, things.size());

    i = 0;
    for (Entity entity : things) {

        Entity thing = em.get(entity.getUuid());
        assertNotNull("thing should not be null", thing);
        assertFalse("thing id not valid", thing.getUuid().equals(new UUID(0, 0)));
        assertEquals("name not expected value", "thing" + i, thing.getProperty("name"));

        i++;
    }

    List<UUID> ids = new ArrayList<UUID>();
    for (Entity entity : things) {
        ids.add(entity.getUuid());

        Entity en = em.get(entity.getUuid());
        String type = en.getType();
        assertEquals("type not expected value", "thing", type);

        Object property = en.getProperty("name");
        assertNotNull("thing name property should not be null", property);
        assertTrue("thing name should start with \"thing\"", property.toString().startsWith("thing"));

        Map<String, Object> properties = en.getProperties();
        assertEquals("number of properties wrong", 5, properties.size());
    }

    i = 0;
    Results results = em.get(ids, Results.Level.CORE_PROPERTIES);
    for (Entity thing : results) {
        assertNotNull("thing should not be null", thing);

        assertFalse("thing id not valid", thing.getUuid().equals(new UUID(0, 0)));

        assertEquals("wrong type", "thing", thing.getType());

        assertNotNull("thing name should not be null", thing.getProperty("name"));
        String name = thing.getProperty("name").toString();
        assertEquals("unexpected name", "thing" + i, name);

        i++;

    }

    assertEquals("entities unfound entity name count incorrect", 10, i);

    /*
     * List<UUID> entities = emf.findEntityIds(applicationId, "thing", null,
     * null, 100); assertNotNull("entities list should not be null",
     * entities); assertEquals("entities count incorrect", 10,
     * entities.size());
     */

}

From source file:io.lavagna.service.calendarutils.CalendarVEventHandler.java

public void addMilestoneEvent(String projectShortName, java.util.Date date, LabelListValueWithMetadata m,
        SearchResults cards) throws URISyntaxException {

    URI uri = new URI(String.format("%s%s/milestones/", applicationUrl, projectShortName));

    double closed = 0;
    double total = 0;
    StringBuilder descBuilder = new StringBuilder();
    for (CardFullWithCounts card : cards.getFound()) {
        if (card.getColumnDefinition() == ColumnDefinition.CLOSED) {
            closed++;/*from w  w w.j  av a 2  s.  c om*/
        }
        total++;
        descBuilder.append(getEventName(card));
        descBuilder.append("\n");
    }

    final String name = String.format("%s - %s (%.0f%%)", projectShortName, m.getValue(),
            total > 0 ? 100 * closed / total : 100);

    final UUID id = new UUID(getLong(m.getCardLabelId(), m.getId()), getLong(m.getOrder(), 0));

    DateTime dueDate = new DateTime(date.getTime());
    dueDate.setUtc(true);
    final VEvent event = new VEvent(dueDate, name);
    event.getProperties().getProperty(Property.DTSTART).getParameters().add(Value.DATE_TIME);

    event.getProperties().add(new Description(descBuilder.toString()));

    event.getProperties().add(new Uid(id.toString()));

    // Reminder on milestone's date
    if (!m.getMetadata().containsKey("status") || !m.getMetadata().get("status").equals("CLOSED")) {
        event.getAlarms().add(createReminder(name));
    }

    // Url
    event.getProperties().add(new Url(uri));
    events.add(event);
}

From source file:io.selendroid.server.model.AndroidNativeElement.java

public AndroidNativeElement(View view, ServerInstrumentation instrumentation, KeySender keys,
        KnownElements ke) {/*from   www.j av a2s .com*/
    Preconditions.checkNotNull(view);
    this.viewRef = new WeakReference<View>(view);
    hashCode = view.hashCode() + 31;
    this.instrumentation = instrumentation;
    this.keys = keys;
    this.nativeElementSearchScope = new NativeElementSearchScope(instrumentation, keys, ke);
    this.ke = ke;

    Random random = new Random();
    this.id = new UUID(random.nextLong(), random.nextLong()).toString();
}

From source file:com.joyent.manta.client.multipart.EncryptedServerSideMultipartManagerIT.java

public void nonExistentFileHasNotStarted() throws IOException {
    String path = testPathPrefix + UUID.randomUUID().toString();
    UUID unknownId = new UUID(0L, -1L);

    ServerSideMultipartUpload wrapped = new ServerSideMultipartUpload(unknownId, path, null);

    EncryptedMultipartUpload<ServerSideMultipartUpload> upload = new EncryptedMultipartUpload<>(wrapped, null);
    assertEquals(multipart.getStatus(upload), MantaMultipartStatus.UNKNOWN);
}

From source file:com.strategicgains.docussandra.controller.perf.remote.PlayByPlayRemote.java

@Override
public List<Document> getDocumentsFromFS(int numToRead) throws IOException, ParseException {
    File file = new File(System.getProperty("user.home"), path);
    logger.info("Data path: " + file.getAbsolutePath());
    List<Document> toReturn = new ArrayList<>(numToRead);
    int counter = 0;
    synchronized (this) {
        numToRead = numToRead + position.intValue();
        try (BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
            String line = null;//www .j a va 2 s.  c om
            while ((line = reader.readLine()) != null) {
                if (counter < position.intValue()) {
                    //read up to where we need to go. there has to be a better way to do this, however, not worth it right now
                    counter++;
                } else if (counter >= position.intValue() && counter < numToRead) {
                    //we have a section we care about
                    //so we add the document
                    Document doc = new Document();
                    doc.table(getTb());
                    doc.setUuid(new UUID(Long.MAX_VALUE - position.intValue(), 1));//give it a UUID that we will reconize
                    doc.object(line);
                    toReturn.add(doc);
                    position.addAndGet(1);//jump the postition
                    counter++;//and the counter
                } else {
                    logger.info("Exausted all documents in the PBP.json file for this chunk position: "
                            + position.get());
                    break;//we are done
                }

            }
        }
    }
    return toReturn;
}

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

@Test
public void should_dsl_select_with_IN_clause() throws Exception {
    //Given//  w  w  w  . j a v a2  s  .c o  m
    final long id1 = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    final long id2 = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    final UUID uuid1 = new UUID(1L, 1L);
    final UUID uuid2 = new UUID(2L, 2L);
    final UUID uuid3 = new UUID(3L, 3L);

    scriptExecutor.executeScriptTemplate("EntityWithCompositePartitionKey/insert_single_row.cql",
            ImmutableMap.of("id", id1, "uuid", uuid1, "value", "val1-1"));
    scriptExecutor.executeScriptTemplate("EntityWithCompositePartitionKey/insert_single_row.cql",
            ImmutableMap.of("id", id1, "uuid", uuid2, "value", "val1-2"));
    scriptExecutor.executeScriptTemplate("EntityWithCompositePartitionKey/insert_single_row.cql",
            ImmutableMap.of("id", id2, "uuid", uuid1, "value", "val2-1"));
    scriptExecutor.executeScriptTemplate("EntityWithCompositePartitionKey/insert_single_row.cql",
            ImmutableMap.of("id", id2, "uuid", uuid2, "value", "val2-2"));
    scriptExecutor.executeScriptTemplate("EntityWithCompositePartitionKey/insert_single_row.cql",
            ImmutableMap.of("id", id2, "uuid", uuid3, "value", "val2-3"));

    //When
    final List<EntityWithCompositePartitionKey> actuals = manager.dsl().select().value().fromBaseTable().where()
            .id_IN(id1, id2).uuid_IN(uuid1, uuid3).getList();

    //Then
    assertThat(actuals).hasSize(3);
    assertThat(actuals.stream().map(EntityWithCompositePartitionKey::getValue).sorted()
            .collect(Collectors.toList())).containsExactly("val1-1", "val2-1", "val2-3");
}

From source file:org.midonet.midolman.rules.TestRules.java

@Before
public void setup() {
    pktMatch = new FlowMatch();
    pktMatch.setInputPortNumber((short) 5);
    pktMatch.setEthSrc("02:11:33:00:11:01");
    pktMatch.setEthDst("02:11:aa:ee:22:05");
    pktMatch.setEtherType(IPv4.ETHERTYPE);
    pktMatch.setNetworkSrc(IPv4Addr.fromInt(0x0a001406));
    pktMatch.setNetworkDst(IPv4Addr.fromInt(0x0a000b22));
    pktMatch.setNetworkProto((byte) 6); // TCP
    pktMatch.setNetworkTOS((byte) 34);
    pktMatch.setSrcPort(4321);//from  w w w  .  j a  v a  2s .c o  m
    pktMatch.setDstPort(1234);
    pktResponseMatch = new FlowMatch();
    pktResponseMatch.setInputPortNumber((short) 5);
    pktResponseMatch.setEthDst("02:11:33:00:11:01");
    pktResponseMatch.setEthSrc("02:11:aa:ee:22:05");
    pktResponseMatch.setEtherType(IPv4.ETHERTYPE);
    pktResponseMatch.setNetworkDst(IPv4Addr.fromInt(0x0a001406));
    pktResponseMatch.setNetworkSrc(IPv4Addr.fromInt(0x0a000b22));
    pktResponseMatch.setNetworkProto((byte) 6); // TCP
    pktResponseMatch.setNetworkTOS((byte) 34);
    pktResponseMatch.setDstPort(4321);
    pktResponseMatch.setSrcPort(1234);
    rand = new Random();
    inPort = new UUID(rand.nextLong(), rand.nextLong());
    ownerId = new UUID(rand.nextLong(), rand.nextLong());
    jumpChainId = new UUID(rand.nextLong(), rand.nextLong());
    jumpChainName = "AJumpChainName";
    // Build a condition that matches the packet.
    cond = new Condition();
    cond.inPortIds = new HashSet<>();
    cond.inPortIds.add(inPort);
    cond.nwSrcIp = new IPv4Subnet(IPv4Addr.fromString("10.0.20.0"), 24);
    cond.nwProto = 15;
    cond.nwProtoInv = true;
    cond.tpSrc = new Range<>(2000, 3000);
    cond.tpSrcInv = true;
    cond.tpDst = new Range<>(1000, 2000);

    nats = new HashSet<>();
    nats.add(new NatTarget(0x0a090807, 0x0a090810, 21333, 32999));

    pktCtx = PacketContext.generatedForJava(1, null, pktMatch, null);
    @SuppressWarnings("unchecked")
    ShardedFlowStateTable<ConnTrackKeyStore, Boolean> shardedConntrack = ShardedFlowStateTable.create();
    pktCtx = PacketContext.generatedForJava(1, null, pktMatch, null);
    FlowStateTable<ConnTrackKeyStore, Boolean> conntrackTable = shardedConntrack
            .addShard(Logger$.MODULE$.apply(NOPLogger.NOP_LOGGER));
    ShardedFlowStateTable<NatKeyStore, NatBinding> shardedNat = ShardedFlowStateTable.create();
    FlowStateTable<NatKeyStore, NatBinding> natTable = shardedNat
            .addShard(Logger$.MODULE$.apply(NOPLogger.NOP_LOGGER));
    FlowStateTable<TraceKeyStore, TraceState.TraceContext> traceTable = ShardedFlowStateTable.<TraceKeyStore, TraceState.TraceContext>create()
            .addShard(Logger$.MODULE$.apply(NOPLogger.NOP_LOGGER));
    conntrackTx = new FlowStateTransaction<>(conntrackTable);
    natTx = new FlowStateTransaction<>(natTable);
    traceTx = new FlowStateTransaction<>(traceTable);
    pktCtx.initialize(conntrackTx, natTx, HappyGoLuckyLeaser$.MODULE$, traceTx);
    pktCtx.currentDevice_$eq(ownerId);
}

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

@Test
public void should_dsl_select_slice_with_tuples_same_partition() throws Exception {
    //Given//  w  w  w. j  a  v a2  s  .co  m
    final Map<String, Object> values = new HashMap<>();
    final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    values.put("id1", id);
    values.put("id2", id);
    values.put("id3", id);
    values.put("id4", id);
    values.put("id5", id);

    final UUID uuid1 = new UUID(0L, 0L);
    final UUID uuid2 = new UUID(0L, 1L);

    values.put("uuid1", uuid1);
    values.put("uuid2", uuid1);
    values.put("uuid3", uuid1);
    values.put("uuid4", uuid2);
    values.put("uuid5", uuid2);

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));

    final Date date2 = dateFormat.parse("2015-10-02 00:00:00 GMT");
    final Date date3 = dateFormat.parse("2015-10-03 00:00:00 GMT");
    final Date date4 = dateFormat.parse("2015-10-04 00:00:00 GMT");

    values.put("date1", "'2015-10-01 00:00:00+0000'");
    values.put("date2", "'2015-10-02 00:00:00+0000'");
    values.put("date3", "'2015-10-03 00:00:00+0000'");
    values.put("date4", "'2015-10-04 00:00:00+0000'");
    values.put("date5", "'2015-10-05 00:00:00+0000'");

    /*
    Data are ordered as physically:
            
    uuid1, date3,
    uuid1, date2,
    uuid1, date1,
    uuid2, date5,
    uuid2, date4
            
    because date is ORDERED BY DESC natively
            
    but (uuid,date) >= (uuid1, date2) AND (uuid,date) < (uuid2, date4) should return
            
    uuid1, date3
    uuid1, date2
            
     */
    scriptExecutor.executeScriptTemplate("EntityWithClusteringColumns/insert_many_rows.cql", values);

    //When
    final List<EntityWithClusteringColumns> list = manager.dsl().select().uuid().date().value().fromBaseTable()
            .where().id_Eq(id).uuid_And_date_Gte_And_Lt(uuid1, date2, uuid2, date4).getList();

    //Then
    assertThat(list).hasSize(2);

    assertThat(list.get(0).getUuid()).isEqualTo(uuid1);
    assertThat(list.get(0).getDate()).isEqualTo(date3);
    assertThat(list.get(0).getValue()).isEqualTo("val3");

    assertThat(list.get(1).getUuid()).isEqualTo(uuid1);
    assertThat(list.get(1).getDate()).isEqualTo(date2);
    assertThat(list.get(1).getValue()).isEqualTo("val2");
}

From source file:org.apache.cassandra.db.marshal.UUIDType.java

public UUID compose(ByteBuffer bytes) {

    bytes = bytes.slice();//from   ww w  . j a  va  2  s . c o  m
    if (bytes.remaining() < 16)
        return new UUID(0, 0);
    return new UUID(bytes.getLong(), bytes.getLong());
}

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

/**
 * Creates datastore documents in cloudstore.
 *
 * This method creates datastore documents with datastore IDs 00000000-0000-0000-0000-000000000000,
 * 00000000-0000-0000-0000-000000000001, and so on.
 *
 * @param numDatastores The number of datastore documents to create.
 *///  w  w  w . j a v  a  2s  . c o m
public static void loadDatastores(TestEnvironment cloudstore, int numDatastores) throws Throwable {
    for (int i = 0; i < numDatastores; i++) {
        DatastoreService.State datastore = new DatastoreService.State();
        String datastoreId = new UUID(0, i).toString();
        datastore.id = datastoreId;
        datastore.name = datastoreId;
        datastore.documentSelfLink = datastoreId;
        datastore.type = "SHARED_VMFS";
        // TODO(mmutsuzaki) Support datastore tags.
        datastore.tags = new HashSet<>();
        Operation result = cloudstore.sendPostAndWait(DatastoreServiceFactory.SELF_LINK, datastore);
        assertThat(result.getStatusCode(), is(200));
        logger.debug("Created a datastore document: {}", Utils.toJson(false, false, datastore));
    }
}