Example usage for java.util Date before

List of usage examples for java.util Date before

Introduction

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

Prototype

public boolean before(Date when) 

Source Link

Document

Tests if this date is before the specified date.

Usage

From source file:de.knurt.fam.template.util.ContactDetailsRequestHandler.java

public static Date correctBirthdate(Date birthdate) {
    Calendar now = Calendar.getInstance();
    // older then 0?
    if (birthdate != null) {
        if (birthdate.after(now.getTime())) {
            birthdate = null;/*from  w w  w.j a  v a 2s .c  om*/
        }
    }
    if (birthdate != null) {
        // younger then 200?
        now.roll(Calendar.YEAR, -200);
        if (birthdate.before(now.getTime())) {
            birthdate = null;
        }
    }
    return birthdate;
}

From source file:services.GoogleComputeEngineService.java

public static void listOperations(ActorRef actor, Date lastOperationDate) throws GoogleComputeEngineException {
    checkAuthentication();/*  w ww  .  j a  v a 2  s  .  c  om*/
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
    Inbox inbox = Inbox.create(Akka.system());
    if (lastOperationDate != null) {
        lastOperationDate = new Date(lastOperationDate.getTime() + 1);
    }
    OperationsCache.cleanOldOperationsFromCache();
    for (Operation o : client.getOperations()) {
        if (lastOperationDate != null) {
            if (!OperationsCache.statusHasChanged(o) && !"RUNNING".equalsIgnoreCase(o.getStatus())) {
                if (o.getStartTime() == null) {
                    continue;
                }
                try {
                    Date date = format.parse(o.getStartTime());
                    if (date.before(lastOperationDate)) {
                        continue;
                    }
                } catch (ParseException e) {
                    continue;
                }
            }
        }
        OperationsCache.addOperation(o);
        inbox.send(actor, o);
    }
}

From source file:jp.co.ctc_g.jse.core.validation.util.Validators.java

/**
 * ?????????//from  ww w  . j  a  va  2 s . c  o  m
 * @param suspect 
 * @param target ?
 * @return ??????false
 */
public static boolean before(Date suspect, Date target) {
    if (suspect == null)
        return true;
    return suspect.before(target);
}

From source file:jp.co.ctc_g.jse.core.validation.util.Validators.java

/**
 * ???????????????/* w w w .  ja v  a2  s  .  c  o  m*/
 * @param suspect 
 * @param target ?
 * @return ??????????false
 */
public static boolean beforeEqualsTo(Date suspect, Date target) {
    if (suspect == null)
        return true;
    return suspect.before(target) || suspect.equals(target);
}

From source file:com.sitewhere.hbase.device.HBaseDeviceEvent.java

/**
 * Find all event rows associated with a site and return values that match the search
 * criteria. TODO: This is not optimized at all and will take forever in cases where
 * there are ton of assignments and events. It has to go through every record
 * associated with the site. It works for now though.
 * /*from w  w  w.  j  a v  a2s .  co  m*/
 * @param hbase
 * @param siteToken
 * @param eventType
 * @param criteria
 * @return
 * @throws SiteWhereException
 */
protected static Pager<byte[]> getEventRowsForSite(ISiteWhereHBaseClient hbase, String siteToken,
        DeviceAssignmentRecordType eventType, IDateRangeSearchCriteria criteria) throws SiteWhereException {
    Long siteId = IdManager.getInstance().getSiteKeys().getValue(siteToken);
    if (siteId == null) {
        throw new SiteWhereSystemException(ErrorCode.InvalidSiteToken, ErrorLevel.ERROR);
    }
    byte[] startPrefix = HBaseSite.getAssignmentRowKey(siteId);
    byte[] afterPrefix = HBaseSite.getAfterAssignmentRowKey(siteId);

    HTableInterface events = null;
    ResultScanner scanner = null;
    try {
        events = hbase.getTableInterface(ISiteWhereHBase.EVENTS_TABLE_NAME);
        Scan scan = new Scan();
        scan.setStartRow(startPrefix);
        scan.setStopRow(afterPrefix);
        scanner = events.getScanner(scan);

        List<DatedByteArray> matches = new ArrayList<DatedByteArray>();
        Iterator<Result> results = scanner.iterator();
        while (results.hasNext()) {
            Result current = results.next();
            byte[] key = current.getRow();
            if (key.length > 7) {
                Map<byte[], byte[]> cells = current.getFamilyMap(ISiteWhereHBase.FAMILY_ID);
                for (byte[] qual : cells.keySet()) {
                    byte[] value = cells.get(qual);
                    if ((qual.length > 3) && (qual[3] == eventType.getType())) {
                        Date eventDate = getDateForEventKeyValue(key, qual);
                        if ((criteria.getStartDate() != null) && (eventDate.before(criteria.getStartDate()))) {
                            continue;
                        }
                        if ((criteria.getEndDate() != null) && (eventDate.after(criteria.getEndDate()))) {
                            continue;
                        }
                        matches.add(new DatedByteArray(eventDate, value));
                    }
                }
            }
        }
        Collections.sort(matches, Collections.reverseOrder());
        Pager<byte[]> pager = new Pager<byte[]>(criteria);
        for (DatedByteArray match : matches) {
            pager.process(match.getJson());
        }
        return pager;
    } catch (IOException e) {
        throw new SiteWhereException("Error scanning event rows.", e);
    } finally {
        if (scanner != null) {
            scanner.close();
        }
        HBaseUtils.closeCleanly(events);
    }
}

