Java Code Examples for java.time.LocalDateTime#isEqual()

The following examples show how to use java.time.LocalDateTime#isEqual() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Logic.java    From HubTurbo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Replaces assignee of the issue in the {@link Logic#models} corresponding to {@code modifiedIssue} with
 * {@code originalAssigneeLoginName} if the current assignee on the issue is assigned at
 * the same time as {@code modifiedIssue}
 * @param originalIssue
 */
private void revertLocalAssigneeReplace(TurboIssue originalIssue) {
    TurboIssue currentIssue = getIssue(originalIssue.getRepoId(), originalIssue.getId()).orElse(originalIssue);
    LocalDateTime originalAssigneeModifiedAt = originalIssue.getAssigneeLastModifiedAt();
    LocalDateTime currentAssigneeAssignedAt = currentIssue.getAssigneeLastModifiedAt();
    boolean isCurrentAssigneeModifiedFromOriginalAssignee = originalAssigneeModifiedAt.isEqual(
            currentAssigneeAssignedAt);

    if (!isCurrentAssigneeModifiedFromOriginalAssignee) {
        return;
    }

    logger.info("Reverting assignee for issue " + currentIssue);
    models.replaceIssueAssignee(currentIssue.getRepoId(), currentIssue.getId(), originalIssue.getAssignee());
    refreshUI();
}
 
