Example usage for java.util UUID equals

List of usage examples for java.util UUID equals

Introduction

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

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares this object to the specified object.

Usage

From source file:me.eccentric_nz.TARDIS.utility.TARDISUUIDCache.java

/**
 * Get the UUID from the cache for the player named 'name', with blocking
 * get.//from   w ww  .j a va  2  s .  c  o m
 *
 * If the player named is not in the cache, then we will fetch the UUID in a
 * blocking fashion. Note that this will block the thread until the fetch is
 * complete, so only use this in a thread or in special circumstances.
 *
 * @param name The player name.
 * @return a UUID
 */
public UUID getId(String name) {
    Validate.notEmpty(name);
    UUID uuid = cache.get(name);
    if (uuid == null) {
        syncFetch(nameList(name));
        return cache.get(name);
    } else if (uuid.equals(ZERO_UUID)) {
        uuid = null;
    }
    return uuid;
}

From source file:org.photovault.replication.ObjectHistory.java

@Transient
public Change<T> getChange(UUID id) {
    for (Change<T> c : allChanges) {
        if (id.equals(c.getUuid())) {
            return c;
        }//  w  ww  . j a va 2  s .  c  om
    }
    return null;
}

From source file:org.apache.cassandra.db.SystemKeyspaceTest.java

@Test
public void testLocalHostID() {
    UUID firstId = SystemKeyspace.getLocalHostId();
    UUID secondId = SystemKeyspace.getLocalHostId();
    assert firstId.equals(secondId) : String.format("%s != %s%n", firstId.toString(), secondId.toString());
}

From source file:com.intellectualcrafters.plot.commands.Info.java

private String getPlayerName(final UUID uuid) {
    if (uuid == null) {
        return "unknown";
    }/*  w w  w  . j av  a 2s. c  o  m*/
    if (uuid.equals(DBFunc.everyone) || uuid.toString().equalsIgnoreCase(DBFunc.everyone.toString())) {
        return "everyone";
    }
    /*
     * OfflinePlayer plr = Bukkit.getOfflinePlayer(uuid); if (plr.getName()
     * == null) { return "unknown"; } return plr.getName();
     */
    return UUIDHandler.getName(uuid);
}

From source file:org.photovault.replication.ChangeDTO.java

public void verify() throws IOException {
    UUID checksum = calcUuid();
    if (!checksum.equals(changeUuid)) {
        throw new IllegalStateException(
                "UUID of change is incorrect - excepted" + changeUuid + " but calculated " + checksum);
    }/*w w  w .j a  v a  2 s. c  o m*/
}

From source file:org.usergrid.rest.RootResource.java

private ApplicationResource appResourceFor(UUID applicationId) throws Exception {
    if (applicationId.equals(MANAGEMENT_APPLICATION_ID)) {
        throw new UnauthorizedException();
    }/*from w w  w. ja  va 2s . co  m*/

    return getSubResource(ApplicationResource.class).init(applicationId);
}

From source file:gov.va.isaac.util.OTFUtility.java

private static boolean isPreferred(List<RefexChronicleDdo<?, ?>> annotations) {
    for (RefexChronicleDdo<?, ?> frc : annotations) {
        for (Object version : frc.getVersions()) {
            if (version instanceof RefexCompVersionDdo) {
                UUID uuid = ((RefexCompVersionDdo<?, ?>) version).getComp1Ref().getUuid();
                return uuid.equals(PREFERRED_UUID);
            }//from   www .  j  ava 2s. com
        }
    }
    return false;
}

From source file:org.brekka.pegasus.core.services.impl.AllocationServiceSupport.java

protected void assignFileXml(final Allocation allocation) {
    XmlEntity<AllocationDocument> xml = this.xmlEntityService.release(allocation.getXml(),
            AllocationDocument.class);
    AllocationType allocationType = xml.getBean().getAllocation();
    List<AllocationFile> files = allocation.getFiles();
    BundleType bundle = allocationType.getBundle();
    if (bundle == null) {
        allocation.setFiles(Collections.<AllocationFile>emptyList());
        return;//w w w .ja v  a2  s .c o  m
    }
    List<FileType> fileList = bundle.getFileList();
    // Use nested loops as there should never be that many files.
    for (FileType fileType : fileList) {
        UUID cryptedFileID = UUID.fromString(fileType.getUUID());
        for (AllocationFile allocationFile : files) {
            UUID id = allocationFile.getCryptedFile().getId();
            if (id.equals(cryptedFileID)) {
                allocationFile.setXml(fileType);
                break; // Break out of this loop
            }
        }
    }
}

