Example usage for java.util Date setTime

List of usage examples for java.util Date setTime

Introduction

In this page you can find the example usage for java.util Date setTime.

Prototype

public void setTime(long time) 

Source Link

Document

Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.

Usage

From source file:eu.stratosphere.runtime.io.network.netty.NettyConnectionManager.java

public NettyConnectionManager(ChannelManager channelManager, InetAddress bindAddress, int bindPort,
        int bufferSize, int numInThreads, int numOutThreads, int lowWaterMark, int highWaterMark) {
    this.outConnections = new ConcurrentHashMap<RemoteReceiver, Object>();
    this.channelManager = channelManager;

    // --------------------------------------------------------------------

    int defaultNumThreads = Math.max(Runtime.getRuntime().availableProcessors() / 4, 1);
    numInThreads = (numInThreads == -1) ? defaultNumThreads : numInThreads;
    numOutThreads = (numOutThreads == -1) ? defaultNumThreads : numOutThreads;
    LOG.info(String.format("Starting with %d incoming and %d outgoing connection threads.", numInThreads,
            numOutThreads));/*from   ww  w  .  ja  va  2s  .  c  om*/

    lowWaterMark = (lowWaterMark == -1) ? bufferSize / 2 : lowWaterMark;
    highWaterMark = (highWaterMark == -1) ? bufferSize : highWaterMark;
    LOG.info(String.format("Setting low water mark to %d and high water mark to %d bytes.", lowWaterMark,
            highWaterMark));

    // --------------------------------------------------------------------
    // server bootstrap (incoming connections)
    // --------------------------------------------------------------------
    this.in = new ServerBootstrap();
    this.in.group(new NioEventLoopGroup(numInThreads)).channel(NioServerSocketChannel.class)
            .localAddress(bindAddress, bindPort).childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel channel) throws Exception {
                    channel.pipeline()
                            .addLast(new InboundEnvelopeDecoder(NettyConnectionManager.this.channelManager))
                            .addLast(new InboundEnvelopeDispatcherHandler(
                                    NettyConnectionManager.this.channelManager));
                }
            }).option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(bufferSize))
            .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

    // --------------------------------------------------------------------
    // client bootstrap (outgoing connections)
    // --------------------------------------------------------------------
    this.out = new Bootstrap();
    this.out.group(new NioEventLoopGroup(numOutThreads)).channel(NioSocketChannel.class)
            .handler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel channel) throws Exception {
                    channel.pipeline().addLast(new OutboundEnvelopeEncoder());
                }
            }).option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, lowWaterMark)
            .option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, highWaterMark)
            .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
            .option(ChannelOption.TCP_NODELAY, false).option(ChannelOption.SO_KEEPALIVE, true);

    try {
        this.in.bind().sync();
    } catch (InterruptedException e) {
        throw new RuntimeException("Could not bind server socket for incoming connections.");
    }

    if (LOG.isDebugEnabled()) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                Date date = new Date();

                while (true) {
                    try {
                        Thread.sleep(DEBUG_PRINT_QUEUED_ENVELOPES_EVERY_MS);

                        date.setTime(System.currentTimeMillis());
                        System.out.println(date);

                        System.out.println(getNonZeroNumQueuedEnvelopes());

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }
}

From source file:UserInterface.TMAnalystRole.TMAnaylstWorkAreaJPanel.java

