List of usage examples for org.joda.time DateTime plus
public DateTime plus(ReadablePeriod period)
From source file:stroom.test.SetupSampleDataBean.java
License:Apache License
private String createRandomData() { final DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy,HH:mm:ss") .withZone(DateTimeZone.UTC); final DateTime refDateTime = new DateTime(2010, 1, 1, 0, 0, 0); final StringBuilder sb = new StringBuilder(); sb.append("Date,Time,FileNo,LineNo,User,Message\n"); for (int i = 0; i < 1000; i++) { final DateTime dateTime = refDateTime.plus((long) (Math.random() * 10000000)); sb.append(formatter.print(dateTime)); sb.append(","); sb.append(createNum(4));/* w ww. j a va 2 s. co m*/ sb.append(","); sb.append(createNum(10)); sb.append(",user"); sb.append(createNum(10)); sb.append(",Some message "); sb.append(createNum(10)); sb.append("\n"); } return sb.toString(); }
From source file:syncthing.android.service.SyncthingUtils.java
License:Open Source License
public static Interval getIntervalForRange(DateTime now, long start, long end) { DateTime daybreak = now.withTimeAtStartOfDay(); Interval interval;//w ww. j a v a 2 s. c o m if (start < end) { //same day interval = new Interval(daybreak.plus(start), daybreak.plus(end)); } else /*start >|== end*/ { if (now.isAfter(daybreak.plus(start))) { //rolls next day interval = new Interval(daybreak.plus(start), daybreak.plusDays(1).plus(end)); } else { //rolls previous day interval = new Interval(daybreak.minusDays(1).plus(start), daybreak.plus(end)); } } return interval; }
From source file:ta4jexamples.loaders.CsvTradesLoader.java
License:Open Source License
/** * Builds a list of empty ticks.//from w w w . j a v a 2s .c o m * @param beginTime the begin time of the whole period * @param endTime the end time of the whole period * @param duration the tick duration (in seconds) * @return the list of empty ticks */ private static List<Tick> buildEmptyTicks(DateTime beginTime, DateTime endTime, int duration) { List<Tick> emptyTicks = new ArrayList<Tick>(); Period tickTimePeriod = Period.seconds(duration); DateTime tickEndTime = beginTime; do { tickEndTime = tickEndTime.plus(tickTimePeriod); emptyTicks.add(new Tick(tickTimePeriod, tickEndTime)); } while (tickEndTime.isBefore(endTime)); return emptyTicks; }
From source file:TVShowTimelineMaker.timeConstraints.CharacterRelation.java
@Override public boolean complexApplyConstraint() { boolean changed = super.complexApplyConstraint(); if (this.mCharacterRelationKind.equals(CharacterRelationKind.MOTHER)) { if ((!this.mFirstNamedCharacter.getBirthday().isMarkedForComplexEval()) && this.mSecondNamedCharacter.getBirthday().isMarkedForComplexEval()) { this.mFirstNamedCharacter.getBirthday().setUpForComplexEval(); }/*from w w w . j a va 2 s .c om*/ if (this.mFirstNamedCharacter.getBirthday().isMarkedForComplexEval() && (!this.mSecondNamedCharacter.getBirthday().isMarkedForComplexEval())) { this.mSecondNamedCharacter.getBirthday().setUpForComplexEval(); } if (this.mFirstNamedCharacter.getBirthday().isMarkedForComplexEval() && this.mSecondNamedCharacter.getBirthday().isMarkedForComplexEval()) { NavigableSet<DateTime> firstEpisodeDates = this.mFirstNamedCharacter.getBirthday() .getPossibleDays(); NavigableSet<DateTime> secondEpisodeDates = this.mSecondNamedCharacter.getBirthday() .getPossibleDays(); DateTime lowerBoundOnBirthDay1 = secondEpisodeDates.first().minusYears(START_OF_MENOPAUSE) .withHourOfDay(1); DateTime upperBoundOnBirthDay1 = secondEpisodeDates.first() .minus(this.mCharacterRelationKind.mPeriod).withHourOfDay(23); Iterator<DateTime> firstEpisodeDatesIterator = firstEpisodeDates.iterator(); Iterator<DateTime> secondEpisodeDatesIterator = secondEpisodeDates.iterator(); DateTime curFirstEpisodeDate = firstEpisodeDatesIterator.next(); DateTime curSecondEpisodeDate = secondEpisodeDatesIterator.next(); boolean cont = true; //while (indexInToFirstEpisodeDatesDates < firstEpisodeDates.size()) { while (cont) { if (curFirstEpisodeDate.isBefore(lowerBoundOnBirthDay1)) { firstEpisodeDatesIterator.remove(); if (firstEpisodeDatesIterator.hasNext()) { curFirstEpisodeDate = firstEpisodeDatesIterator.next(); } else { cont = false; } changed = true; } else if (curFirstEpisodeDate.isAfter(upperBoundOnBirthDay1)) { if (secondEpisodeDatesIterator.hasNext()) { curSecondEpisodeDate = secondEpisodeDatesIterator.next(); lowerBoundOnBirthDay1 = curSecondEpisodeDate.minusYears(START_OF_MENOPAUSE) .withHourOfDay(1); upperBoundOnBirthDay1 = curSecondEpisodeDate.minus(this.mCharacterRelationKind.mPeriod) .withHourOfDay(23); } else { firstEpisodeDatesIterator.remove(); if (firstEpisodeDatesIterator.hasNext()) { curFirstEpisodeDate = firstEpisodeDatesIterator.next(); } else { cont = false; } changed = true; } } else { if (firstEpisodeDatesIterator.hasNext()) { curFirstEpisodeDate = firstEpisodeDatesIterator.next(); } else { cont = false; } } } firstEpisodeDatesIterator = firstEpisodeDates.iterator(); secondEpisodeDatesIterator = secondEpisodeDates.iterator(); curFirstEpisodeDate = firstEpisodeDatesIterator.next(); curSecondEpisodeDate = secondEpisodeDatesIterator.next(); cont = true; DateTime lowerBoundOnBirthDay2 = firstEpisodeDates.first().plus(this.mCharacterRelationKind.mPeriod) .withHourOfDay(1); DateTime upperBoundOnBirthDay2 = firstEpisodeDates.first().plusYears(START_OF_MENOPAUSE) .withHourOfDay(23); while (cont) { if (curSecondEpisodeDate.isBefore(lowerBoundOnBirthDay2)) { secondEpisodeDatesIterator.remove(); if (secondEpisodeDatesIterator.hasNext()) { curSecondEpisodeDate = secondEpisodeDatesIterator.next(); } else { cont = false; } changed = true; } else if (curSecondEpisodeDate.isAfter(upperBoundOnBirthDay2)) { if (firstEpisodeDatesIterator.hasNext()) { curFirstEpisodeDate = firstEpisodeDatesIterator.next(); lowerBoundOnBirthDay2 = curFirstEpisodeDate.plus(this.mCharacterRelationKind.mPeriod) .withHourOfDay(1); upperBoundOnBirthDay2 = curFirstEpisodeDate.plusYears(START_OF_MENOPAUSE) .withHourOfDay(23); } else { secondEpisodeDatesIterator.remove(); if (secondEpisodeDatesIterator.hasNext()) { curSecondEpisodeDate = secondEpisodeDatesIterator.next(); } else { cont = false; } changed = true; } } else { if (secondEpisodeDatesIterator.hasNext()) { curSecondEpisodeDate = secondEpisodeDatesIterator.next(); } else { cont = false; } } } } } return changed; }
From source file:TVShowTimelineMaker.timeConstraints.FieldChangeConstraint.java
public Event[] increaseWhat(DateTime inFirstDay, DateTime inSecondDay) { this.makeToPeriodIfNull(); DateTime minForFirstEvent = inSecondDay.minus(this.toPeriod); DateTime minForSecondEvent = inFirstDay.plus(this.toPeriod); if (this.lowerFields == null) { this.lowerFields = lowerFields(this.mDateTimeFieldType); }// www . j a va 2 s . c o m for (DateTimeFieldType curDateTimeFieldType : this.lowerFields) { minForFirstEvent = minForFirstEvent.property(curDateTimeFieldType).withMinimumValue(); minForSecondEvent = minForSecondEvent.property(curDateTimeFieldType).withMinimumValue(); } if (inFirstDay.isBefore(minForFirstEvent)) { return new Event[] { this.firstEpisode }; } else if (inSecondDay.isBefore(minForSecondEvent)) { return new Event[] { this.secondEpisode }; } else { return new Event[] {}; } }
From source file:TVShowTimelineMaker.timeConstraints.FieldChangeConstraint.java
public boolean consistentWithConstraint(DateTime inFirstDay, DateTime inSecondDay) { this.makeToPeriodIfNull(); int firstValue = inFirstDay.plus(this.toPeriod).get(this.mDateTimeFieldType); int secondValue = inSecondDay.get(this.mDateTimeFieldType); return (firstValue == secondValue); }
From source file:TVShowTimelineMaker.timeConstraints.Relation.java
@Override public boolean complexApplyConstraint() { boolean changed = this.applyConstraint(); if ((!this.firstEpisode.isMarkedForComplexEval()) && this.secondEpisode.isMarkedForComplexEval()) { if ((this.kind == RelationKind.FIXED_TIME_BEFORE) || (this.kind == RelationKind.SAME_DAY_OF_YEAR) || (this.kind == RelationKind.LESS_THEN_BEFORE) || (this.kind == RelationKind.SAME_TIME_AS) || (this.kind == RelationKind.BEFORE_SAME_DAY)) { this.firstEpisode.setUpForComplexEval(); }/* w w w . jav a 2s .c om*/ } if (this.firstEpisode.isMarkedForComplexEval() && (!this.secondEpisode.isMarkedForComplexEval())) { if ((this.kind == RelationKind.FIXED_TIME_BEFORE) || (this.kind == RelationKind.SAME_DAY_OF_YEAR) || (this.kind == RelationKind.LESS_THEN_BEFORE) || (this.kind == RelationKind.SAME_TIME_AS) || (this.kind == RelationKind.BEFORE_SAME_DAY)) { this.secondEpisode.setUpForComplexEval(); } } if (this.firstEpisode.isMarkedForComplexEval() && this.secondEpisode.isMarkedForComplexEval()) { NavigableSet<DateTime> firstEpisodeStartDates; NavigableSet<DateTime> firstEpisodeEndDates; NavigableSet<DateTime> secondEpisodeStartDates; NavigableSet<DateTime> secondEpisodeEndDates; if (this.firstEpisode instanceof OnceDayEvent) { OnceDayEvent firstEpisodeDayEvent = (OnceDayEvent) this.firstEpisode; firstEpisodeStartDates = firstEpisodeDayEvent.getPossibleDays(); firstEpisodeEndDates = firstEpisodeDayEvent.getPossibleDays(); } else if (this.firstEpisode instanceof OncePeriodEvent) { OncePeriodEvent firstEpisodePeriodEvent = (OncePeriodEvent) this.firstEpisode; firstEpisodeStartDates = firstEpisodePeriodEvent.getStartPossibleDays(); firstEpisodeEndDates = firstEpisodePeriodEvent.getEndPossibleDays(); } else { throw new UnsupportedOperationException( this.firstEpisode.getClass().getCanonicalName() + "Not supported yet"); } if (this.secondEpisode instanceof OnceDayEvent) { OnceDayEvent secondEpisodeDayEvent = (OnceDayEvent) this.secondEpisode; secondEpisodeStartDates = secondEpisodeDayEvent.getPossibleDays(); secondEpisodeEndDates = secondEpisodeDayEvent.getPossibleDays(); } else if (this.secondEpisode instanceof OncePeriodEvent) { OncePeriodEvent secondEpisodePeriodEvent = (OncePeriodEvent) this.secondEpisode; secondEpisodeStartDates = secondEpisodePeriodEvent.getStartPossibleDays(); secondEpisodeEndDates = secondEpisodePeriodEvent.getEndPossibleDays(); } else { throw new UnsupportedOperationException( this.firstEpisode.getClass().getCanonicalName() + "Not supported yet"); } Iterator<DateTime> firstEpisodeStartDatesIterator = firstEpisodeStartDates.iterator(); Iterator<DateTime> secondEpisodeStartDatesIterator = secondEpisodeStartDates.iterator(); DateTime curFirstEpisodeStartDate = firstEpisodeStartDatesIterator.next(); DateTime curSecondEpisodeStartDate = secondEpisodeStartDatesIterator.next(); Iterator<DateTime> firstEpisodeEndDatesIterator = firstEpisodeEndDates.iterator(); Iterator<DateTime> secondEpisodeEndDatesIterator = secondEpisodeEndDates.iterator(); DateTime curFirstEpisodeEndDate = firstEpisodeEndDatesIterator.next(); DateTime curSecondEpisodeEndDate = secondEpisodeEndDatesIterator.next(); boolean cont = true; if (this.kind == RelationKind.IMMEDIATELY_BEFORE) { DateTime startOfLastDay = secondEpisodeStartDates.last().withHourOfDay(1); /*while (indexInToFirstEpisodeDatesDates < firstEpisodeDates.size()) { if (firstEpisodeDates.get(indexInToFirstEpisodeDatesDates).isAfter(startOfLastDay)) { firstEpisodeDates.remove(indexInToFirstEpisodeDatesDates); changed = true; } else { indexInToFirstEpisodeDatesDates++; } }*/ while (!firstEpisodeEndDates.isEmpty()) { if (firstEpisodeEndDates.last().isAfter(startOfLastDay)) { firstEpisodeEndDates.pollLast(); changed = true; } else { break; } } DateTime endOfFirstPossibleDay = firstEpisodeEndDates.first().withHourOfDay(23); while (cont) { if (endOfFirstPossibleDay.isAfter(curSecondEpisodeStartDate)) { secondEpisodeStartDatesIterator.remove(); if (secondEpisodeStartDatesIterator.hasNext()) { curSecondEpisodeStartDate = secondEpisodeStartDatesIterator.next(); } else { cont = false; } changed = true; } else { //indexInToSecondEpisodeDatesDates++; break; } } } else if (this.kind == RelationKind.BEFORE) { DateTime startOfLastDay = secondEpisodeStartDates.last().withHourOfDay(1); /*while (indexInToFirstEpisodeDatesDates < firstEpisodeDates.size()) { if (firstEpisodeDates.get(indexInToFirstEpisodeDatesDates).isAfter(startOfLastDay)) { firstEpisodeDates.remove(indexInToFirstEpisodeDatesDates); changed = true; } else { indexInToFirstEpisodeDatesDates++; } }*/ while (!firstEpisodeEndDates.isEmpty()) { if (firstEpisodeEndDates.last().isAfter(startOfLastDay)) { firstEpisodeEndDates.pollLast(); changed = true; } else { break; } } DateTime endOfFirstPossibleDay = firstEpisodeEndDates.first().withHourOfDay(23); while (cont) { if (endOfFirstPossibleDay.isAfter(curSecondEpisodeStartDate)) { secondEpisodeStartDatesIterator.remove(); if (secondEpisodeStartDatesIterator.hasNext()) { curSecondEpisodeStartDate = secondEpisodeStartDatesIterator.next(); } else { cont = false; } changed = true; } else { //indexInToSecondEpisodeDatesDates++; break; } } } else if (this.kind == RelationKind.FIXED_TIME_BEFORE) { //while (indexInToFirstEpisodeDatesDates < firstEpisodeEndDates.size()) { while (cont) { //DateTime later = firstEpisodeEndDates.get(indexInToFirstEpisodeDatesDates).plus(time); DateTime later = curFirstEpisodeEndDate.plus(this.time); if (secondEpisodeStartDates.contains(later)) { if (firstEpisodeEndDatesIterator.hasNext()) { curFirstEpisodeEndDate = firstEpisodeEndDatesIterator.next(); } else { break; } } else { firstEpisodeEndDatesIterator.remove(); if (firstEpisodeEndDatesIterator.hasNext()) { curFirstEpisodeEndDate = firstEpisodeEndDatesIterator.next(); } else { cont = false; } changed = true; } } while (cont) { DateTime earlier = curSecondEpisodeStartDate.minus(this.time); if (firstEpisodeEndDates.contains(earlier)) { if (secondEpisodeStartDatesIterator.hasNext()) { curSecondEpisodeStartDate = secondEpisodeStartDatesIterator.next(); } else { break; } } else { secondEpisodeStartDatesIterator.remove(); if (secondEpisodeStartDatesIterator.hasNext()) { curSecondEpisodeStartDate = secondEpisodeStartDatesIterator.next(); } else { cont = false; } changed = true; } } } else if (this.kind == RelationKind.LESS_THEN_BEFORE) { DateTime startOfDay = curSecondEpisodeStartDate.withHourOfDay(1); DateTime tempEarliestPossibleDate = curSecondEpisodeStartDate.minus(this.time).withHourOfDay(1); while (cont) { if (curFirstEpisodeEndDate.isBefore(tempEarliestPossibleDate)) { firstEpisodeEndDatesIterator.remove(); if (firstEpisodeEndDatesIterator.hasNext()) { curFirstEpisodeEndDate = firstEpisodeEndDatesIterator.next(); } else { cont = false; } changed = true; } else if (curFirstEpisodeEndDate.isAfter(startOfDay)) { //if (indexInToSecondEpisodeDatesDates < secondEpisodeStartDates.size()) { if (secondEpisodeStartDatesIterator.hasNext()) { curSecondEpisodeStartDate = secondEpisodeStartDatesIterator.next(); startOfDay = curSecondEpisodeStartDate.withHourOfDay(1); tempEarliestPossibleDate = curSecondEpisodeStartDate.minus(this.time).withHourOfDay(1); } else { firstEpisodeEndDatesIterator.remove(); if (firstEpisodeEndDatesIterator.hasNext()) { curFirstEpisodeEndDate = firstEpisodeEndDatesIterator.next(); } else { cont = false; } changed = true; } } else { if (firstEpisodeEndDatesIterator.hasNext()) { curFirstEpisodeEndDate = firstEpisodeEndDatesIterator.next(); } else { cont = false; } } } firstEpisodeStartDatesIterator = firstEpisodeStartDates.iterator(); secondEpisodeStartDatesIterator = secondEpisodeStartDates.iterator(); curFirstEpisodeStartDate = firstEpisodeStartDatesIterator.next(); curSecondEpisodeStartDate = secondEpisodeStartDatesIterator.next(); firstEpisodeEndDatesIterator = firstEpisodeEndDates.iterator(); secondEpisodeEndDatesIterator = secondEpisodeEndDates.iterator(); curFirstEpisodeEndDate = firstEpisodeEndDatesIterator.next(); curSecondEpisodeEndDate = secondEpisodeEndDatesIterator.next(); cont = true; DateTime endOfDay = curFirstEpisodeEndDate.withHourOfDay(23); DateTime tempLatestPossibleDate = curFirstEpisodeEndDate.plus(this.time).withHourOfDay(23); while (cont) { if (curSecondEpisodeStartDate.isBefore(endOfDay)) { secondEpisodeStartDatesIterator.remove(); if (secondEpisodeStartDatesIterator.hasNext()) { curSecondEpisodeStartDate = secondEpisodeStartDatesIterator.next(); } else { cont = false; } changed = true; } else if (curSecondEpisodeStartDate.isAfter(tempLatestPossibleDate)) { //indexInToFirstEpisodeDatesDates++; //if (indexInToFirstEpisodeDatesDates < firstEpisodeEndDates.size()) { if (firstEpisodeEndDatesIterator.hasNext()) { curFirstEpisodeEndDate = firstEpisodeEndDatesIterator.next(); endOfDay = curFirstEpisodeEndDate.withHourOfDay(23); tempLatestPossibleDate = curFirstEpisodeEndDate.plus(this.time).withHourOfDay(23); } else { secondEpisodeStartDatesIterator.remove(); if (secondEpisodeStartDatesIterator.hasNext()) { curSecondEpisodeStartDate = secondEpisodeStartDatesIterator.next(); } else { cont = false; } changed = true; } } else { if (secondEpisodeStartDatesIterator.hasNext()) { curSecondEpisodeStartDate = secondEpisodeStartDatesIterator.next(); } else { cont = false; } } } } else if (this.kind == RelationKind.SAME_DAY_OF_YEAR) { changed |= this.mSameTimeOfYearConstraint.complexApplyConstraint(); } else if ((this.kind == RelationKind.SAME_TIME_AS) || (this.kind == RelationKind.BEFORE_SAME_DAY)) { Iterator<DateTime> iterator = firstEpisodeStartDates.iterator(); while (iterator.hasNext()) { DateTime next = iterator.next(); if (!secondEpisodeStartDates.contains(next)) { iterator.remove(); changed = true; } } iterator = secondEpisodeStartDates.iterator(); while (iterator.hasNext()) { DateTime next = iterator.next(); if (!firstEpisodeStartDates.contains(next)) { iterator.remove(); changed = true; } } iterator = firstEpisodeEndDates.iterator(); while (iterator.hasNext()) { DateTime next = iterator.next(); if (!secondEpisodeEndDates.contains(next)) { iterator.remove(); changed = true; } } iterator = secondEpisodeEndDates.iterator(); while (iterator.hasNext()) { DateTime next = iterator.next(); if (!firstEpisodeEndDates.contains(next)) { iterator.remove(); changed = true; } } } else if (this.kind == RelationKind.MORE_THEN_BEFORE) { DateTime tempEarliestPossibleDateForSecondEpisode = firstEpisodeEndDates.first().plus(this.time) .withHourOfDay(1); DateTime tempLatestPossibleDateForFirstEpisode = secondEpisodeStartDates.last().minus(this.time) .withHourOfDay(23); /*while (indexInToFirstEpisodeDatesDates < firstEpisodeDates.size()) { if (firstEpisodeDates.get(indexInToFirstEpisodeDatesDates).isAfter(tempLatestPossibleDateForFirstEpisode)) { firstEpisodeDates.remove(indexInToFirstEpisodeDatesDates); changed = true; } else { indexInToFirstEpisodeDatesDates++; } }*/ while (!firstEpisodeEndDates.isEmpty()) { if (firstEpisodeEndDates.last().isAfter(tempLatestPossibleDateForFirstEpisode)) { firstEpisodeEndDates.pollLast(); changed = true; } else { break; } } while (cont) { if (tempEarliestPossibleDateForSecondEpisode.isAfter(curSecondEpisodeStartDate)) { secondEpisodeStartDatesIterator.remove(); if (secondEpisodeStartDatesIterator.hasNext()) { curSecondEpisodeStartDate = secondEpisodeStartDatesIterator.next(); } else { cont = true; } changed = true; } else { //indexInToSecondEpisodeDatesDates++; break; } } } } return changed; }
From source file:TVShowTimelineMaker.timeConstraints.Relation.java
public boolean consistentWithConstraint(DateTime inFirstDay, DateTime inSecondDay) { if ((this.kind == RelationKind.IMMEDIATELY_BEFORE) || (this.kind == RelationKind.BEFORE)) { return inFirstDay.isBefore(inSecondDay.withHourOfDay(1)); } else if (this.kind == RelationKind.FIXED_TIME_BEFORE) { return inFirstDay.plus(this.time).equals(inSecondDay); } else if (this.kind == RelationKind.LESS_THEN_BEFORE) { DateTime tempEarliestPossibleDate = inSecondDay.minus(this.time).withHourOfDay(1); return inFirstDay.isAfter(tempEarliestPossibleDate) && inFirstDay.isBefore(inSecondDay.withHourOfDay(1)); } else if (this.kind == RelationKind.SAME_DAY_OF_YEAR) { return (inFirstDay.getMonthOfYear() == inSecondDay.getMonthOfYear()) && (inFirstDay.getDayOfMonth() == inSecondDay.getDayOfMonth()); } else if ((this.kind == RelationKind.SAME_TIME_AS) || (this.kind == RelationKind.BEFORE_SAME_DAY)) { return this.mSameTimeOfYearConstraint.consistentWithConstraint(inFirstDay, inSecondDay); } else if (this.kind == RelationKind.MORE_THEN_BEFORE) { DateTime earyer = inSecondDay.minus(this.time).withHourOfDay(1); return inFirstDay.isBefore(earyer); } else {/*from w w w . jav a 2 s. c o m*/ return true; } }
From source file:TVShowTimelineMaker.timeConstraints.Relation.java
@Override public boolean consistentWithConstraint(T inFirstPlacement, S inSecondPlacement) { DateTime inFirstStartTime;/*w ww . ja v a 2s. c o m*/ DateTime inFirstEndTime; DateTime inSecondStartTime; DateTime inSecondEndTime; if (this.firstEpisode instanceof OnceDayEvent) { OnceDayEvent.OnceDayEventPlacement curOnceDayEventPlacement = (OnceDayEvent.OnceDayEventPlacement) inFirstPlacement; inFirstStartTime = curOnceDayEventPlacement.day; inFirstEndTime = curOnceDayEventPlacement.day; } else { OncePeriodEvent.OncePeriodEventPlacement curOncePeriodEventPlacement = (OncePeriodEvent.OncePeriodEventPlacement) inFirstPlacement; inFirstStartTime = curOncePeriodEventPlacement.startDay; inFirstEndTime = curOncePeriodEventPlacement.endDay; } if (this.secondEpisode instanceof OnceDayEvent) { OnceDayEvent.OnceDayEventPlacement curOnceDayEventPlacement = (OnceDayEvent.OnceDayEventPlacement) inSecondPlacement; inSecondStartTime = curOnceDayEventPlacement.day; inSecondEndTime = curOnceDayEventPlacement.day; } else { OncePeriodEvent.OncePeriodEventPlacement curOncePeriodEventPlacement = (OncePeriodEvent.OncePeriodEventPlacement) inSecondPlacement; inSecondStartTime = curOncePeriodEventPlacement.startDay; inSecondEndTime = curOncePeriodEventPlacement.endDay; } if ((this.kind == RelationKind.IMMEDIATELY_BEFORE) || (this.kind == RelationKind.BEFORE)) { return inFirstEndTime.isBefore(inSecondStartTime.withHourOfDay(1)); } else if (this.kind == RelationKind.FIXED_TIME_BEFORE) { return inFirstEndTime.plus(this.time).equals(inSecondStartTime); } else if (this.kind == RelationKind.LESS_THEN_BEFORE) { DateTime tempEarliestPossibleDate = inSecondStartTime.minus(this.time).withHourOfDay(1); return inFirstEndTime.isAfter(tempEarliestPossibleDate) && inFirstEndTime.isBefore(inSecondStartTime.withHourOfDay(1)); } else if (this.kind == RelationKind.SAME_DAY_OF_YEAR) { return this.mSameTimeOfYearConstraint.consistentWithConstraint(inFirstPlacement, inSecondPlacement); } else if ((this.kind == RelationKind.SAME_TIME_AS) || (this.kind == RelationKind.BEFORE_SAME_DAY)) { return inFirstStartTime.equals(inSecondStartTime) && inFirstEndTime.equals(inSecondEndTime); } else if (this.kind == RelationKind.MORE_THEN_BEFORE) { DateTime earyer = inSecondStartTime.minus(this.time).withHourOfDay(1); return inFirstEndTime.isBefore(earyer); } else { return true; } }
From source file:TVShowTimelineMaker.timeConstraints.Relation.java
@Override public Event[] increaseWhat(Placement<?> inValues[]) { DateTime inFirstStartTime;/* w w w .j a va 2 s. c o m*/ DateTime inFirstEndTime; DateTime inSecondStartTime; DateTime inSecondEndTime; if (this.firstEpisode instanceof OnceDayEvent) { OnceDayEvent.OnceDayEventPlacement curOnceDayEventPlacement = (OnceDayEvent.OnceDayEventPlacement) inValues[0]; inFirstStartTime = curOnceDayEventPlacement.day; inFirstEndTime = curOnceDayEventPlacement.day; } else { return new Event[] { this.firstEpisode, this.secondEpisode }; } if (this.secondEpisode instanceof OnceDayEvent) { OnceDayEvent.OnceDayEventPlacement curOnceDayEventPlacement = (OnceDayEvent.OnceDayEventPlacement) inValues[1]; inSecondStartTime = curOnceDayEventPlacement.day; inSecondEndTime = curOnceDayEventPlacement.day; } else { return new Event[] { this.firstEpisode, this.secondEpisode }; } if ((this.kind == RelationKind.IMMEDIATELY_BEFORE) || (this.kind == RelationKind.BEFORE)) { if (!inFirstEndTime.isBefore(inSecondStartTime.withHourOfDay(1))) { return new Event[] { this.secondEpisode }; } } else if (this.kind == RelationKind.FIXED_TIME_BEFORE) { //inFirstEndTime.plus(this.time).equals(inSecondStartTime); DateTime later = inFirstEndTime.plus(this.time); if (later.isBefore(inSecondStartTime)) { return new Event[] { this.firstEpisode }; } else if (later.isAfter(inSecondStartTime)) { return new Event[] { this.secondEpisode }; } } else if (this.kind == RelationKind.LESS_THEN_BEFORE) { DateTime tempEarliestPossibleDate = inSecondStartTime.minus(this.time).withHourOfDay(1); if (!inFirstEndTime.isAfter(tempEarliestPossibleDate)) { return new Event[] { this.firstEpisode }; } if (!inFirstEndTime.isBefore(inSecondStartTime.withHourOfDay(1))) { return new Event[] { this.secondEpisode }; } } else if (this.kind == RelationKind.SAME_DAY_OF_YEAR) { return this.mSameTimeOfYearConstraint.increaseWhat(inValues); } else if ((this.kind == RelationKind.SAME_TIME_AS) || (this.kind == RelationKind.BEFORE_SAME_DAY)) { //inFirstStartTime.equals(inSecondStartTime) && inFirstEndTime.equals(inSecondEndTime); if (inFirstStartTime.isBefore(inSecondStartTime) || inFirstEndTime.isBefore(inSecondEndTime)) { return new Event[] { this.firstEpisode }; } else if (inFirstStartTime.isAfter(inSecondStartTime) || inFirstEndTime.isAfter(inSecondEndTime)) { return new Event[] { this.secondEpisode }; } } else if (this.kind == RelationKind.MORE_THEN_BEFORE) { DateTime earyer = inSecondStartTime.minus(this.time).withHourOfDay(1); if (!inFirstEndTime.isBefore(earyer)) { return new Event[] { this.secondEpisode }; } } return new Event[] {}; }