Example usage for org.apache.commons.lang.time DateUtils addSeconds

List of usage examples for org.apache.commons.lang.time DateUtils addSeconds

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateUtils addSeconds.

Prototype

public static Date addSeconds(Date date, int amount) 

Source Link

Document

Adds a number of seconds to a date returning a new object.

Usage

From source file:com.dp2345.dao.impl.CartDaoImpl.java

public void evictExpired() {
    String jpql = "delete from Cart cart where cart.modifyDate <= :expire";
    entityManager.createQuery(jpql).setFlushMode(FlushModeType.COMMIT)
            .setParameter("expire", DateUtils.addSeconds(new Date(), -Cart.TIMEOUT)).executeUpdate();
}

From source file:ch.ksfx.util.calc.AssetPriceSparser.java

public static List<Observation> sparseAssetPriceWithoutAveragingObservation(List<Observation> assetPrices,
        Integer sparsingSeconds) {
    Collections.sort(assetPrices, new ObservationDateComparator());

    Integer currentIndex = 0;//w ww.  j  a  va  2  s  .  co  m
    List<Observation> sparsedPrices = new ArrayList<Observation>();

    for (Observation ap : assetPrices) {
        if (sparsedPrices.isEmpty()) {
            sparsedPrices.add(ap);
        }

        if (DateUtils.addSeconds(sparsedPrices.get(currentIndex).getObservationTime(), sparsingSeconds)
                .before(ap.getObservationTime())) {
            sparsedPrices.add(ap);
            currentIndex++;
        }
    }

    return sparsedPrices;
}

From source file:com.doculibre.constellio.wicket.components.form.LoggingTextArea.java

public LoggingTextArea(String id, final LineProvider lineProvider, long refreshDelayMillis) {
    super(id);// ww w  . j  ava  2s.  c  o m
    setModel(new LoadableDetachableModel() {
        @Override
        protected Object load() {
            List<String> potentialNewLines;
            if (lastLoggingDate == null) {
                potentialNewLines = lineProvider.getFirstLines();
                lastLoggingDate = new Date();
            } else {
                potentialNewLines = lineProvider.getLatestLines(DateUtils.addSeconds(lastLoggingDate, -30));
            }

            // Remove unnecessary lines to avoid a slllloooooowwww memory leak! ;)
            int maxRows = 100;
            while (!loggedLines.isEmpty() && loggedLines.size() > maxRows) {
                // Remove oldest
                loggedLines.remove(0);
            }

            int firstLineToAdd = 0;
            for (String potentialNewLine : potentialNewLines) {
                if (!loggedLines.contains(potentialNewLine)) {
                    break;
                } else {
                    firstLineToAdd++;
                }
            }

            if (firstLineToAdd < potentialNewLines.size()) {
                loggedLines.addAll(potentialNewLines.subList(firstLineToAdd, potentialNewLines.size()));
            }

            StringBuffer sb = new StringBuffer();
            for (String loggedLine : loggedLines) {
                sb.insert(0, loggedLine + "\n");
            }

            if (!potentialNewLines.isEmpty()) {
                lastLoggingDate = new Date();
            }
            return sb.toString();
        }
    });
    initComponents(refreshDelayMillis);
}

From source file:io.github.GoldenDeveloper79.TheBasics.Commands.MuteCMD.java

public void performCommand(final Player player, final String[] args) {
    PlayerData data = BasicUtils.getData(Bukkit.getPlayer(args[0]));

    if (!data.isMuted()) {
        String reason = BasicUtils.getMessage("MuteDefault").replace("%p", player.getName());

        if (args.length > 2) {
            reason = BasicUtils.combineString(3, args);
        }//from  w w w . j a  v a  2s .  co m

        int seconds = getTimeInSeconds(args[1]);

        if (seconds != 0) {
            Date time = DateUtils.addSeconds(new Date(), seconds);
            data.setMuted(time, reason);

            BasicUtils.notify("TheBasics.Mute.Notify", BasicUtils.getMessage("MuteNofiy")
                    .replace("%p", player.getName()).replace("%p2", args[0]).replace("%r", reason));
            BasicUtils.sendMessage(player, BasicUtils.getMessage("MuteSender").replace("%p", args[0]));
            BasicUtils.sendMessage(data.getPlayer(), BasicUtils.getMessage("MuteReceiver")
                    .replace("%p", player.getName()).replace("%r", reason));
        } else {
            BasicUtils.sendMessage(player, BasicUtils.getMessage("MuteInvalidTime"));
        }
    } else {
        BasicUtils.sendMessage(player, BasicUtils.getMessage("MuteAlready"));
    }
}