From source file:com.sitewhere.hbase.device.HBaseDeviceEvent.java

/**
 * Find all event rows associated with a device assignment and return cells that match
 * the search criteria.// ww w . ja va 2  s.c  o m
 * 
 * @param hbase
 * @param assnToken
 * @param eventType
 * @param criteria
 * @return
 * @throws SiteWhereException
 */
protected static Pager<byte[]> getEventRowsForAssignment(ISiteWhereHBaseClient hbase, String assnToken,
        DeviceAssignmentRecordType eventType, IDateRangeSearchCriteria criteria) throws SiteWhereException {
    byte[] assnKey = IdManager.getInstance().getAssignmentKeys().getValue(assnToken);
    if (assnKey == null) {
        throw new SiteWhereSystemException(ErrorCode.InvalidDeviceAssignmentToken, ErrorLevel.ERROR);
    }

    // Note: Because time values are inverted, start and end keys are reversed.
    byte[] startKey = null, endKey = null;
    if (criteria.getStartDate() != null) {
        startKey = getRowKey(assnKey, criteria.getEndDate().getTime());
    } else {
        startKey = getAbsoluteStartKey(assnKey);
    }
    if (criteria.getEndDate() != null) {
        endKey = getRowKey(assnKey, criteria.getStartDate().getTime());
    } else {
        endKey = getAbsoluteEndKey(assnKey);
    }

    HTableInterface events = null;
    ResultScanner scanner = null;
    try {
        events = hbase.getTableInterface(ISiteWhereHBase.EVENTS_TABLE_NAME);
        Scan scan = new Scan();
        scan.setStartRow(startKey);
        scan.setStopRow(endKey);
        scanner = events.getScanner(scan);

        Pager<byte[]> pager = new Pager<byte[]>(criteria);
        Iterator<Result> results = scanner.iterator();
        while (results.hasNext()) {
            Result current = results.next();
            Map<byte[], byte[]> cells = current.getFamilyMap(ISiteWhereHBase.FAMILY_ID);
            for (byte[] qual : cells.keySet()) {
                byte[] value = cells.get(qual);
                if ((qual.length > 3) && (qual[3] == eventType.getType())) {
                    Date eventDate = getDateForEventKeyValue(current.getRow(), qual);
                    if ((criteria.getStartDate() != null) && (eventDate.before(criteria.getStartDate()))) {
                        continue;
                    }
                    if ((criteria.getEndDate() != null) && (eventDate.after(criteria.getEndDate()))) {
                        continue;
                    }
                    pager.process(value);
                }
            }
        }
        return pager;
    } catch (IOException e) {
        throw new SiteWhereException("Error scanning event rows.", e);
    } finally {
        if (scanner != null) {
            scanner.close();
        }
        HBaseUtils.closeCleanly(events);
    }

}

From source file:org.wso2.carbon.apimgt.hostobjects.oidc.internal.Util.java