private void btnSimulateDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSimulateDataActionPerformed
    // TODO add your handling code here:
    int days = (int) spnrDays.getValue();

    objSimulation = new SimulationClass();
    Date today = new Date();
    Date olderThanToday = new Date();
    olderThanToday.setTime(today.getTime() + (long) (-days) * 1000 * 60 * 60 * 24);

    for (Train t : enterprise.getTrainCatalog().getTrainsList()) {
        if (t.getLineOnTrain().isIsActive() && t.getLineOnTrain().isHasStarted()) {
            for (int i = 1; i <= days; i++) {
                Date thistoday = new Date();
                thistoday.setTime(olderThanToday.getTime());
                TrainOffered selectedTrainOffered = enterprise.getTrainsOfferedHistory().fetchOrAddTrain(t,
                        thistoday);/*from   w w  w .  j a v a2s .co m*/

                objSimulation.generatePreviousCrowdedData(selectedTrainOffered);

                olderThanToday.setTime(olderThanToday.getTime() + (long) (1) * 1000 * 60 * 60 * 24);
            }
            olderThanToday.setTime(today.getTime() + (long) (-days) * 1000 * 60 * 60 * 24);
        }
    }

    JOptionPane.showMessageDialog(this, "Data generated successfully.", "Simulation",
            JOptionPane.INFORMATION_MESSAGE);
    spnrDays.setValue(1);
}

From source file:jef.tools.DateUtils.java

/**
 * /* w w  w. j a va 2  s .  co  m*/
 */
public static void addYear(Date d, int value) {
    Calendar c = Calendar.getInstance();
    c.setTime(d);
    c.add(Calendar.YEAR, value);
    d.setTime(c.getTime().getTime());
}

From source file:jef.tools.DateUtils.java

/**
 * //from w ww. ja v a2  s .c  o  m
 */
public static void addMonth(Date d, int value) {
    Calendar c = Calendar.getInstance();
    c.setTime(d);
    c.add(Calendar.MONTH, value);
    d.setTime(c.getTime().getTime());
}

From source file:tools.xor.logic.DefaultQueryInheritanceCustom.java

public void limitPatents() {
    setupMetaEntityStateVO(aggregateService);
    setupMetaEntityTypeVO(aggregateService);

    Date today = new Date();
    Date TwodaysAgo = new Date();
    Date FifteendaysAgo = new Date();
    TwodaysAgo.setTime(today.getTime() - 2 * 1000 * 60 * 60 * 24);
    FifteendaysAgo.setTime(today.getTime() - 15 * 1000 * 60 * 60 * 24);

    // Create first patent
    Patent patent1 = new Patent();
    patent1.setName("PATENT1");
    patent1.setDisplayName("Defects");
    patent1.setDescription("User story to address product defects");
    patent1.setState(getState(MetaEntityStateEnum.RETIRED.name()));
    patent1.setMetaEntityType(getType(MetaEntityTypeEnum.PATENT.name()));
    patent1.setCreatedOn(FifteendaysAgo);
    patent1 = (Patent) aggregateService.create(patent1, new Settings());

    // Create second patent
    Patent patent2 = new Patent();
    patent2.setName("PATENT2");
    patent2.setDisplayName("Enhancements");
    patent2.setDescription("User story to address product enhancements");
    patent2.setState(getState(MetaEntityStateEnum.ACTIVE.name()));
    patent2.setMetaEntityType(getType(MetaEntityTypeEnum.PATENT.name()));
    patent2.setCreatedOn(TwodaysAgo);/*w  ww.jav  a 2  s.c om*/
    patent2 = (Patent) aggregateService.create(patent2, new Settings());

    Patent patent3 = new Patent();
    patent3.setName("PATENT3");
    patent3.setDisplayName("Use cases");
    patent3.setDescription("User story to address use cases");
    patent3.setState(getState(MetaEntityStateEnum.ACTIVE.name()));
    patent3.setMetaEntityType(getType(MetaEntityTypeEnum.PATENT.name()));
    patent3.setCreatedOn(today);
    patent3 = (Patent) aggregateService.create(patent3, new Settings());

    // query the task object
    Settings settings = new Settings();
    settings.addFunctionFilter("asc(name)", 1);

    settings.setView(aggregateService.getView("ARTIFACTINFO"));
    MetaEntityVO input = new MetaEntityVO();
    MetaEntityTypeVO typeVO = new MetaEntityTypeVO();
    typeVO.setName(MetaEntityTypeEnum.PATENT.name());
    input.setMetaEntityType(typeVO);
    List<?> toList = aggregateService.query(input, settings);

    assert (toList.size() == 3);

    settings = new Settings();
    settings.addFunctionFilter("asc(name)", 1);
    settings.setView(aggregateService.getView("ARTIFACTINFO"));
    settings.setLimit(2);
    toList = aggregateService.query(input, settings);

    assert (toList.size() == 2);
}

