Example usage for org.joda.time Interval getEnd

List of usage examples for org.joda.time Interval getEnd

Introduction

In this page you can find the example usage for org.joda.time Interval getEnd.

Prototype

public DateTime getEnd() 

Source Link

Document

Gets the end of this time interval, which is exclusive, as a DateTime.

Usage

From source file:com.microsoft.exchange.ExchangeDateUtils.java

License:Apache License

/**
 * will always return at least two intervals.
 * //w  ww.  ja  v a  2s . c  o m
 * @param start
 * @param end
 * @param count
 * @return
 */
public static List<Interval> generateMultipleIntervals(Date start, Date end, int count) {
    List<Interval> intervals = generateIntervals(start, end);
    int actualCount = intervals.size();
    if (count > actualCount) {
        while (actualCount < count) {
            List<Interval> tIntervals = new ArrayList<Interval>();
            for (Interval i : intervals) {
                tIntervals.addAll(generateIntervals(i.getStart().toDate(), i.getEnd().toDate()));
            }
            intervals = tIntervals;
            actualCount = intervals.size();
        }
    }
    return intervals;
}

From source file:com.microsoft.exchange.impl.BaseExchangeCalendarDataDao.java

License:Apache License

/**
 * This method issues a {@link FindItem} request using a {@link CalendarViewType} to obtain identifiers for all {@link CalendarItemType}s between {@code startDate} and {@code endDate}
 * /* w  w  w . j  a v a  2 s . c  o  m*/
 * Note: CalendarView element returns single calendar items and all occurrences.  In other words, this method expands recurrence for you.
 * 
 * @see <a href='http://msdn.microsoft.com/en-us/library/office/aa566107(v=exchg.140).aspx'>FindItem Operation</a>
 * 
 * @param upn
 * @param startDate
 * @param endDate
 * @param calendarIds - if omitted the primary calendar folder will be targeted
 * @param depth
 * @return a never null but possibly empty {@link Set} of {@link ItemIdType}
 */
private Set<ItemIdType> findCalendarItemIdsInternal(String upn, Date startDate, Date endDate,
        Collection<FolderIdType> calendarIds, int depth) {
    Validate.isTrue(StringUtils.isNotBlank(upn), "upn argument cannot be blank");
    Validate.notNull(startDate, "startDate argument cannot be null");
    Validate.notNull(endDate, "endDate argument cannot be null");
    //if folderIds is empty the primary calendar folder will be targeted
    int newDepth = depth + 1;
    if (depth > getMaxRetries()) {
        throw new ExchangeRuntimeException("findCalendarItemIdsInternal(upn=" + upn + ",startDate=" + startDate
                + ",+endDate=" + endDate + ",...) failed " + getMaxRetries() + " consecutive attempts.");
    } else {
        setContextCredentials(upn);
        FindItem request = getRequestFactory().constructCalendarViewFindCalendarItemIdsByDateRange(startDate,
                endDate, calendarIds);
        try {
            FindItemResponse response = getWebServices().findItem(request);
            return getResponseUtils().parseFindItemIdResponseNoOffset(response);

        } catch (ExchangeInvalidUPNRuntimeException e0) {
            log.warn("findCalendarItemIdsInternal(upn=" + upn + ",startDate=" + startDate + ",+endDate="
                    + endDate
                    + ",...) ExchangeInvalidUPNRuntimeException.  Attempting to resolve valid upn... - failure #"
                    + newDepth);

            String resolvedUpn = resolveUpn(upn);
            if (StringUtils.isNotBlank(resolvedUpn) && (!resolvedUpn.equalsIgnoreCase(upn))) {
                return findCalendarItemIdsInternal(resolvedUpn, startDate, endDate, calendarIds, newDepth);
            } else {
                //rethrow
                throw e0;
            }
        } catch (ExchangeExceededFindCountLimitRuntimeException e1) {
            log.warn("findCalendarItemIdsInternal(upn=" + upn + ",startDate=" + startDate + ",+endDate="
                    + endDate + ",...) ExceededFindCountLimit splitting request and trying again. - failure #"
                    + newDepth);
            Set<ItemIdType> foundItems = new HashSet<ItemIdType>();
            List<Interval> intervals = ExchangeDateUtils.generateIntervals(startDate, endDate);
            for (Interval i : intervals) {
                foundItems.addAll(findCalendarItemIdsInternal(upn, i.getStart().toDate(), i.getEnd().toDate(),
                        calendarIds, newDepth));
            }
            return foundItems;
        } catch (ExchangeRuntimeException e2) {
            long backoff = getWaitTimeExp(newDepth);
            log.warn("findCalendarItemIdsInternal(upn=" + upn + ",startDate=" + startDate + ",+endDate="
                    + endDate + ",...) - failure #" + newDepth + ". Sleeping for " + backoff + " before retry. "
                    + e2.getMessage());
            try {
                Thread.sleep(backoff);
            } catch (InterruptedException e1) {
                log.warn("InterruptedException=" + e1);
            }
            return findCalendarItemIdsInternal(upn, startDate, endDate, calendarIds, newDepth);
        }
    }
}