From source file:org.apache.usergrid.persistence.cassandra.EntityManagerFactoryImplIT.java

@Test
public void testDeleteApplication() throws Exception {
    ReIndexService reIndexService = setup.getInjector().getInstance(ReIndexService.class);

    int maxRetries = 10;

    String rand = UUIDGenerator.newTimeUUID().toString();

    // create an application with a collection and an entity

    String appName = "test-app-" + rand;
    String orgName = "test-org-" + rand;
    final UUID deletedAppId = setup.createApplication(orgName, appName);

    EntityManager em = setup.getEmf().getEntityManager(deletedAppId);

    Map<String, Object> properties1 = new LinkedHashMap<String, Object>();
    properties1.put("Name", "12 Angry Men");
    properties1.put("Year", 1957);
    Entity film1 = em.create("film", properties1);

    Map<String, Object> properties2 = new LinkedHashMap<String, Object>();
    properties2.put("Name", "Reservoir Dogs");
    properties2.put("Year", 1992);
    Entity film2 = em.create("film", properties2);

    for (int j = 0; j < maxRetries; j++) {
        if (setup.getEmf().lookupApplication(orgName + "/" + appName) != null) {
            break;
        }/*from  ww w .j a v  a2 s. c o  m*/
        Thread.sleep(500);
    }

    this.app.refreshIndex();

    // wait for it to appear in delete apps list

    Func2<UUID, Map<String, UUID>, Boolean> findApps = (applicationId, apps) -> {
        boolean found = false;
        for (String app : apps.keySet()) {
            UUID appId = apps.get(app);
            if (appId.equals(applicationId)) {
                found = true;
                break;
            }
        }
        return found;
    };

    Map<String, UUID> apps = setup.getEmf().getApplications();
    boolean found = findApps.call(deletedAppId, apps);
    assertTrue("Restored app not found in apps collection", found);

    // delete the application
    setup.getEmf().deleteApplication(deletedAppId);

    this.app.refreshIndex();

    found = findApps.call(deletedAppId, emf.getDeletedApplications());

    assertTrue("Deleted app must be found in in deleted apps collection", found);

    // attempt to get entities in application's collections in various ways should all fail
    found = setup.getEmf().lookupApplication(orgName + "/" + appName) != null;

    assertFalse("Lookup of deleted app must fail", found);

    // app must not be found in apps collection
    found = findApps.call(deletedAppId, emf.getApplications());
    assertFalse("Deleted app must not be found in apps collection", found);

    // restore the app
    emf.restoreApplication(deletedAppId);
    final ReIndexRequestBuilder builder = reIndexService.getBuilder().withApplicationId(deletedAppId);

    ReIndexService.ReIndexStatus status = reIndexService.rebuildIndex(builder);
    int count = 0;
    do {
        status = reIndexService.getStatus(status.getJobId());
        count++;
        if (count > 0) {
            if (count > 10) {
                break;
            }
            Thread.sleep(1000);
        }
    } while (status.getStatus() != ReIndexService.Status.COMPLETE);

    this.app.refreshIndex();

    // test to see that app now works and is happy

    // it should not be found in the deleted apps collection
    found = findApps.call(deletedAppId, emf.getDeletedApplications());
    assertFalse("Restored app found in deleted apps collection", found);
    this.app.refreshIndex();

    apps = setup.getEmf().getApplications();
    found = findApps.call(deletedAppId, apps);

    assertTrue("Restored app not found in apps collection", found);

    // TODO: this assertion should work!
    assertTrue(setup.getEmf().lookupApplication(orgName + "/" + appName) != null);
}

From source file:org.apache.usergrid.tools.DupOrgRepair.java

