Example usage for java.util Date hashCode

List of usage examples for java.util Date hashCode

Introduction

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

Prototype

public int hashCode() 

Source Link

Document

Returns a hash code value for this object.

Usage

From source file:Main.java

public static void main(String[] args) {

    Date date = new Date();

    int i = date.hashCode();
    System.out.println(i);/*w  w w.ja  v a 2 s  . c o m*/
}

From source file:Main.java

public static void main(String[] args) throws InterruptedException {
    Date date = new Date();
    Thread.sleep(1);/*from   ww w.j a  v a2s .c o m*/
    Date other = new Date();
    out.printf("equals? = %s, hashCode? = %s %n", (date.equals(other)), (date.hashCode() == other.hashCode()));

    Date todayeOne = trim(date);
    Date todayTwo = trim(other);

    out.printf("equals? = %s, hashCode? = %s %n", (todayeOne.equals(todayTwo)),
            (todayeOne.hashCode() == todayTwo.hashCode()));

}

From source file:org.broadleafcommerce.core.order.domain.OrderImpl.java

@Override
public int hashCode() {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result + ((customer == null) ? 0 : customer.hashCode());
    Date myDateCreated = auditable != null ? auditable.getDateCreated() : null;
    result = prime * result + ((myDateCreated == null) ? 0 : myDateCreated.hashCode());
    return result;
}

From source file:org.campware.cream.modules.scheduledjobs.Pop3Job.java

private String getTempCode() {
    Date currDate = new Date();
    return Integer.toString(currDate.hashCode());
}

From source file:org.campware.cream.modules.util.XmlRpcHandler.java

private String getTempCode() {
    Date currDate = new Date();

    return Integer.toString(currDate.hashCode());
}

From source file:org.castor.cpa.test.test10.TestTypeHandling.java

public void testDateParameterized() throws PersistenceException, ParseException {
    LOG.debug("Testing date->int/numeric/char parameterized conversion");
    SimpleDateFormat df = new SimpleDateFormat();
    df.applyPattern("yyyy/MM/dd");
    Date date = df.parse("2000/05/27");
    df.applyPattern("yyyy/MM/dd HH:mm:ss.SSS");
    Date time = df.parse("2000/05/27 02:16:01.234");
    df.applyPattern("yyyy/MM/dd HH:mm:ss.SSS");
    Date timestamp = df.parse("2000/05/27 02:16:01.234");
    _db.begin();/*from www  . java 2  s .  co m*/
    _oql.bind(TypeHandling.DEFAULT_ID);
    Enumeration<?> enumeration = _oql.execute();
    if (enumeration.hasMoreElements()) {
        TypeHandling types = (TypeHandling) enumeration.nextElement();
        types.setDate2(date);
        types.setTime2(time);
        types.setTimestamp2(timestamp);
    }
    _db.commit();

    _db.begin();
    _oql.bind(TypeHandling.DEFAULT_ID);
    enumeration = _oql.execute();
    if (enumeration.hasMoreElements()) {
        TypeHandling types = (TypeHandling) enumeration.nextElement();
        if (!date.equals(types.getDate2())) {
            LOG.error("date/int value was not set");
            fail("date/int value was not set");
        }
        if (!time.equals(types.getTime2())) {
            LOG.error("time/string value was not set");
            fail("time/string vlaue was not set");
        }
        if (!timestamp.equals(types.getTimestamp2())) {
            LOG.error("timestamp/numeric value was not set");
            LOG.error("timestamp was set to: " + df.format(timestamp));
            LOG.error("with oid: " + timestamp.hashCode());
            LOG.error("timestamp is: " + df.format(types.getTimestamp2()));
            LOG.error("with oid: " + types.getTimestamp2().hashCode());
            fail("timestamp/numeric value was not set");
        }
    } else {
        LOG.error("failed to load object");
        fail("failed to load object");
    }
    _db.commit();
    LOG.debug("OK: date->int/numeric/char conversion passed");
}

From source file:org.jasig.ssp.model.AbstractAuditable.java

protected final int hashField(final String name, final Date value) {
    return ((value == null) || (value.getTime() == 0) ? name.hashCode() : value.hashCode());
}

From source file:org.rhq.enterprise.server.content.ContentSourceManagerBean.java

@SuppressWarnings("unchecked")
public String getResourceSubscriptionMD5(int resourceId) {
    MessageDigestGenerator md5Generator = new MessageDigestGenerator();

    Query q = entityManager.createNamedQuery(Repo.QUERY_FIND_REPOS_BY_RESOURCE_ID);
    q.setParameter("resourceId", resourceId);
    List<Repo> repos = q.getResultList();

    for (Repo repo : repos) {
        long modifiedTimestamp = repo.getLastModifiedDate();
        Date modifiedDate = new Date(modifiedTimestamp);
        md5Generator.add(Integer.toString(modifiedDate.hashCode()).getBytes());
    }//from   ww  w.  j  ava  2  s  .  c o  m

    String digestString = md5Generator.getDigestString();
    return digestString;
}