From source file:com.netflix.ice.basic.BasicDataManager.java

License:Apache License

private double[] getData(Interval interval, TagLists tagLists) throws ExecutionException {
    DateTime start = config.startDate;/*from  ww  w .  j a v a  2 s.c  o  m*/
    DateTime end = config.startDate;

    if (consolidateType == ConsolidateType.hourly) {
        start = interval.getStart().withDayOfMonth(1).withMillisOfDay(0);
        end = interval.getEnd();
    } else if (consolidateType == ConsolidateType.daily) {
        start = interval.getStart().withDayOfYear(1).withMillisOfDay(0);
        end = interval.getEnd();
    }

    int num = 0;
    if (consolidateType == ConsolidateType.hourly) {
        num = interval.toPeriod(PeriodType.hours()).getHours();
        if (interval.getStart().plusHours(num).isBefore(interval.getEnd()))
            num++;
    } else if (consolidateType == ConsolidateType.daily) {
        num = interval.toPeriod(PeriodType.days()).getDays();
        if (interval.getStart().plusDays(num).isBefore(interval.getEnd()))
            num++;
    } else if (consolidateType == ConsolidateType.weekly) {
        num = interval.toPeriod(PeriodType.weeks()).getWeeks();
        if (interval.getStart().plusWeeks(num).isBefore(interval.getEnd()))
            num++;
    } else if (consolidateType == ConsolidateType.monthly) {
        num = interval.toPeriod(PeriodType.months()).getMonths();
        if (interval.getStart().plusMonths(num).isBefore(interval.getEnd()))
            num++;
    }

    double[] result = new double[num];

    do {
        ReadOnlyData data = getReadOnlyData(start);

        int resultIndex = 0;
        int fromIndex = 0;

        if (interval.getStart().isBefore(start)) {
            if (consolidateType == ConsolidateType.hourly) {
                resultIndex = Hours.hoursBetween(interval.getStart(), start).getHours();
            } else if (consolidateType == ConsolidateType.daily) {
                resultIndex = Days.daysBetween(interval.getStart(), start).getDays();
            } else if (consolidateType == ConsolidateType.weekly) {
                resultIndex = Weeks.weeksBetween(interval.getStart(), start).getWeeks();
            } else if (consolidateType == ConsolidateType.monthly) {
                resultIndex = Months.monthsBetween(interval.getStart(), start).getMonths();
            }
        } else {
            if (consolidateType == ConsolidateType.hourly) {
                fromIndex = Hours.hoursBetween(start, interval.getStart()).getHours();
            } else if (consolidateType == ConsolidateType.daily) {
                fromIndex = Days.daysBetween(start, interval.getStart()).getDays();
            } else if (consolidateType == ConsolidateType.weekly) {
                fromIndex = Weeks.weeksBetween(start, interval.getStart()).getWeeks();
                if (start.getDayOfWeek() != interval.getStart().getDayOfWeek())
                    fromIndex++;
            } else if (consolidateType == ConsolidateType.monthly) {
                fromIndex = Months.monthsBetween(start, interval.getStart()).getMonths();
            }
        }

        List<Integer> columeIndexs = Lists.newArrayList();
        int columeIndex = 0;
        for (TagGroup tagGroup : data.getTagGroups()) {
            if (tagLists.contains(tagGroup))
                columeIndexs.add(columeIndex);
            columeIndex++;
        }
        while (resultIndex < num && fromIndex < data.getNum()) {
            double[] fromData = data.getData(fromIndex++);
            for (Integer cIndex : columeIndexs)
                result[resultIndex] += fromData[cIndex];
            resultIndex++;
        }

        if (consolidateType == ConsolidateType.hourly)
            start = start.plusMonths(1);
        else if (consolidateType == ConsolidateType.daily)
            start = start.plusYears(1);
        else
            break;
    } while (start.isBefore(end));

    return result;
}

From source file:com.netflix.ice.basic.BasicThroughputMetricService.java

License:Apache License