/**
 * Merge the source orgId into the targetId in the following way.
 * <p/>//from  w  w  w.jav  a2 s . co m
 * 1) link all admins from the source org to the target org 2) link all apps from the source org to the target or 3)
 * delete the target org
 */
@SuppressWarnings("unchecked")
private void mergeOrganizations(String outputDir, UUID sourceOrgId, UUID targetOrgId) throws Exception {

    OrganizationInfo sourceOrgInfo = managementService.getOrganizationByUuid(sourceOrgId);

    Map<String, Object> sourceOrg = managementService.getOrganizationData(sourceOrgInfo);

    OrganizationInfo targetOrgInfo = managementService.getOrganizationByUuid(targetOrgId);

    Map<String, Object> targetOrg = managementService.getOrganizationData(targetOrgInfo);

    // Dump the output on these two orgs
    FileWriter file = new FileWriter(
            String.format("%s/%s.%s.orig", outputDir, sourceOrgInfo.getName(), sourceOrgId));

    file.write(JsonUtils.mapToFormattedJsonString(sourceOrg));

    file.write("\n\n");

    file.write(JsonUtils.mapToFormattedJsonString(targetOrg));

    file.flush();
    file.close();

    // BiMap<UUID, String> targetApps =
    // managementService.getApplicationsForOrganization(targetOrgId);

    // now perform the merge

    // add all the admins
    Map<String, UserInfo> admins = (Map<String, UserInfo>) sourceOrg.get("users");

    for (Entry<String, UserInfo> adminEntry : admins.entrySet()) {
        UserInfo admin = adminEntry.getValue();

        logger.info("adding admin with uuid {} and email {} to org with name {} and uuid {}", new Object[] {
                admin.getUuid(), admin.getEmail(), targetOrgInfo.getName(), targetOrgInfo.getUuid() });

        // copy the admins over
        managementService.addAdminUserToOrganization(admin, targetOrgInfo, false);
    }

    // get the root entity manager
    EntityManager em = emf.getEntityManager(CassandraService.MANAGEMENT_APPLICATION_ID);

    // Add the apps to the org
    Map<String, UUID> sourceApps = (Map<String, UUID>) sourceOrg.get("applications");

    Map<String, UUID> targetApps = (Map<String, UUID>) targetOrg.get("applications");

    for (Entry<String, UUID> app : sourceApps.entrySet()) {

        // we have colliding app names
        if (targetApps.get(app.getKey()) != null) {

            // already added, skip it
            if (app.getValue().equals(targetApps.get(app.getKey()))) {
                continue;
            }

            // check to see if this orgname/appname lookup returns the app we're
            // about to re-assign. If it does NOT, then we need to rename this app
            // before performing the link.
            UUID appIdToKeep = emf.lookupApplication(app.getKey());

            UUID appIdToChange = appIdToKeep.equals(app.getValue()) ? targetApps.get(app.getKey())
                    : app.getValue();

            // get the existing target entity
            Entity appEntity = em.get(appIdToChange);

            if (appEntity != null) {

                String oldName = appEntity.getProperty("name").toString();
                String newName = oldName + appEntity.getUuid();

                //force the property to be updated
                em.setProperty(appEntity, "name", newName, true);

                logger.info("Renamed app from {} to {}", oldName, newName);
            }
        }

        logger.info("Adding application with name {} and id {} to organization with uuid {}",
                new Object[] { app.getKey(), app.getValue(), targetOrgId });
        managementService.addApplicationToOrganization(targetOrgId, app.getValue());
    }

    // now delete the original org

    logger.info("Deleting org with the name {} and uuid {}", sourceOrgInfo.getName(), sourceOrgInfo.getUuid());

    // delete the source org
    em.delete(new SimpleEntityRef("group", sourceOrgId));

    // re-dump the target from the cassandra stat
    targetOrgInfo = managementService.getOrganizationByUuid(targetOrgId);

    targetOrg = managementService.getOrganizationData(targetOrgInfo);

    file = new FileWriter(String.format("%s/%s.%s.new", outputDir, targetOrgInfo.getName(), targetOrgId));

    file.write(JsonUtils.mapToFormattedJsonString(targetOrg));

    file.flush();
    file.close();
}