Example 2
Source File: Logic.java    From HubTurbo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Sets the state of the issue in the {@link Logic#models} corresponding to {@code modifiedIssue} to
 * {@code isOpenOriginally} if the current state on the issue is assigned at the same time as {@code modifiedIssue}
 *
 * @param modifiedIssue
 * @param isOpenOriginally
 */
private void revertLocalStateEdit(TurboIssue modifiedIssue, boolean isOpenOriginally) {
    TurboIssue currentIssue = getIssue(modifiedIssue.getRepoId(), modifiedIssue.getId()).orElse(modifiedIssue);
    LocalDateTime originalStateModifiedAt = modifiedIssue.getStateLastModifiedAt();
    LocalDateTime currentStateModifiedAt = currentIssue.getStateLastModifiedAt();
    boolean isCurrentStateModifiedFromOriginalState = originalStateModifiedAt.isEqual(currentStateModifiedAt);

    if (!isCurrentStateModifiedFromOriginalState) {
        logger.warn("Not reverting state for issue " + currentIssue + " as it is modified somewhere else.");
        return;
    }

    logger.info("Reverting state for issue " + currentIssue);
    models.editIssueState(currentIssue.getRepoId(), currentIssue.getId(), isOpenOriginally);
    refreshUI();
}
 
Example 3
Source File: ChartPointsFormatter.java    From cucumber-performance with MIT License 5 votes vote down vote up
private Chart createChart(BaseResult simulation ,LocalDateTime start, LocalDateTime stop, HashMap<String,List<GroupResult>> results) {
	Chart chart = new Chart();
	Long period = getPeriod(Duration.between(start,stop), chartPoints);
	LocalDateTime endPeriod = this.getEnd(start, period);
	LocalDateTime startPeriod = start;
	statistics = new DefaultStatistics(simulation, results);
	while (endPeriod.isBefore(stop)|| endPeriod.isEqual(stop)) {
		runMinions(statistics.getStats(isStrict,startPeriod,endPeriod),statistics.getSortedResults());
		statistics.getErrors();
		chart.putPoint(getMid(startPeriod,endPeriod), statistics.getStatistics());
		startPeriod = endPeriod;
		endPeriod = this.getEnd(endPeriod, period);
	}
	return chart;
}
 
Example 4
Source File: LocalDateTimeValidator.java    From andhow with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValid(LocalDateTime value) {
	if (value != null) {
		return value.isBefore(ref) || value.isEqual(ref);
	}
	return false;
}
 
Example 5
Source File: LocalDateTimeValidator.java    From andhow with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValid(LocalDateTime value) {
	if (value != null) {
		return value.isAfter(ref) || value.isEqual(ref);
	}
	return false;
}
 
Example 6
Source File: TimeframeIntervalHandler.java    From SmartApplianceEnabler with GNU General Public License v2.0 5 votes vote down vote up
public void addTimeframeInterval(LocalDateTime now, TimeframeInterval timeframeInterval, boolean asFirst, boolean updateQueue) {
    logger.debug("{}: Adding timeframeInterval to queue: {}", applianceId, timeframeInterval.toString(now));

    addTimeframeIntervalChangedListener(timeframeInterval.getRequest());
    timeframeIntervalChangedListeners.forEach(
            listener -> listener.timeframeIntervalCreated(now, timeframeInterval));

    if (asFirst) {
        TimeframeInterval activeTimeframeInterval = getActiveTimeframeInterval();
        if(activeTimeframeInterval != null) {
            deactivateTimeframeInterval(now, activeTimeframeInterval);

            LocalDateTime firstIntervalStart = activeTimeframeInterval.getInterval().getStart();
            LocalDateTime addedIntervalEnd = timeframeInterval.getInterval().getEnd();
            if(firstIntervalStart.isEqual(addedIntervalEnd) || firstIntervalStart.isBefore(addedIntervalEnd)) {
                Interval firstIntervalAdjusted = new Interval(addedIntervalEnd.plusSeconds(1),
                        activeTimeframeInterval.getInterval().getEnd());
                activeTimeframeInterval.setInterval(firstIntervalAdjusted);
            }
        }
        queue.addFirst(timeframeInterval);
    } else {
        queue.add(timeframeInterval);
    }
    timeframeInterval.stateTransitionTo(now, TimeframeIntervalState.QUEUED);
    if(updateQueue) {
        updateQueue(now, false);
    }
}
 
Example 7
Source File: TimeframeInterval.java    From SmartApplianceEnabler with GNU General Public License v2.0 5 votes vote down vote up
public boolean isIntervalSufficient(LocalDateTime now) {
    if(getRequest() instanceof AbstractEnergyRequest) {
        return true;
    }
    LocalDateTime latestStart = getLatestStart(now, LocalDateTime.from(interval.getEnd()), getRequest().getMax(now));
    return now.isEqual(latestStart) || now.isBefore(latestStart);
}
 
Example 8
Source File: Logic.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Replaces labels of the issue in the {@link Logic#models} corresponding to {@code modifiedIssue} with
 * {@code originalLabels} if the current labels on the issue is assigned at the same time as {@code modifiedIssue}
 *
 * @param modifiedIssue
 * @param originalLabels
 */
private void revertLocalLabelsReplace(TurboIssue modifiedIssue, List<String> originalLabels) {
    TurboIssue currentIssue = getIssue(modifiedIssue.getRepoId(), modifiedIssue.getId()).orElse(modifiedIssue);
    LocalDateTime originalLabelsModifiedAt = modifiedIssue.getLabelsLastModifiedAt();
    LocalDateTime currentLabelsAssignedAt = currentIssue.getLabelsLastModifiedAt();
    boolean isCurrentLabelsModifiedFromOriginalLabels = originalLabelsModifiedAt.isEqual(currentLabelsAssignedAt);

    if (isCurrentLabelsModifiedFromOriginalLabels) {
        logger.info("Reverting labels for issue " + currentIssue);
        models.replaceIssueLabels(currentIssue.getRepoId(), currentIssue.getId(), originalLabels);
        refreshUI();
    }
}
 
Example 9
Source File: Logic.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Replaces the milestone of the issue in the {@link Logic#models} corresponding to {@code originalIssue}
 * with originalIssue's milestone if both issues have the same last modified LocalDateTime
 *
 * @param originalIssue
 */
private void revertLocalMilestoneReplace(TurboIssue originalIssue, Optional<Integer> oldMilestone) {
    TurboIssue currentIssue = getIssue(originalIssue.getRepoId(), originalIssue.getId()).orElse(originalIssue);
    LocalDateTime originalMilestoneModifiedAt = originalIssue.getMilestoneLastModifiedAt();
    LocalDateTime currentMilestoneAssignedAt = currentIssue.getMilestoneLastModifiedAt();
    boolean isCurrentMilestoneModifiedFromOriginalMilestone = originalMilestoneModifiedAt
            .isEqual(currentMilestoneAssignedAt);

    if (!isCurrentMilestoneModifiedFromOriginalMilestone) return;

    logger.info("Reverting milestone for issue " + currentIssue);
    models.replaceIssueMilestone(currentIssue.getRepoId(), currentIssue.getId(), oldMilestone);
    refreshUI();
}
 
Example 10
Source File: Axis.java    From charts with Apache License 2.0 4 votes vote down vote up
private List<LocalDateTime> createTickValues(final double WIDTH, final LocalDateTime START, final LocalDateTime END) {
    List<LocalDateTime> dateList = new ArrayList<>();
    LocalDateTime       dateTime = LocalDateTime.now();

    if (null == START || null == END) return dateList;

    // The preferred gap which should be between two tick marks.
    double majorTickSpace = 100;
    double noOfTicks      = WIDTH / majorTickSpace;

    List<LocalDateTime> previousDateList = new ArrayList<>();
    Interval            previousInterval = Interval.values()[0];

    // Starting with the greatest interval, add one of each dateTime unit.
    for (Interval interval : Interval.values()) {
        // Reset the dateTime.
        dateTime = LocalDateTime.of(START.toLocalDate(), START.toLocalTime());
        // Clear the list.
        dateList.clear();
        previousDateList.clear();
        currentInterval = interval;

        // Loop as long we exceeded the END bound.
        while(dateTime.isBefore(END)) {
            dateList.add(dateTime);
            dateTime = dateTime.plus(interval.getAmount(), interval.getInterval());
        }

        // Then check the size of the list. If it is greater than the amount of ticks, take that list.
        if (dateList.size() > noOfTicks) {
            dateTime = LocalDateTime.of(START.toLocalDate(), START.toLocalTime());
            // Recheck if the previous interval is better suited.
            while(dateTime.isBefore(END) || dateTime.isEqual(END)) {
                previousDateList.add(dateTime);
                dateTime = dateTime.plus(previousInterval.getAmount(), previousInterval.getInterval());
            }
            break;
        }

        previousInterval = interval;
    }
    if (previousDateList.size() - noOfTicks > noOfTicks - dateList.size()) {
        dateList = previousDateList;
        currentInterval = previousInterval;
    }

    // At last add the END bound.
    dateList.add(END);

    List<LocalDateTime> evenDateList = makeDatesEven(dateList, dateTime);
    // If there are at least three dates, check if the gap between the START date and the second date is at least half the gap of the second and third date.
    // Do the same for the END bound.
    // If gaps between dates are to small, remove one of them.
    // This can occur, e.g. if the START bound is 25.12.2013 and years are shown. Then the next year shown would be 2014 (01.01.2014) which would be too narrow to 25.12.2013.
    if (evenDateList.size() > 2) {
        LocalDateTime secondDate       = evenDateList.get(1);
        LocalDateTime thirdDate        = evenDateList.get(2);
        LocalDateTime lastDate         = evenDateList.get(dateList.size() - 2);
        LocalDateTime previousLastDate = evenDateList.get(dateList.size() - 3);

        // If the second date is too near by the START bound, remove it.
        if (secondDate.toEpochSecond(ZoneOffset.ofHours(0)) - START.toEpochSecond(ZoneOffset.ofHours(0)) < thirdDate.toEpochSecond(ZoneOffset.ofHours(0)) - secondDate.toEpochSecond(ZoneOffset.ofHours(0))) {
            evenDateList.remove(secondDate);
        }

        // If difference from the END bound to the last date is less than the half of the difference of the previous two dates,
        // we better remove the last date, as it comes to close to the END bound.
        if (END.toEpochSecond(ZoneOffset.ofHours(0)) - lastDate.toEpochSecond(ZoneOffset.ofHours(0)) < ((lastDate.toEpochSecond(ZoneOffset.ofHours(0)) - previousLastDate.toEpochSecond(ZoneOffset.ofHours(0)) * 0.5))) {
            evenDateList.remove(lastDate);
        }
    }
    return evenDateList;
}
 
Example 11
Source File: TimeframeInterval.java    From SmartApplianceEnabler with GNU General Public License v2.0 4 votes vote down vote up
public boolean isActivatable(LocalDateTime now, boolean ignoreStartTime) {
    return getState() == TimeframeIntervalState.QUEUED
            && (ignoreStartTime || now.isEqual(getInterval().getStart()) || now.isAfter(getInterval().getStart()))
            && (!(request instanceof RuntimeRequest) || isIntervalSufficient(now)
    );
}
 
Example 12
Source File: Interval.java    From SmartApplianceEnabler with GNU General Public License v2.0 4 votes vote down vote up
public boolean contains(LocalDateTime instant) {
    if(start != null && end != null && instant != null) {
        return (instant.isEqual(start) || instant.isAfter(start)) && (instant.isEqual(end) || instant.isBefore(end));
    }
    return false;
}
 
Example 13
Source File: OracleCDCSource.java    From datacollector with Apache License 2.0 4 votes vote down vote up
private boolean inSessionWindowCurrent(LocalDateTime startTime, LocalDateTime endTime) {
  LocalDateTime currentTime = nowAtDBTz();
  return (currentTime.isAfter(startTime) && currentTime.isBefore(endTime)) ||
      currentTime.isEqual(startTime) ||
      currentTime.isEqual(endTime);
}