public double[] getData(Interval interval, ConsolidateType consolidateType) throws Exception {
    DateTime start = interval.getStart().withDayOfMonth(1).withMillisOfDay(0);
    DateTime end = interval.getEnd();

    int num = interval.toPeriod(PeriodType.hours()).getHours();
    if (interval.getStart().plusHours(num).isBefore(interval.getEnd()))
        num++;/* w  w  w .  j  a v a2  s .c om*/

    double[] hourly = new double[num];
    List<Double> monthly = Lists.newArrayList();
    do {
        double total = 0;
        int resultIndex = interval.getStart().isBefore(start)
                ? Hours.hoursBetween(interval.getStart(), start).getHours()
                : 0;
        int fromIndex = interval.getStart().isBefore(start) ? 0
                : Hours.hoursBetween(start, interval.getStart()).getHours();

        double[] data = this.data.get(start);
        while (resultIndex < num && fromIndex < data.length) {
            total += data[fromIndex];
            hourly[resultIndex++] = data[fromIndex++];
        }

        start = start.plusMonths(1);
        monthly.add(total);
    } while (start.isBefore(end));

    int hoursInPeriod = (int) (consolidateType.millis / AwsUtils.hourMillis);
    num = consolidateType == ConsolidateType.monthly ? monthly.size()
            : (int) Math.ceil(1.0 * num / hoursInPeriod);
    double[] result = new double[num];

    if (consolidateType == ConsolidateType.monthly) {
        for (int i = 0; i < num; i++)
            result[i] = monthly.get(i);
    } else {
        for (int i = 0; i < hourly.length; i++)
            result[i / hoursInPeriod] += hourly[i];
    }
    return result;
}

From source file:com.netflix.ice.reader.ReaderConfig.java

License:Apache License

private void readData(Product product, DataManager dataManager, Interval interval,
        ConsolidateType consolidateType) {
    if (consolidateType == ConsolidateType.hourly) {
        DateTime start = interval.getStart().withDayOfMonth(1).withMillisOfDay(0);
        do {//from w  w  w. ja v  a2  s .  com
            int hours = dataManager.getDataLength(start);
            logger.info("found " + hours + " hours data for " + product + " " + interval);
            start = start.plusMonths(1);
        } while (start.isBefore(interval.getEnd()));
    } else if (consolidateType == ConsolidateType.daily) {
        DateTime start = interval.getStart().withDayOfYear(1).withMillisOfDay(0);
        do {
            dataManager.getDataLength(start);
            start = start.plusYears(1);
        } while (start.isBefore(interval.getEnd()));
    } else {
        dataManager.getData(interval, new TagLists(), TagType.Account, AggregateType.both, false);
    }
}

From source file:com.nfsdb.journal.Journal.java

License:Apache License

public TempPartition<T> createTempPartition(String name) throws JournalException {
    int lag = getMetadata().getLag();
    if (lag <= 0) {
        throw new JournalRuntimeException("Journal doesn't support temp partitions: %s", this);
    }/*from w w w . j a  va2 s . c om*/

    Interval interval = null;
    if (getMetadata().getPartitionType() != PartitionType.NONE) {
        if (nonLagPartitionCount() > 0) {
            Interval lastPartitionInterval = partitions.get(nonLagPartitionCount() - 1).getInterval();
            interval = new Interval(lastPartitionInterval.getStart(),
                    lastPartitionInterval.getEnd().plusHours(lag));
        } else {
            interval = Dates.intervalForDate(System.currentTimeMillis(), getMetadata().getPartitionType());
        }
    }
    return new TempPartition<>(this, interval, nonLagPartitionCount(), name);
}

From source file:com.peertopark.java.dates.Intervals.java

License:Apache License

/**
 * Get a list of DateTime with the days of week in a datetime interval
 * @param interval//from w ww. j a v a 2  s . c  o  m
 * @param dayOfWeek
 * @return List of DateTime
 */
public static List<DateTime> daysOfWeek(Interval interval, int dayOfWeek) {
    return Dates.daysOfWeekInDateInterval(interval.getStart(), interval.getEnd(), dayOfWeek);
}

From source file:com.peertopark.java.dates.iterators.DayOfWeekIterator.java

License:Apache License

public DayOfWeekIterator(Interval interval, int dayOfWeekToIterate) {
    this(interval.getStart(), interval.getEnd(), dayOfWeekToIterate);
}

From source file:com.pinterest.deployservice.handler.DeployHandler.java

License:Apache License