From source file:ch.ksfx.util.calc.MovingAverageCalculator.java

public static Double calculateMovingAverageForSecondsBackObservation(List<Observation> prices,
        Integer secondsBackFromNow, boolean askPrice) {
    List<Observation> aps = new ArrayList<Observation>(prices);

    Collections.sort(aps, new ObservationDateComparator());
    Collections.reverse(aps);/*from ww w.ja v  a 2  s.c o m*/

    Date referenceDate = DateUtils.addSeconds(aps.get(0).getObservationTime(), (secondsBackFromNow * -1));

    if (prices.get(0).getObservationTime().after(referenceDate)) {
        return null;
    }

    List<Observation> relevantPrices = new ArrayList<Observation>();

    for (Integer iI = 0; iI < aps.size(); iI++) {
        if (aps.get(iI).getObservationTime().after(referenceDate)) {
            relevantPrices.add(aps.get(iI));
        } else {
            break;
        }
    }

    if (askPrice) {
        Double cal = 0.0;

        for (Observation ap : relevantPrices) {
            cal = cal + Double.parseDouble(ap.getScalarValue());
        }

        return cal / relevantPrices.size();
    } else {
        Double cal = 0.0;

        for (Observation ap : relevantPrices) {
            cal = cal + Double.parseDouble(ap.getScalarValue());
        }

        return cal / relevantPrices.size();
    }
}

From source file:com.exxonmobile.ace.hybris.test.services.AccountManagerApproveScheduleService.java

public OrderScheduleCronJobModel scheduleAccountManagerJobToApproveReject(final String orderCode,
        final String customerUid) {
    LOG.debug("Scheduling a job to approve or reject action for order " + orderCode);

    final B2BCustomerModel user = userService.getUserForUID(customerUid.toLowerCase(), B2BCustomerModel.class);
    final OrderModel orderModel = customerAccountService.getOrderForCode(user, orderCode,
            getCurrentBaseStore(user));//from  w w w .j  av a  2s. c  o m

    final OrderScheduleCronJobModel orderScheduleCronJobModel = getModelService()
            .create(OrderScheduleCronJobModel.class);
    orderScheduleCronJobModel.setOrder(orderModel);
    orderScheduleCronJobModel.setJob(getCronJobService().getJob(getAccountManagerTestDataJobId()));

    final TriggerModel triggerModel = getModelService().create(TriggerModel.class);
    triggerModel.setSecond(null);
    triggerModel.setMinute(null);
    triggerModel.setHour(null);
    triggerModel.setDay(null);
    triggerModel.setMonth(null);
    triggerModel.setYear(null);
    triggerModel.setDaysOfWeek(null);

    triggerModel.setActivationTime(DateUtils.addSeconds(new Date(), 30));
    triggerModel.setActive(Boolean.TRUE);
    triggerModel.setCronJob(orderScheduleCronJobModel);

    getModelService().save(triggerModel);
    orderScheduleCronJobModel.setTriggers(Collections.singletonList(triggerModel));

    this.getModelService().save(orderScheduleCronJobModel);
    LOG.debug("Created job " + orderScheduleCronJobModel.getCode());
    return orderScheduleCronJobModel;
}

From source file:io.github.GoldenDeveloper79.TheBasics.Commands.MuteCMD.java

public void performCommand(final ConsoleCommandSender console, final String[] args) {
    PlayerData data = BasicUtils.getData(Bukkit.getPlayer(args[0]));

    if (!data.isMuted()) {
        String reason = BasicUtils.getMessage("MuteDefault").replace("%p", console.getName());

        if (args.length > 2) {
            reason = BasicUtils.combineString(2, args);
        }//from  w ww.j av a  2 s.c o  m

        int seconds = getTimeInSeconds(args[1]);

        if (seconds != 0) {
            Date time = DateUtils.addSeconds(new Date(), seconds);
            data.setMuted(time, reason);

            BasicUtils.notify("TheBasics.Mute.Notify", BasicUtils.getMessage("MuteNotify")
                    .replace("%p", console.getName()).replace("%s", args[0]).replace("%r", reason));
            BasicUtils.sendMessage(console, BasicUtils.getMessage("MuteSender").replace("%p", args[0]));
            BasicUtils.sendMessage(data.getPlayer(), BasicUtils.getMessage("MuteReceiver")
                    .replace("%p", console.getName()).replace("%r", reason));
        } else {
            BasicUtils.sendMessage(console, BasicUtils.getMessage("MuteInvalidTime"));
        }
    } else {
        BasicUtils.sendMessage(console, BasicUtils.getMessage("MuteAlready"));
    }
}

