Example usage for java.time Instant compareTo

List of usage examples for java.time Instant compareTo

Introduction

In this page you can find the example usage for java.time Instant compareTo.

Prototype

@Override
public int compareTo(Instant otherInstant) 

Source Link

Document

Compares this instant to the specified instant.

Usage

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.parse("2014-12-03T10:15:30.00Z");
    System.out.println(instant.compareTo(Instant.now()));

}

From source file:com.epam.ta.reportportal.database.UniqueBugDocumentHandler.java

public Map<String, List<ChartObject>> getResult() {
    // Sorting//  w w w  . j av  a  2  s  .  c  om
    for (Map.Entry<String, List<ChartObject>> entry : result.entrySet()) {
        Collections.sort(entry.getValue(), (o1, o2) -> {
            Instant one = Instant.ofEpochMilli(Long.valueOf(o1.getStartTime()));
            Instant next = Instant.ofEpochMilli(Long.valueOf(o2.getStartTime()));
            return one.compareTo(next);
        });
        result.put(entry.getKey(), entry.getValue());
    }
    return result;
}

From source file:com.github.aptd.simulation.elements.IBaseElement.java

@IAgentActionFilter
@IAgentActionName(name = "nextactivation/set")
private void setNextActivation(@Nullable final ZonedDateTime p_datetime) throws Exception {
    if (p_datetime == null)
        throw new IllegalArgumentException("next activation time must not be null");

    final Instant l_instant = p_datetime.toInstant();
    if (l_instant.compareTo(m_time.current()) <= 0)
        throw new IllegalArgumentException("next activation time must be in the future");

    m_nextactivation = l_instant;//w w  w . j a va 2 s  .co m
}

From source file:com.att.aro.datacollector.ioscollector.utilities.AppSigningHelper.java

private boolean isProvProfileExpired() throws IOSAppException {
    DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT;
    Instant dateTime = Instant.from(formatter.parse(provProfile.getExpiration()));
    return dateTime.compareTo(Instant.now()) < 0;
}

From source file:com.orange.cepheus.cep.SubscriptionManager.java

private void periodicSubscriptionTask() {

    Instant now = Instant.now();
    Instant nextSubscriptionTaskDate = now.plusMillis(subscriptionPeriodicity);
    logger.info("Launch of the periodic subscription task at {}", now.toString());

    // Futures will use the current subscription list.
    // So that they will not add old subscriptions to a new configuration.
    Subscriptions subscriptions = this.subscriptions;

    for (EventTypeIn eventType : eventTypeIns) {
        SubscribeContext subscribeContext = null;
        for (Provider provider : eventType.getProviders()) {

            boolean deadlineIsPassed = false;
            Instant subscriptionDate = provider.getSubscriptionDate();
            if (subscriptionDate != null) {
                Instant subscriptionEndDate = subscriptionDate.plus(Duration.parse(subscriptionDuration));
                // check if deadline is passed
                if (nextSubscriptionTaskDate.compareTo(subscriptionEndDate) >= 0) {
                    deadlineIsPassed = true;
                    String subscriptionId = provider.getSubscriptionId();
                    // if delay is passed then clear the subscription info in provider et suppress subscription
                    if (subscriptionId != null) {
                        subscriptions.removeSubscription(subscriptionId);
                        provider.setSubscriptionId(null);
                        provider.setSubscriptionDate(null);
                    }//from ww w.j a va 2  s.c  o m
                }
            }
            //Send subscription if subscription is a new subscription or we do not receive a response (subscriptionDate is null)
            //Send subscription if deadline is passed
            if ((subscriptionDate == null) || deadlineIsPassed) {
                // lazy build body request only when the first request requires it
                if (subscribeContext == null) {
                    subscribeContext = buildSubscribeContext(eventType);
                }
                subscribeProvider(provider, subscribeContext, subscriptions);
            }
        }
    }
}

From source file:org.cryptomator.frontend.webdav.jackrabbitservlet.FilesystemResourceFactory.java

/**
 * @return <code>true</code> if a partial response should be generated according to an If-Range precondition.
 *///from  www. j  a  v  a  2s  .  c o m
private boolean isIfRangeHeaderSatisfied(FileLocator file, String ifRangeHeader) throws DavException {
    if (ifRangeHeader == null) {
        // no header set -> satisfied implicitly
        return true;
    } else {
        try {
            Instant expectedTime = Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(ifRangeHeader));
            Instant actualTime = file.lastModified();
            return expectedTime.compareTo(actualTime) == 0;
        } catch (DateTimeParseException e) {
            throw new DavException(DavServletResponse.SC_BAD_REQUEST,
                    "Unsupported If-Range header: " + ifRangeHeader);
        }
    }
}

From source file:org.cryptomator.frontend.webdav.servlet.DavResourceFactoryImpl.java

/**
 * @return <code>true</code> if a partial response should be generated according to an If-Range precondition.
 *//* ww w . j av  a2 s.c om*/
private boolean isIfRangeHeaderSatisfied(BasicFileAttributes attr, String ifRangeHeader) throws DavException {
    if (ifRangeHeader == null) {
        // no header set -> satisfied implicitly
        return true;
    } else {
        try {
            Instant expectedTime = Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(ifRangeHeader));
            Instant actualTime = attr.lastModifiedTime().toInstant();
            return expectedTime.compareTo(actualTime) == 0;
        } catch (DateTimeParseException e) {
            throw new DavException(DavServletResponse.SC_BAD_REQUEST,
                    "Unsupported If-Range header: " + ifRangeHeader);
        }
    }
}

From source file:org.janusgraph.graphdb.database.management.ManagementSystem.java

@Override
public void forceCloseInstance(String instanceId) {
    Preconditions.checkArgument(!graph.getConfiguration().getUniqueGraphId().equals(instanceId),
            "Cannot force close this current instance [%s]. Properly shut down the graph instead.", instanceId);
    Preconditions.checkArgument(modifyConfig.has(REGISTRATION_TIME, instanceId),
            "Instance [%s] is not currently open", instanceId);
    Instant registrationTime = modifyConfig.get(REGISTRATION_TIME, instanceId);
    Preconditions.checkArgument(registrationTime.compareTo(txStartTime) < 0,
            "The to-be-closed instance [%s] was started after this transaction"
                    + "which indicates a successful restart and can hence not be closed: %s vs %s",
            instanceId, registrationTime, txStartTime);
    modifyConfig.remove(REGISTRATION_TIME, instanceId);
}