public List<DeployBean> getDeployCandidates(String envId, Interval interval, int size, boolean onlyGoodBuilds)
        throws Exception {
    LOG.info("Search Deploy candidates between {} and {} for environment {}",
            interval.getStart().toString(ISODateTimeFormat.dateTime()),
            interval.getEnd().toString(ISODateTimeFormat.dateTime()), envId);
    List<DeployBean> taggedGoodDeploys = new ArrayList<DeployBean>();

    List<DeployBean> availableDeploys = deployDAO.getAcceptedDeploys(envId, interval, size);

    if (!onlyGoodBuilds) {
        return availableDeploys;
    }/*from   w  w w .j  a  va 2s .c  om*/

    if (!availableDeploys.isEmpty()) {
        Map<String, DeployBean> buildId2DeployBean = new HashMap<String, DeployBean>();
        for (DeployBean deployBean : availableDeploys) {
            String buildId = deployBean.getBuild_id();
            if (StringUtils.isNotEmpty(buildId)) {
                buildId2DeployBean.put(buildId, deployBean);
            }
        }
        List<BuildBean> availableBuilds = buildDAO.getBuildsFromIds(buildId2DeployBean.keySet());
        List<BuildTagBean> buildTagBeanList = buildTagsManager.getEffectiveTagsWithBuilds(availableBuilds);
        for (BuildTagBean buildTagBean : buildTagBeanList) {
            if (buildTagBean.getTag() != null && buildTagBean.getTag().getValue() == TagValue.BAD_BUILD) {
                // bad build,  do not include
                LOG.info("Env {} Build {} is tagged as BAD_BUILD, ignore", envId, buildTagBean.getBuild());
            } else {
                String buildId = buildTagBean.getBuild().getBuild_id();
                taggedGoodDeploys.add(buildId2DeployBean.get(buildId));
            }
        }
    }
    // should order deploy bean by start date desc
    if (taggedGoodDeploys.size() > 0) {
        Collections.sort(taggedGoodDeploys, new Comparator<DeployBean>() {
            @Override
            public int compare(final DeployBean d1, final DeployBean d2) {
                return Long.compare(d2.getStart_date(), d1.getStart_date());
            }
        });
        LOG.info("Env {} the first deploy candidate is {}", envId, taggedGoodDeploys.get(0).getBuild_id());
    }
    return taggedGoodDeploys;
}

From source file:com.pinterest.teletraan.worker.AutoPromoter.java

License:Apache License

/**
 * get a list of available builds, and filter out the BAD_BUILD builds
 * @param envBean/*from   w  w  w. ja  va  2  s. c o m*/
 * @param interval
 * @param size
 * @return
 * @throws Exception
 */
List<BuildBean> getBuildCandidates(EnvironBean envBean, Interval interval, int size) throws Exception {
    // By default, buildName is the same as envName
    String buildName = envBean.getBuild_name();
    String scmBranch = envBean.getBranch();
    List<BuildBean> taggedGoodBuilds = new ArrayList<BuildBean>();

    List<BuildBean> availableBuilds = buildDAO.getAcceptedBuilds(buildName, scmBranch, interval, size);
    LOG.info("Env {} stage {} has {} accepted builds with name {} branch {} between {} and {}",
            envBean.getEnv_name(), envBean.getStage_name(), availableBuilds.size(), buildName, scmBranch,
            interval.getStart().toString(), interval.getEnd().toString());
    if (!availableBuilds.isEmpty()) {
        List<BuildTagBean> buildTagBeanList = buildTagsManager.getEffectiveTagsWithBuilds(availableBuilds);
        for (BuildTagBean buildTagBean : buildTagBeanList) {
            if (buildTagBean.getTag() != null && buildTagBean.getTag().getValue() == TagValue.BAD_BUILD) {
                // bad build,  do not include
                LOG.info("Env {} Build {} is tagged as BAD_BUILD, ignore", envBean.getEnv_id(),
                        buildTagBean.getBuild());
            } else {
                taggedGoodBuilds.add(buildTagBean.getBuild());
            }
        }
    }
    // should order build bean ORDER BY publish_date DESC
    if (taggedGoodBuilds.size() > 0) {
        Collections.sort(taggedGoodBuilds, new Comparator<BuildBean>() {
            @Override
            public int compare(final BuildBean d1, final BuildBean d2) {
                return Long.compare(d2.getPublish_date(), d1.getPublish_date());
            }
        });
        LOG.info("Env {} the first build candidate is {}", envBean.getEnv_id(),
                taggedGoodBuilds.get(0).getBuild_id());
    }
    return taggedGoodBuilds;
}