From source file:ch.ksfx.web.services.chart.ObservationChartGenerator.java

public List<TimePeriodValues> getBollingerBandsForTicksBack(TimeSeries asset, Date startDate, Date endDate,
        Integer ticksBack, Integer bollingerK) {
    List<TimePeriodValues> bollingerBands = new ArrayList<TimePeriodValues>();

    List<Observation> assetPrices = observationDAO.queryObservationsSparse(asset.getId().intValue(), startDate,
            endDate);//w  w  w. j  av a 2  s .  com

    //Get some earlier prices to calc simple moving average
    List<Observation> movingAveragePrices = observationDAO.queryObservationsSparse(asset.getId().intValue(),
            (startDate.getTime() == 0l) ? startDate : DateUtils.addSeconds(startDate, ticksBack * -1), endDate);

    assetPrices = simplifyAssetPrices(assetPrices);

    TimePeriodValues middleBand = new TimePeriodValues("SMA" + ticksBack + "Ticks " + asset.getName());

    TimePeriodValues topBand = new TimePeriodValues(
            "TicksBollinger Top K" + bollingerK + " " + asset.getName());
    TimePeriodValues bottomBand = new TimePeriodValues(
            "TicksBollinger Bottom K" + bollingerK + " " + asset.getName());

    List<Observation> relevantMovingAveragePrices = null;
    Double movingAverage = null;
    Double standardDeviation = null;

    Integer filterSizer = 0;

    for (Observation ap : assetPrices) {

        if ((movingAveragePrices.indexOf(ap) - ticksBack) < 0) {
            continue;
        }

        relevantMovingAveragePrices = movingAveragePrices.subList(movingAveragePrices.indexOf(ap) - ticksBack,
                movingAveragePrices.indexOf(ap));

        movingAverage = MovingAverageCalculator.calculateMovingAverageObservation(relevantMovingAveragePrices,
                true);

        middleBand.add(new SimpleTimePeriod(ap.getObservationTime(), ap.getObservationTime()), movingAverage);

        if (relevantMovingAveragePrices.size() > 1) {
            standardDeviation = BollingerCalculator
                    .calcStandardDeviationObservation(relevantMovingAveragePrices, true);

            topBand.add(new SimpleTimePeriod(ap.getObservationTime(), ap.getObservationTime()),
                    movingAverage + (standardDeviation * bollingerK));
            bottomBand.add(new SimpleTimePeriod(ap.getObservationTime(), ap.getObservationTime()),
                    movingAverage - (standardDeviation * bollingerK));
        }
    }

    bollingerBands.add(middleBand);

    bollingerBands.add(topBand);
    bollingerBands.add(bottomBand);

    return bollingerBands;
}

From source file:com.dp2345.controller.admin.OrderController.java

/**
 * ?/*from   w  w w  . ja  v a 2  s .co  m*/
 */
@RequestMapping(value = "/check_lock", method = RequestMethod.POST)
public @ResponseBody Message checkLock(Long id) {
    Order order = orderService.find(id);
    if (order == null) {
        return Message.warn("admin.common.invalid");
    }
    Admin admin = adminService.getCurrent();
    if (order.isLocked(admin)) {
        if (order.getOperator() != null) {
            return Message.warn("admin.order.adminLocked", order.getOperator().getUsername());
        } else {
            return Message.warn("admin.order.memberLocked");
        }
    } else {
        order.setLockExpire(DateUtils.addSeconds(new Date(), 20));
        order.setOperator(admin);
        orderService.update(order);
        return SUCCESS_MESSAGE;
    }
}

From source file:com.silverpeas.gallery.model.InternalMediaTest.java

