List of usage examples for java.util Date compareTo
public int compareTo(Date anotherDate)
From source file:io.fabric8.maven.core.util.KubernetesResourceUtil.java
public static boolean isNewerResource(HasMetadata newer, HasMetadata older) { Date t1 = getCreationTimestamp(newer); Date t2 = getCreationTimestamp(older); if (t1 != null) { return t2 == null || t1.compareTo(t2) > 0; }//from ww w . j ava 2 s . c om return false; }
From source file:com.unboundid.scim2.common.utils.JsonUtils.java
/** * Compares two JsonNodes for order. Nodes containing datetime and numerical * values are ordered accordingly. Otherwise, the values' string * representation will be compared lexicographically. * * @param n1 the first node to be compared. * @param n2 the second node to be compared. * @param attributeDefinition The attribute definition of the attribute * whose values to compare or {@code null} to * compare string values using case insensitive * matching./* w w w . j av a 2s .co m*/ * @return a negative integer, zero, or a positive integer as the * first argument is less than, equal to, or greater than the second. */ public static int compareTo(final JsonNode n1, final JsonNode n2, final AttributeDefinition attributeDefinition) { if (n1.isTextual() && n2.isTextual()) { Date d1 = dateValue(n1); Date d2 = dateValue(n2); if (d1 != null && d2 != null) { return d1.compareTo(d2); } else { if (attributeDefinition != null && attributeDefinition.getType() == AttributeDefinition.Type.STRING && attributeDefinition.isCaseExact()) { return n1.textValue().compareTo(n2.textValue()); } return StaticUtils.toLowerCase(n1.textValue()).compareTo(StaticUtils.toLowerCase(n2.textValue())); } } if (n1.isNumber() && n2.isNumber()) { if (n1.isBigDecimal() || n2.isBigDecimal()) { return n1.decimalValue().compareTo(n2.decimalValue()); } if (n1.isFloatingPointNumber() || n2.isFloatingPointNumber()) { return Double.compare(n1.doubleValue(), n2.doubleValue()); } if (n1.isBigInteger() || n2.isBigInteger()) { return n1.bigIntegerValue().compareTo(n2.bigIntegerValue()); } return Long.compare(n1.longValue(), n2.longValue()); } // Compare everything else lexicographically return n1.asText().compareTo(n2.asText()); }
From source file:mitm.common.security.crl.CRLUtils.java
/** * Returns 0 if crl and otherCRL have similar validity (ie no one is newer than the other), * > 0 if crl is newer than otherCRL and < 0 if crl is older than otherCRL *///from w ww.j a v a 2 s . c om public static int compare(X509CRL crl, X509CRL otherCRL) throws IOException, MissingDateException { BigInteger crlNumber = X509CRLInspector.getCRLNumber(crl); BigInteger otherCRLNumber = X509CRLInspector.getCRLNumber(crl); Date thisUpdate = crl.getThisUpdate(); Date otherThisUpdate = otherCRL.getThisUpdate(); if (thisUpdate == null || otherThisUpdate == null) { throw new MissingDateException("One of the CRLs has a missing thisUpdate."); } int cmp; if (crlNumber != null && otherCRLNumber != null) { cmp = crlNumber.compareTo(otherCRLNumber); if (cmp > 0) { if (thisUpdate.before(otherThisUpdate)) { logger.warn("According to CRL numbers a new CRL is found but thisUpdate is older."); } logger.debug("The CRL number is bigger and is therefore more recent."); } else if (cmp == 0) { /* * same CRL number but thisUpdate can be newer */ cmp = thisUpdate.compareTo(otherThisUpdate); if (cmp > 0) { logger.debug("The CRL numbers are equal but thisUpdate is newer."); } } else { if (thisUpdate.after(otherThisUpdate)) { logger.warn("According to CRL numbers this not a new CRL but thisUpdate is newer."); } } } else { /* * no CRL number so compare thisUpdate */ cmp = thisUpdate.compareTo(otherThisUpdate); if (cmp > 0) { logger.debug("A more recent CRL is found."); } } return cmp; }
From source file:gov.utah.dts.det.ccl.model.view.NewApplicationPendingDeadlineView.java
public boolean isCloseFacility() { Date today = new Date(); if (today.compareTo(DateUtils.addMonths(licenseStartDate, 6)) >= 0) { return true; }//from w w w . j a va 2 s .c o m return false; }
From source file:io.fabric8.maven.core.util.kubernetes.KubernetesResourceUtil.java
public static boolean isNewerResource(HasMetadata newer, HasMetadata older) { Date t1 = getCreationTimestamp(newer); Date t2 = getCreationTimestamp(older); return t1 != null && (t2 == null || t1.compareTo(t2) > 0); }
From source file:org.b3log.solo.util.comparator.ArticleCreateDateComparator.java
@Override public int compare(final JSONObject article1, final JSONObject article2) { try {/*from ww w. java 2 s . c o m*/ final Date date1 = (Date) article1.get(Article.ARTICLE_CREATE_DATE); final Date date2 = (Date) article2.get(Article.ARTICLE_CREATE_DATE); return date2.compareTo(date1); } catch (final Exception e) { throw new IllegalStateException(e); } }
From source file:org.b3log.solo.util.comparator.ArticleUpdateDateComparator.java
@Override public int compare(final JSONObject article1, final JSONObject article2) { try {/*from w ww .j a v a 2s . co m*/ final Date date1 = (Date) article1.get(Article.ARTICLE_UPDATE_DATE); final Date date2 = (Date) article2.get(Article.ARTICLE_UPDATE_DATE); return date2.compareTo(date1); } catch (final Exception e) { throw new IllegalStateException(e); } }
From source file:org.shengrui.oa.util.UtilDateTime.java
/** * /*w w w .j av a2 s. co m*/ * @param start1 * @param end1 * @param start2 * @param end2 */ public static boolean hasInter(Date start1, Date end1, Date start2, Date end2) { if (start1 != null && end1 != null && start2 != null && end2 != null) { if (start1.compareTo(start2) < 0 && start2.compareTo(end1) < 0) { return true; } if (start1.compareTo(end2) < 0 && end2.compareTo(end1) < 0) { return true; } if (start2.compareTo(start1) < 0 && end1.compareTo(end2) < 0) { return true; } } return false; }
From source file:io.fabric8.maven.core.util.KubernetesResourceUtil.java
public static Pod getNewestPod(Collection<Pod> pods) { if (pods == null || pods.isEmpty()) { return null; }//from w w w .j ava 2 s. c o m List<Pod> sortedPods = new ArrayList<>(pods); Collections.sort(sortedPods, new Comparator<Pod>() { @Override public int compare(Pod p1, Pod p2) { Date t1 = getCreationTimestamp(p1); Date t2 = getCreationTimestamp(p2); if (t1 != null) { if (t2 == null) { return 1; } else { return t1.compareTo(t2); } } else if (t2 == null) { return 0; } return -1; } }); return sortedPods.get(sortedPods.size() - 1); }
From source file:org.alfresco.integrations.google.docs.utils.FileRevisionComparator.java
@Override public int compare(FileRevision entry1, FileRevision entry2) { Date entry1Revision = entry1.getModifiedDate(); Date entry2Revision = entry2.getModifiedDate(); return entry1Revision.compareTo(entry2Revision); }