From source file:be.fedict.eid.pkira.blm.model.contracthandler.ContractHandlerBean.java

protected void scheduleNotificationMail(Registration registration, CertificateInfo certificateInfo,
        Certificate certificate) {
    String notificationMailMinutes = configurationEntryQuery
            .findByEntryKey(ConfigurationEntryKey.NOTIFICATION_MAIL_MINUTES).getValue();
    for (String notificationMailMinute : notificationMailMinutes.split("\\s*,\\s*")) {
        Long intervalParam = Long.valueOf(notificationMailMinute);

        Date when;
        if (intervalParam > 0) {
            when = certificateInfo.getValidityEnd();
            when.setTime(when.getTime() - intervalParam * 1000 * 60);
        } else {//from w ww .  jav  a2  s  . co m
            when = new Date();
            when.setTime(when.getTime() - intervalParam * 1000 * 60);
        }
        QuartzTriggerHandle timer = schedulerBean.scheduleNotifcation(when, certificate.getIssuer(),
                certificate.getSerialNumber());
        certificate.addTimer(timer);
    }
}

From source file:tools.xor.logic.DefaultQueryInheritanceCustom.java

public void listPatentsBetweenDate() {
    setupMetaEntityStateVO(aggregateService);
    setupMetaEntityTypeVO(aggregateService);

    Date today = new Date();
    Date TwodaysAgo = new Date();
    Date FifteendaysAgo = new Date();
    TwodaysAgo.setTime(today.getTime() - 2 * 1000 * 60 * 60 * 24);
    FifteendaysAgo.setTime(today.getTime() - 15 * 1000 * 60 * 60 * 24);

    // Create first patent
    Patent patent1 = new Patent();
    patent1.setName("PATENT1");
    patent1.setDisplayName("Defects");
    patent1.setDescription("User story to address product defects");
    patent1.setState(getState(MetaEntityStateEnum.RETIRED.name()));
    patent1.setMetaEntityType(getType(MetaEntityTypeEnum.PATENT.name()));
    patent1.setCreatedOn(FifteendaysAgo);
    patent1 = (Patent) aggregateService.create(patent1, new Settings());

    // Create second patent
    Patent patent2 = new Patent();
    patent2.setName("PATENT2");
    patent2.setDisplayName("Enhancements");
    patent2.setDescription("User story to address product enhancements");
    patent2.setState(getState(MetaEntityStateEnum.ACTIVE.name()));
    patent2.setMetaEntityType(getType(MetaEntityTypeEnum.PATENT.name()));
    patent2.setCreatedOn(TwodaysAgo);//from ww w.  j a v  a 2s  .c  om
    patent2 = (Patent) aggregateService.create(patent2, new Settings());

    Patent patent3 = new Patent();
    patent3.setName("PATENT3");
    patent3.setDisplayName("Use cases");
    patent3.setDescription("User story to address use cases");
    patent3.setState(getState(MetaEntityStateEnum.ACTIVE.name()));
    patent3.setMetaEntityType(getType(MetaEntityTypeEnum.TASK.name()));
    patent3.setCreatedOn(today);
    patent3 = (Patent) aggregateService.create(patent3, new Settings());

    // query the task object
    Settings settings = new Settings();
    settings.addFunctionFilter("ilike(name, :name)");
    settings.addFunctionFilter("in(state.name, :state)");
    settings.addFunctionFilter("equal(ownedBy.name, :owner)");
    settings.addFunctionFilter("between(createdOn, :createdFrom, :createdTo)");
    settings.addFunctionFilter("asc(name)", 1);

    // Filter by date
    Date yesterday = new Date();
    yesterday.setTime(today.getTime() - 1 * 1000 * 60 * 60 * 24);
    Date fiveDaysAgo = new Date();
    fiveDaysAgo.setTime(today.getTime() - 5 * 1000 * 60 * 60 * 24);
    settings.addFilter("createdFrom", fiveDaysAgo);
    settings.addFilter("createdTo", yesterday);

    settings.setView(aggregateService.getView("ARTIFACTINFO"));
    MetaEntityVO input = new MetaEntityVO();
    MetaEntityTypeVO typeVO = new MetaEntityTypeVO();
    typeVO.setName(MetaEntityTypeEnum.PATENT.name());
    input.setMetaEntityType(typeVO);
    List<?> toList = aggregateService.query(input, settings);

    assert (toList.size() == 1);

    Object obj = toList.get(0);
    assert (PatentVO.class.isAssignableFrom(obj.getClass()));

    PatentVO a1 = (PatentVO) obj;
    assert (a1.getName().equals("PATENT2"));
}