public static boolean validateIdClaims(ServerConfiguration serverConfiguration, AuthClient authClient,
        JWT idToken, String nonce, ReadOnlyJWTClaimsSet idClaims) throws Exception {

    boolean isValid = true;
    String clientId = authClient.getClientId();
    String clientAlgorithm = authClient.getClientAlgorithm();
    Algorithm tokenAlg = idToken.getHeader().getAlgorithm();

    if (clientAlgorithm != null) {

        Algorithm clientAlg = new Algorithm(clientAlgorithm);
        if (!clientAlg.equals(tokenAlg)) {
            isValid = false;//from  w ww.j  a  va2 s  .com
            log.error("Token algorithm " + tokenAlg + " does not match expected algorithm " + clientAlg);
        }
    }

    // check the issuer
    if (idClaims.getIssuer() == null) {
        isValid = false;
        log.error("Id Token Issuer is null");
    } else if (!idClaims.getIssuer().equals(serverConfiguration.getIssuer())) {
        isValid = false;
        log.error("Issuers do not match, expected " + serverConfiguration.getIssuer() + " got "
                + idClaims.getIssuer());
    }

    // check expiration
    if (idClaims.getExpirationTime() == null) {
        isValid = false;
        log.error("Id Token does not have required expiration claim");
    } else {
        // it's not null, see if it's expired
        Date now = new Date(System.currentTimeMillis() - (OIDCConstants.TIME_SKEW_ALLOWANCE * 1000));
        if (now.after(idClaims.getExpirationTime())) {
            isValid = false;
            log.error("Id Token is expired: " + idClaims.getExpirationTime());
        }
    }

    // check not before
    if (idClaims.getNotBeforeTime() != null) {
        Date now = new Date(System.currentTimeMillis() + (OIDCConstants.TIME_SKEW_ALLOWANCE * 1000));
        if (now.before(idClaims.getNotBeforeTime())) {
            isValid = false;
            log.error("Id Token not valid untill: " + idClaims.getNotBeforeTime());
        }
    }

    // check issued at
    if (idClaims.getIssueTime() == null) {
        isValid = false;
        log.error("Id Token does not have required issued-at claim");
    } else {
        // since it's not null, see if it was issued in the future
        Date now = new Date(System.currentTimeMillis() + (OIDCConstants.TIME_SKEW_ALLOWANCE * 1000));
        if (now.before(idClaims.getIssueTime())) {
            isValid = false;
            log.error("Id Token was issued in the future: " + idClaims.getIssueTime());
        }
    }

    // check audience
    if (idClaims.getAudience() == null) {
        isValid = false;
        log.error("Id token audience is null");
    } else if (!idClaims.getAudience().contains(clientId)) {
        isValid = false;
        log.error("Audience does not match, expected " + clientId + " got " + idClaims.getAudience());
    }

    // compare the nonce to our stored claim
    String nonceValue = idClaims.getStringClaim("nonce");
    if (nonceValue == null || "".equals(nonceValue)) {
        isValid = false;
        log.error("ID token did not contain a nonce claim.");
    } else if (!nonceValue.equals(nonce)) {
        isValid = false;
        log.error("Possible replay attack detected! The comparison of the nonce in the returned "
                + "ID Token to the session " + "NONCE" + " failed. Expected " + nonce + " got " + nonceValue
                + ".");

    }

    return isValid;
}

From source file:com.feilong.core.date.DateExtensionUtil.java

/**
 * ?(??),./*from   w  w w .ja v a  2s  .co  m*/
 * 
 * <h3>:</h3>
 * <blockquote>
 * 
 * <pre class="code">
 * Date fromDate = DateUtil.toDate("2011-03-5 23:31:25.456", DatePattern.COMMON_DATE_AND_TIME);
 * Date toDate = DateUtil.toDate("2011-03-10 01:30:24.895", DatePattern.COMMON_DATE_AND_TIME);
 * LOGGER.debug(JsonUtil.format(DateExtensionUtil.getIntervalDayList(fromDate, toDate)));
 * </pre>
 * 
 * <b>:</b>
 * 
 * <pre class="code">
 * ["2011-03-05 00:00:00",
 * "2011-03-06 00:00:00",
 * "2011-03-07 00:00:00",
 * "2011-03-08 00:00:00",
 * "2011-03-09 00:00:00",
 * "2011-03-10 00:00:00"
 * ]
 * </pre>
 * 
 * </blockquote>
 * 
 * <h3>:</h3>
 * <blockquote>
 * <ol>
 * <li>?? <code>00:00:00.000</code></li>
 * <li> <code>fromDate</code> <code>toDate</code></li>
 * </ol>
 * </blockquote>
 * 
 * @param fromDate
 *            the from date
 * @param toDate
 *            the to date
 * @return  <code>fromDate</code> null, {@link NullPointerException}<br>
 *          <code>toDate</code> null, {@link NullPointerException}
 * @see #getIntervalDay(Date, Date)
 * @see org.apache.commons.lang3.time.DateUtils#iterator(Calendar, int)
 * @since 1.5.4
 */
public static List<Date> getIntervalDayList(Date fromDate, Date toDate) {
    Validate.notNull(fromDate, "fromDate can't be null!");
    Validate.notNull(toDate, "toDate can't be null!");

    Date minDate = fromDate.before(toDate) ? fromDate : toDate;
    Date maxDate = fromDate.before(toDate) ? toDate : fromDate;

    // ******?********
    Date beginDateReset = DateUtil.getFirstDateOfThisDay(minDate);
    Date endDateReset = DateUtil.getLastDateOfThisDay(maxDate);

    List<Date> list = new ArrayList<Date>();
    list.add(beginDateReset);

    // 
    int intervalDay = getIntervalDay(beginDateReset, endDateReset);
    for (int i = 0; i < intervalDay; ++i) {
        list.add(DateUtil.addDay(beginDateReset, i + 1));
    }

    return list;
}