@Test
public void isDownloadable() {
    Date dateOfDay = DateUtil.getDate();
    InternalMedia iMedia = defaultInternalMedia();

    assertThat(iMedia.isDownloadAuthorized(), is(true));
    assertThat(iMedia.isVisible(dateOfDay), is(true));
    assertThat(iMedia.getDownloadPeriod().getBeginDatable(), comparesEqualTo(beginDownloadDate));
    assertThat(iMedia.getDownloadPeriod().getEndDatable(), comparesEqualTo(endDownloadDate));
    assertThat(iMedia.isDownloadable(), is(true));

    iMedia.setDownloadAuthorized(false);

    assertThat(iMedia.isDownloadAuthorized(), is(false));
    assertThat(iMedia.isVisible(dateOfDay), is(true));
    assertThat(iMedia.getDownloadPeriod().getBeginDatable(), comparesEqualTo(beginDownloadDate));
    assertThat(iMedia.getDownloadPeriod().getEndDatable(), comparesEqualTo(endDownloadDate));
    assertThat(iMedia.isDownloadable(), is(false));

    iMedia.setDownloadAuthorized(true);/*from   w w w.ja va2  s  .  c om*/
    iMedia.setVisibilityPeriod(Period.from(beginDownloadDate, beginDownloadDate));

    assertThat(iMedia.isDownloadAuthorized(), is(true));
    assertThat(iMedia.isVisible(dateOfDay), is(false));
    assertThat(iMedia.getDownloadPeriod().getBeginDatable(), comparesEqualTo(beginDownloadDate));
    assertThat(iMedia.getDownloadPeriod().getEndDatable(), comparesEqualTo(endDownloadDate));
    assertThat(iMedia.isDownloadable(), is(false));

    iMedia.setVisibilityPeriod(Period.UNDEFINED);

    assertThat(iMedia.isDownloadAuthorized(), is(true));
    assertThat(iMedia.isVisible(dateOfDay), is(true));
    assertThat(iMedia.getDownloadPeriod().getBeginDatable(), comparesEqualTo(beginDownloadDate));
    assertThat(iMedia.getDownloadPeriod().getEndDatable(), comparesEqualTo(endDownloadDate));
    assertThat(iMedia.isDownloadable(), is(true));

    dateOfDay = DateUtils.addSeconds(DateUtil.getDate(), 1);
    iMedia.setDownloadPeriod(Period.from(beginDownloadDate, dateOfDay));

    assertThat(iMedia.isDownloadAuthorized(), is(true));
    assertThat(iMedia.isVisible(dateOfDay), is(true));
    assertThat(iMedia.getDownloadPeriod().getBeginDatable(), comparesEqualTo(beginDownloadDate));
    assertThat(iMedia.getDownloadPeriod().getEndDatable(), comparesEqualTo(dateOfDay));
    assertThat(iMedia.isDownloadable(), is(true));

    dateOfDay = DateUtils.addSeconds(DateUtil.getDate(), -1);
    iMedia.setDownloadPeriod(Period.from(beginDownloadDate, dateOfDay));

    assertThat(iMedia.isDownloadAuthorized(), is(true));
    assertThat(iMedia.isVisible(dateOfDay), is(true));
    assertThat(iMedia.getDownloadPeriod().getBeginDatable(), comparesEqualTo(beginDownloadDate));
    assertThat(iMedia.getDownloadPeriod().getEndDatable(), comparesEqualTo(dateOfDay));
    assertThat(iMedia.isDownloadable(), is(false));

    dateOfDay = DateUtils.addSeconds(DateUtil.getDate(), -1);
    iMedia.setDownloadPeriod(Period.from(dateOfDay, endDownloadDate));

    assertThat(iMedia.isDownloadAuthorized(), is(true));
    assertThat(iMedia.isVisible(dateOfDay), is(true));
    assertThat(iMedia.getDownloadPeriod().getBeginDatable(), comparesEqualTo(dateOfDay));
    assertThat(iMedia.getDownloadPeriod().getEndDatable(), comparesEqualTo(endDownloadDate));
    assertThat(iMedia.isDownloadable(), is(true));

    dateOfDay = DateUtils.addSeconds(DateUtil.getDate(), 1);
    iMedia.setDownloadPeriod(Period.from(dateOfDay, endDownloadDate));

    assertThat(iMedia.isDownloadAuthorized(), is(true));
    assertThat(iMedia.isVisible(dateOfDay), is(true));
    assertThat(iMedia.getDownloadPeriod().getBeginDatable(), comparesEqualTo(dateOfDay));
    assertThat(iMedia.getDownloadPeriod().getEndDatable(), comparesEqualTo(endDownloadDate));
    assertThat(iMedia.isDownloadable(), is(false));
}