From source file:UserInterface.TMAnalystRole.TMAnaylstWorkAreaJPanel.java

private void btnRouteAnalysisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRouteAnalysisActionPerformed
    // TODO add your handling code here:
    Line selectedLine = (Line) cboActiveLines.getSelectedItem();
    ArrayList<Route> routeList = new ArrayList<>();

    for (Segment s : selectedLine.getSegments()) {
        routeList.add(s.getRoutes().get(0));
    }//from  ww w. j a v a2 s .c o m

    ArrayList<Segment> segmentList = selectedLine.getSegments();
    for (int i = segmentList.size() - 1; i >= 0; i--) {
        routeList.add(segmentList.get(i).getRoutes().get(1));
    }

    int days = (int) spnrRecord.getValue();
    Date today = new Date();
    Date olderThanToday = new Date();
    olderThanToday.setTime(today.getTime() + (long) (-days) * 1000 * 60 * 60 * 24);
    long todayDate = (today.getTime()) / (1000 * 60 * 60 * 24);
    long olderDate = (olderThanToday.getTime()) / (1000 * 60 * 60 * 24);

    Map<Route, Integer> routesWithCapacityList = new LinkedHashMap<>();

    for (Route r : routeList) {
        int routeCount = 0;

        for (TimeSlot.TimeSlotRange ts : TimeSlot.TimeSlotRange.values()) {
            Train selectedTrain = r.fetchRouteSchedule(ts).getTrainOffered();
            int intermediateCount = 0;
            int trainsFound = 0;
            for (TrainOffered selectedTrainOffered : enterprise.getTrainsOfferedHistory().getTrainsOffered()) {
                if (selectedTrainOffered.getTrain().equals(selectedTrain)) {
                    long selectedDate = (selectedTrainOffered.getDayOffered().getTime())
                            / (1000 * 60 * 60 * 24);
                    if (selectedDate >= olderDate && selectedDate <= todayDate) {
                        intermediateCount += selectedTrainOffered.fetchRunningTrainByTimeSlot(ts)
                                .getRunningCapacity();
                        trainsFound++;
                    }
                }

            }
            if (trainsFound != 0) {
                intermediateCount = intermediateCount / trainsFound;
                routeCount += intermediateCount;
            }
        }
        routeCount = Math.round(routeCount / 15);
        routesWithCapacityList.putIfAbsent(r, routeCount);
    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (Map.Entry<Route, Integer> entry : routesWithCapacityList.entrySet()) {
        dataset.setValue(entry.getValue(), "Routes", entry.getKey().getRouteName());

    }

    JFreeChart chart = ChartFactory.createBarChart(
            "Congestion Levels of Line : " + selectedLine.getLineName() + " for " + days + " days", "Routes",
            "Average Congestion Levels", dataset, PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeGridlinePaint(Color.BLUE);
    ChartFrame frame = new ChartFrame("Bar Chart for Congestion Analysis", chart);
    frame.setVisible(true);
    frame.setSize(this.getWidth(), this.getHeight() + 200);

}

From source file:org.collectionspace.chain.csp.webui.userdetails.UserDetailsReset.java

private long daysBetween(Date startDate, Date endDate) throws UIException {

    long daysBetween = 0;
    while (startDate.before(endDate)) {
        startDate.setTime(startDate.getTime() + (24 * 60 * 60 * 1000));
        daysBetween++;//from  www  .  ja v  a2s.  c  o  m
    }
    return daysBetween;
}

From source file:org.alfresco.module.vti.web.ws.AbstractMeetingFromICalEndpoint.java

/**
 * Get last date of recurrence meeting for weekly recurrence meeting
 * /*w  ww  .ja v  a2 s  .  c o m*/
 * @param meetingFirstDay first date of meeting
 * @param eventParam event parameters from meeting RRULE
 * @param eventOccurrs count of meetings
 * @param interval interval between meetings
 * @return last date of recurrence meeting
 */
private Date getLastMeetingWeekly(Date meetingFirstDay, Map<String, String> eventParam, long eventOccurrs,
        long interval) {
    String[] ruleDays = eventParam.get("BYDAY").split(",");

    long fullWeeks = eventOccurrs / ruleDays.length;
    int occurrsToAdd = new Long(eventOccurrs % ruleDays.length).intValue() - 1;
    Date lastMeeting = new Date();

    lastMeeting.setTime(meetingFirstDay.getTime() + fullWeeks * 7 * DAY * interval);

    if (occurrsToAdd == -1) {
        lastMeeting.setTime(lastMeeting.getTime() - 7 * DAY * interval);
        occurrsToAdd += ruleDays.length;
    }
    if (occurrsToAdd > 0) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(lastMeeting);
        long eventStartDayOfWeek = cal.get(Calendar.DAY_OF_WEEK) - 1;

        long eventLastDay = eventStartDayOfWeek;

        // Add days that are after rule start day.
        for (int i = 0; i < ruleDays.length; i++) {
            if (occurrsToAdd > 0) {
                long dayFromRule = daysMap.get(ruleDays[i]);

                if (dayFromRule > eventLastDay) {
                    long dayOffset = dayFromRule - eventLastDay;
                    lastMeeting.setTime(lastMeeting.getTime() + dayOffset * DAY);
                    eventLastDay = dayFromRule;
                    occurrsToAdd--;
                }
            } else {
                break;
            }
        }

        if (occurrsToAdd > 0) {
            lastMeeting.setTime(lastMeeting.getTime() + 7 * DAY * interval);

            cal.setTime(lastMeeting);
            cal.set(Calendar.DAY_OF_WEEK, 2);
            cal.getTime();
            cal.add(Calendar.DAY_OF_YEAR, -1);
            lastMeeting.setTime(cal.getTimeInMillis());

            // Find the first day before rule start day.
            long dayOffset = 0;
            for (int i = 0; i < ruleDays.length; i++) {
                if (occurrsToAdd > 0) {
                    long dayFromRule = daysMap.get(ruleDays[i]);

                    if (dayFromRule < eventStartDayOfWeek) {
                        // we doesn't include Monday because we've already include it.
                        if (dayFromRule > daysMap.get("SU")) {
                            dayOffset = dayFromRule;
                        }
                        occurrsToAdd--;
                    } else if (dayFromRule == eventStartDayOfWeek) {
                        occurrsToAdd--;
                    }
                } else {
                    break;
                }
            }
            lastMeeting.setTime(lastMeeting.getTime() + DAY * dayOffset);
        }
    }
    return lastMeeting;
}