From source file:net.kamhon.ieagle.util.DateUtil.java

/**
 * Not Consider time. Just compare date.
 * //from  www .jav a  2 s .c o  m
 * @param date
 * @param startDate
 * @param endDate
 * @return
 */
public static boolean isBetweenDate(Date date, Date startDate, Date endDate) {
    Date clonedDate = (Date) date.clone();
    clonedDate = formatDateByTime(clonedDate, 0, 0, 0, 0);

    Date clonedStartDate = (Date) startDate.clone();
    Date clonedEndDate = (Date) endDate.clone();

    clonedStartDate = formatDateByTime(clonedStartDate, 0, 0, 0, 0);
    clonedEndDate = formatDateByTime(clonedEndDate, 23, 59, 59, 999);

    return (clonedDate.equals(clonedStartDate) || clonedDate.after(clonedStartDate))
            && (clonedDate.equals(clonedEndDate) || clonedDate.before(clonedEndDate));
}

From source file:org.wso2.carbon.apimgt.authenticator.oidc.util.Util.java

public static boolean validateIdClaims(ServerConfiguration serverConfiguration, AuthClient authClient,
        JWT idToken, String nonce, ReadOnlyJWTClaimsSet idClaims) throws Exception {

    boolean isValid = true;
    String clientId = authClient.getClientId();
    String clientAlgorithm = authClient.getClientAlgorithm();
    Algorithm tokenAlg = idToken.getHeader().getAlgorithm();

    if (clientAlgorithm != null) {

        Algorithm clientAlg = new Algorithm(clientAlgorithm);
        if (!clientAlg.equals(tokenAlg)) {
            isValid = false;/*from  w  w  w  . j  ava 2 s. com*/
            log.error("Token algorithm " + tokenAlg + " does not match expected algorithm " + clientAlg);
        }
    }

    // check the issuer
    if (idClaims.getIssuer() == null) {
        isValid = false;
        log.error("Id Token Issuer is null");
    } else if (!idClaims.getIssuer().equals(serverConfiguration.getIssuer())) {
        isValid = false;
        log.error("Issuers do not match, expected " + serverConfiguration.getIssuer() + " got "
                + idClaims.getIssuer());
    }

    // check expiration
    if (idClaims.getExpirationTime() == null) {
        isValid = false;
        log.error("Id Token does not have required expiration claim");
    } else {
        // it's not null, see if it's expired
        Date now = new Date(
                System.currentTimeMillis() - (OIDCAuthenticatorBEConstants.TIME_SKEW_ALLOWANCE * 1000));
        if (now.after(idClaims.getExpirationTime())) {
            isValid = false;
            log.error("Id Token is expired: " + idClaims.getExpirationTime());
        }
    }

    // check not before
    if (idClaims.getNotBeforeTime() != null) {
        Date now = new Date(
                System.currentTimeMillis() + (OIDCAuthenticatorBEConstants.TIME_SKEW_ALLOWANCE * 1000));
        if (now.before(idClaims.getNotBeforeTime())) {
            isValid = false;
            log.error("Id Token not valid untill: " + idClaims.getNotBeforeTime());
        }
    }

    // check issued at
    if (idClaims.getIssueTime() == null) {
        isValid = false;
        log.error("Id Token does not have required issued-at claim");
    } else {
        // since it's not null, see if it was issued in the future
        Date now = new Date(
                System.currentTimeMillis() + (OIDCAuthenticatorBEConstants.TIME_SKEW_ALLOWANCE * 1000));
        if (now.before(idClaims.getIssueTime())) {
            isValid = false;
            log.error("Id Token was issued in the future: " + idClaims.getIssueTime());
        }
    }

    // check audience
    if (idClaims.getAudience() == null) {
        isValid = false;
        log.error("Id token audience is null");
    } else if (!idClaims.getAudience().contains(clientId)) {
        isValid = false;
        log.error("Audience does not match, expected " + clientId + " got " + idClaims.getAudience());
    }

    // compare the nonce to our stored claim
    String nonceValue = idClaims.getStringClaim("nonce");
    if (nonceValue == null || "".equals(nonceValue)) {
        isValid = false;
        log.error("ID token did not contain a nonce claim.");
    } else if (!nonceValue.equals(nonce)) {
        isValid = false;
        log.error("Possible replay attack detected! The comparison of the nonce in the returned "
                + "ID Token to the session " + "NONCE" + " failed. Expected " + nonce + " got " + nonceValue
                + ".");

    }

    return isValid;
}