From source file:org.rhq.enterprise.server.content.test.ContentSourceManagerBeanTest.java

@Test(enabled = TESTS_ENABLED)
public void testMergeSyncReport() throws Exception {
    PageControl pc;/*from w  ww . j a  v a 2  s  . c  om*/
    int repoId = 0;
    int contentSourceId = 0;

    try {
        // create content source type
        ContentSourceType type = new ContentSourceType("testMergeSyncReportCST");
        Set<ContentSourceType> types = new HashSet<ContentSourceType>();
        types.add(type);
        contentSourceMetadataManager.registerTypes(types); // this blows away any previous existing types
        type = contentSourceManager.getContentSourceType(type.getName());
        assert type != null;
        assert type.getId() > 0;

        // create content source
        ContentSource contentSource = new ContentSource("testMergeSyncReportCS", type);
        contentSource = contentSourceManager.simpleCreateContentSource(overlord, contentSource);
        assert contentSource != null;
        contentSourceId = contentSource.getId();
        assert contentSourceId > 0;

        // create a repo
        Repo repo = new Repo("testRepo");
        repo = repoManager.createRepo(overlord, repo);
        repoId = repo.getId();

        // this report will add a mapping to PV->CS
        // we didn't set up any mappings like that yet - this will be the first one
        PackageSyncReport report = new PackageSyncReport();
        ContentProviderPackageDetailsKey key = new ContentProviderPackageDetailsKey(
                "testCreateContentSourceFoo", "testCreateContentSourceVer", packageType1.getName(),
                architecture1.getName(), resourceType1.getName(), resourceType1.getPlugin());
        ContentProviderPackageDetails details = new ContentProviderPackageDetails(key);
        details.setLocation("dummy-location");
        details.setMetadata("dummy-metadata".getBytes());
        details.addResourceVersion("1.0.0");
        details.addResourceVersion("2.0.0");
        report.addNewPackage(details);
        Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous;
        previous = new HashMap<ContentProviderPackageDetailsKey, PackageVersionContentSource>();

        // merge the report!
        RepoSyncResults results = new RepoSyncResults(repo);
        results = repoManager.persistRepoSyncResults(results);
        assert results != null;

        results = contentSourceManager.mergePackageSyncReport(contentSource, repo, report, previous, results);
        assert results != null;

        // Verify the product version was created
        getTransactionManager().begin();
        EntityManager em = getEntityManager();
        try {
            resourceType1 = em.find(ResourceType.class, resourceType1.getId());

            Query productVersionQuery = em
                    .createNamedQuery(ProductVersion.QUERY_FIND_BY_RESOURCE_TYPE_AND_VERSION);
            productVersionQuery.setParameter("resourceType", resourceType1);
            productVersionQuery.setParameter("version", "1.0.0");

            List productVersionList = productVersionQuery.getResultList();
            assert productVersionList.size() > 0 : "Could not find product version for 1.0.0";

            productVersionQuery = em.createNamedQuery(ProductVersion.QUERY_FIND_BY_RESOURCE_TYPE_AND_VERSION);
            productVersionQuery.setParameter("resourceType", resourceType1);
            productVersionQuery.setParameter("version", "2.0.0");

            productVersionList = productVersionQuery.getResultList();
            assert productVersionList.size() > 0 : "Could not find product version for 2.0.0";
        } finally {
            getTransactionManager().rollback();
            em.close();
        }

        // see that the resource sees no metadata yet - not subscribed yet
        pc = PageControl.getUnlimitedInstance();
        PageList<PackageVersionMetadataComposite> metadataList;
        metadataList = contentSourceManager.getPackageVersionMetadata(resource1.getId(), pc);
        assert metadataList != null;
        assert metadataList.size() == 0 : "-->" + metadataList;
        String metadataMd5 = contentSourceManager.getResourceSubscriptionMD5(resource1.getId());
        assert metadataMd5 != null;
        assert metadataMd5.length() == 32 : "-->" + metadataMd5;
        assert metadataMd5.equals("d41d8cd98f00b204e9800998ecf8427e") : "-->" + metadataMd5;

        // just to make sure the MD5 for empty data is what we think it is...
        metadataMd5 = contentSourceManager.getResourceSubscriptionMD5(Integer.MIN_VALUE); // should find no metadata at all
        assert metadataMd5 != null;
        assert metadataMd5.length() == 32 : "-->" + metadataMd5;
        assert metadataMd5.equals("d41d8cd98f00b204e9800998ecf8427e") : "-->" + metadataMd5;

        // add the content source's packages to the repo
        repoManager.addContentSourcesToRepo(overlord, repoId, new int[] { contentSourceId });

        // see the package versions have been assigned to the repo and content source
        List<PackageVersion> inRepo;
        List<PackageVersionContentSource> inContentSources;
        List<PackageVersionContentSource> inContentSource;

        pc = PageControl.getUnlimitedInstance();
        inRepo = repoManager.findPackageVersionsInRepo(overlord, repoId, pc);
        pc = PageControl.getUnlimitedInstance();
        inContentSources = contentSourceManager.getPackageVersionsFromContentSources(overlord,
                new int[] { contentSourceId }, pc);
        inContentSource = contentSourceManager.getPackageVersionsFromContentSource(overlord, contentSourceId,
                pc);
        assert inRepo != null;
        assert inContentSources != null;
        assert inContentSource != null;
        assert inRepo.size() == 1 : inRepo;
        assert inContentSources.size() == 1 : inContentSources;
        assert inContentSource.size() == 1 : inContentSource;

        // confirm that we didn't load the bits yet
        pc = PageControl.getUnlimitedInstance();
        List<PackageVersionContentSource> unloaded;
        unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSourceInRepo(overlord,
                contentSourceId, repoId, pc);
        assert unloaded != null;
        assert unloaded.size() == 1;

        // check the counts
        long pvccount = repoManager.getPackageVersionCountFromRepo(overlord, repo.getId());
        assert (pvccount == 1) : "-->" + pvccount;
        long pvcscount = contentSourceManager.getPackageVersionCountFromContentSource(overlord,
                contentSourceId);
        assert (pvcscount == 1) : "-->" + pvcscount;

        // subscribe the resource
        repoManager.subscribeResourceToRepos(overlord, resource1.getId(), new int[] { repoId });

        // confirm the resource is subscribed
        pc = PageControl.getUnlimitedInstance();
        metadataList = contentSourceManager.getPackageVersionMetadata(resource1.getId(), pc);
        assert metadataList != null;
        assert metadataList.size() == 1 : "-->" + metadataList;
        metadataMd5 = contentSourceManager.getResourceSubscriptionMD5(resource1.getId());
        assert metadataMd5 != null;
        assert metadataMd5.length() == 32 : "-->" + metadataMd5;

        // MD5 is based on the hash code of last modified time
        repo = repoManager.getRepo(overlord, repoId);
        long modifiedTimestamp = repo.getLastModifiedDate();
        Date modifiedDate = new Date(modifiedTimestamp);
        String datehash = Integer.toString(modifiedDate.hashCode());
        assert metadataMd5.equals(MessageDigestGenerator.getDigestString(datehash)) : "-->" + metadataMd5;

        repoManager.unsubscribeResourceFromRepos(overlord, resource1.getId(), new int[] { repoId });

        // confirm the resource is unsubscribed
        pc = PageControl.getUnlimitedInstance();
        metadataList = contentSourceManager.getPackageVersionMetadata(resource1.getId(), pc);
        assert metadataList != null;
        assert metadataList.size() == 0 : "-->" + metadataList;
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    } finally {
        try {
            // clean up - delete all created entities
            if (repoId != 0) {
                repoManager.deleteRepo(overlord, repoId);
            }

            if (contentSourceId != 0) {
                contentSourceManager.deleteContentSource(overlord, contentSourceId);
            }

            contentSourceMetadataManager.registerTypes(new HashSet<ContentSourceType>());
        } catch (Throwable t) {
        }
    }
}

From source file:org.xwiki.watchlist.internal.api.WatchListEvent.java

/**
 * Constructor.//  w  ww.  java 2 s  .c  om
 *
 * @param documentReference the document on which the event happened
 * @param type the type of event
 * @param userReference the user that triggered the event
 * @param version the version of the document after the event happened on it
 * @param date the date of the event
 */
public WatchListEvent(DocumentReference documentReference, String type, DocumentReference userReference,
        String version, Date date) {
    this.documentReference = documentReference;
    this.type = type;
    this.authorReference = userReference;
    this.version = version;
    this.date = date;

    this.events = new ArrayList<>();
    this.events.add(this);

    int hash = 3;
    if (ActivityEventType.UPDATE.equals(type)) {
        hashCode = 42 * hash + documentReference.hashCode() + type.hashCode();
    } else {
        hashCode = 42 * hash + documentReference.hashCode() + type.hashCode() + date.hashCode();
    }
}