Example usage for java.util GregorianCalendar getTime

List of usage examples for java.util GregorianCalendar getTime

Introduction

In this page you can find the example usage for java.util GregorianCalendar getTime.

Prototype

public final Date getTime() 

Source Link

Document

Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").

Usage

From source file:org.miloss.fgsms.services.rs.impl.reports.os.ThreadCount.java

@Override
public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files,
        TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx)
        throws IOException {

    Connection con = Utility.getPerformanceDBConnection();
    try {/*from w w  w  .  ja  v a 2s. c o m*/
        PreparedStatement cmd = null;
        ResultSet rs = null;
        JFreeChart chart = null;

        data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>");
        data.append(GetHtmlFormattedHelp() + "<br />");
        data.append("<table class=\"table table-hover\"><tr><th>URI</th><th>Average Thread Count</th></tr>");

        TimeSeriesCollection col = new TimeSeriesCollection();
        for (int i = 0; i < urls.size(); i++) {
            if (!isPolicyTypeOf(urls.get(i), PolicyType.MACHINE)
                    && !isPolicyTypeOf(urls.get(i), PolicyType.PROCESS)) {
                continue;
            }
            //https://github.com/mil-oss/fgsms/issues/112
            if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) {
                continue;
            }
            String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i)));
            data.append("<tr><td>").append(url).append("</td>");
            double average = 0;
            try {

                cmd = con.prepareStatement(
                        "select avg(threads) from rawdatamachineprocess where uri=? and utcdatetime > ? and utcdatetime < ?;");
                cmd.setString(1, urls.get(i));
                cmd.setLong(2, range.getStart().getTimeInMillis());
                cmd.setLong(3, range.getEnd().getTimeInMillis());
                rs = cmd.executeQuery();
                if (rs.next()) {
                    average = rs.getDouble(1);
                }
            } catch (Exception ex) {
                log.log(Level.WARN, null, ex);
            } finally {
                DBUtils.safeClose(rs);
                DBUtils.safeClose(cmd);
            }

            data.append("<td>").append(average + "").append("</td></tr>");
            TimeSeries ts = new TimeSeries(urls.get(i), Millisecond.class);
            try {
                //ok now get the raw data....
                cmd = con.prepareStatement(
                        "select threads,utcdatetime from rawdatamachineprocess where uri=? and utcdatetime > ? and utcdatetime < ?;");
                cmd.setString(1, urls.get(i));
                cmd.setLong(2, range.getStart().getTimeInMillis());
                cmd.setLong(3, range.getEnd().getTimeInMillis());
                rs = cmd.executeQuery();

                while (rs.next()) {
                    GregorianCalendar gcal = new GregorianCalendar();
                    gcal.setTimeInMillis(rs.getLong(2));
                    Millisecond m = new Millisecond(gcal.getTime());

                    ts.addOrUpdate(m, rs.getLong(1));
                }
            } catch (Exception ex) {
                log.log(Level.WARN, null, ex);
            } finally {
                DBUtils.safeClose(rs);
                DBUtils.safeClose(cmd);
            }
            col.addSeries(ts);
        }

        data.append("</table>");
        chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "Count", col,
                true, false, false);

        try {
            //if (set.getRowCount() != 0) {
            ChartUtilities.saveChartAsPNG(new File(
                    path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart,
                    1500, 400);
            data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">");
            files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png");
            // }
        } catch (IOException ex) {
            log.log(Level.ERROR, "Error saving chart image for request", ex);
        }
    } catch (Exception ex) {
        log.log(Level.ERROR, null, ex);
    } finally {
        DBUtils.safeClose(con);
    }
}

From source file:com.thoughtworks.go.server.util.HttpTestUtil.java

private Date day(final int offset) {
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.add(GregorianCalendar.DAY_OF_MONTH, offset);
    return gregorianCalendar.getTime();
}

From source file:org.primefaces.extensions.converter.JsonConverterTest.java

@Test
public void testComplexMap() {
    jsonConverter.setType(/*from w  w w.  j  av a 2s.co m*/
            "java.util.Map<java.lang.String, org.apache.commons.lang3.tuple.ImmutablePair<java.lang.Integer, java.util.Date>>");

    Map<String, ImmutablePair<Integer, Date>> map = new HashMap<String, ImmutablePair<Integer, Date>>();
    GregorianCalendar calendar = new GregorianCalendar(2012, 1, 20);
    map.put("cat", new ImmutablePair<Integer, Date>(1, calendar.getTime()));
    calendar = new GregorianCalendar(2011, 6, 1);
    map.put("dog", new ImmutablePair<Integer, Date>(2, calendar.getTime()));
    calendar = new GregorianCalendar(1999, 10, 15);
    map.put("unknow", new ImmutablePair<Integer, Date>(3, calendar.getTime()));

    String json = jsonConverter.getAsString(null, null, map);

    Object obj = jsonConverter.getAsObject(null, null, json);
    assertTrue(CollectionUtils.isEqualCollection(map.entrySet(),
            ((Map<String, ImmutablePair<Integer, Date>>) obj).entrySet()));
}

From source file:org.oscarehr.PMmodule.web.ManageConsent.java

public boolean displayAsSelectedExpiry(int months) {
    if (previousConsentToView == null)
        return (months == -1);
    else {//from   w  w w.j a  v  a2s  .  co  m
        if (previousConsentToView.getExpiry() == null)
            return (months == -1);
        else {
            GregorianCalendar cal1 = new GregorianCalendar();
            cal1.setTime(previousConsentToView.getCreatedDate());
            cal1.add(Calendar.MONTH, months);

            return (DateUtils.isSameDay(cal1.getTime(), previousConsentToView.getExpiry()));
        }
    }
}

From source file:org.miloss.fgsms.services.rs.impl.reports.os.OpenFilesByProcess.java

@Override
public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files,
        TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx)
        throws IOException {

    Connection con = Utility.getPerformanceDBConnection();
    try {/*  w w  w  .  j av  a2s  .  c o m*/
        PreparedStatement cmd = null;
        ResultSet rs = null;
        JFreeChart chart = null;

        data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>");
        data.append(GetHtmlFormattedHelp() + "<br />");
        data.append(
                "<table class=\"table table-hover\"><tr><th>URI</th><th>Average Open File Handles Count</th></tr>");
        TimeSeriesCollection col = new TimeSeriesCollection();
        for (int i = 0; i < urls.size(); i++) {
            if (!isPolicyTypeOf(urls.get(i), PolicyType.PROCESS)) {
                continue;
            }
            //https://github.com/mil-oss/fgsms/issues/112
            if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) {
                continue;
            }
            String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i)));
            data.append("<tr><td>").append(url).append("</td>");
            double average = 0;
            try {
                cmd = con.prepareStatement(
                        "select avg(openfiles) from rawdatamachineprocess where uri=? and utcdatetime > ? and utcdatetime < ?;");
                cmd.setString(1, urls.get(i));
                cmd.setLong(2, range.getStart().getTimeInMillis());
                cmd.setLong(3, range.getEnd().getTimeInMillis());

                rs = cmd.executeQuery();

                if (rs.next()) {
                    average = rs.getDouble(1);

                }
            } catch (Exception ex) {
                log.log(Level.WARN, null, ex);
            } finally {
                DBUtils.safeClose(rs);
                DBUtils.safeClose(cmd);
            }

            data.append("<td>").append(average + "").append("</td></tr>");
            TimeSeries ts = new TimeSeries(url, Millisecond.class);
            try {
                //ok now get the raw data....
                cmd = con.prepareStatement(
                        "select utcdatetime, openfiles from rawdatamachineprocess where uri=? and utcdatetime > ? and utcdatetime < ?;");
                cmd.setString(1, urls.get(i));
                cmd.setLong(2, range.getStart().getTimeInMillis());
                cmd.setLong(3, range.getEnd().getTimeInMillis());

                rs = cmd.executeQuery();

                while (rs.next()) {

                    GregorianCalendar gcal = new GregorianCalendar();
                    gcal.setTimeInMillis(rs.getLong(1));
                    Millisecond m = new Millisecond(gcal.getTime());
                    ts.addOrUpdate(m, rs.getLong(2));

                }
            } catch (Exception ex) {
                log.log(Level.WARN, null, ex);
            } finally {
                DBUtils.safeClose(rs);
                DBUtils.safeClose(cmd);
            }

            col.addSeries(ts);

        }

        chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "Count", col,
                true, false, false);

        data.append("</table>");
        try {
            // if (set.getRowCount() != 0) {
            ChartUtilities.saveChartAsPNG(new File(
                    path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart,
                    1500, 400);
            data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">");
            files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png");
            //}
        } catch (IOException ex) {
            log.log(Level.ERROR, "Error saving chart image for request", ex);
        }
    } catch (Exception ex) {
        log.log(Level.ERROR, null, ex);
    } finally {
        DBUtils.safeClose(con);
    }
}

From source file:org.miloss.fgsms.services.rs.impl.reports.broker.QueueDepth.java

@Override
public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files,
        TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx)
        throws IOException {

    Connection con = Utility.getPerformanceDBConnection();
    try {/* w  ww  .  jav  a  2  s  .c o m*/
        PreparedStatement cmd = null;
        ResultSet rs = null;
        DefaultCategoryDataset set = new DefaultCategoryDataset();
        JFreeChart chart = null;

        data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>");
        data.append(GetHtmlFormattedHelp() + "<br />");
        data.append("<table class=\"table table-hover\"><tr><th>URI</th><th>Channel</th><th>Depth</th></tr>");

        TimeSeriesCollection col = new TimeSeriesCollection();
        for (int i = 0; i < urls.size(); i++) {
            if (!isPolicyTypeOf(urls.get(i), PolicyType.STATISTICAL)) {
                continue;
            }
            //https://github.com/mil-oss/fgsms/issues/112
            if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) {
                continue;
            }
            String url = Utility.encodeHTML(getPolicyDisplayName(urls.get(i)));
            double average = 0;
            data.append("<tr><td>").append(url).append("</td>");
            try {
                cmd = con.prepareStatement(
                        "select avg(queuedepth), host, canonicalname from brokerhistory where host=? and utcdatetime > ? and utcdatetime < ? group by canonicalname, host;");
                cmd.setString(1, urls.get(i));
                cmd.setLong(2, range.getStart().getTimeInMillis());
                cmd.setLong(3, range.getEnd().getTimeInMillis());
                rs = cmd.executeQuery();

                if (rs.next()) {
                    average = rs.getDouble(1);
                }
            } catch (Exception ex) {
                log.log(Level.ERROR, "Error opening or querying the database.", ex);
            } finally {
                DBUtils.safeClose(rs);
                DBUtils.safeClose(cmd);
            }
            data.append("<td>").append(average + "").append("</td>");

            TimeSeries ts = new TimeSeries(url, Millisecond.class);
            try {
                //ok now get the raw data....
                cmd = con.prepareStatement(
                        "select utcdatetime,queuedepth, canonicalname from brokerhistory where host=? and utcdatetime > ? and utcdatetime < ?;");
                cmd.setString(1, urls.get(i));
                cmd.setLong(2, range.getStart().getTimeInMillis());
                cmd.setLong(3, range.getEnd().getTimeInMillis());
                rs = cmd.executeQuery();

                while (rs.next()) {

                    //set.addValue(rs.getLong(1), urls.get(i), rs.getString("canonicalname"));
                    GregorianCalendar gcal = new GregorianCalendar();
                    gcal.setTimeInMillis(rs.getLong(1));
                    Millisecond m = new Millisecond(gcal.getTime());
                    //TimeSeriesDataItem t = new TimeSeriesDataItem(m, rs.getLong(2));
                    //ts.add(t);
                    ts.addOrUpdate(m, rs.getLong(2));

                }

            } catch (Exception ex) {
                log.log(Level.ERROR, "Error opening or querying the database.", ex);
            } finally {
                DBUtils.safeClose(rs);
                DBUtils.safeClose(cmd);
            }

            col.addSeries(ts);

        }
        chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "Count", col,
                true, false, false);

        data.append("</table>");
        try {
            //  if (set.getRowCount() != 0) {
            ChartUtilities.saveChartAsPNG(new File(
                    path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart,
                    1500, 400);
            data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">");
            files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png");
            // }
        } catch (IOException ex) {
            log.log(Level.ERROR, "Error saving chart image for request", ex);
        }
    } catch (Exception ex) {
        log.log(Level.ERROR, null, ex);
    } finally {
        DBUtils.safeClose(con);
    }
}

From source file:org.miloss.fgsms.services.rs.impl.reports.os.MemoryUsageReport.java

@Override
public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files,
        TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx)
        throws IOException {

    Connection con = Utility.getPerformanceDBConnection();
    try {// w  w  w  .  j  a  v a  2 s  . c  o m
        PreparedStatement cmd = null;
        ResultSet rs = null;
        JFreeChart chart = null;

        data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>");
        data.append(GetHtmlFormattedHelp() + "<br />");
        data.append("<table class=\"table table-hover\"><tr><th>URI</th><th>Average Memory Usage (bytes)</tr>");
        TimeSeriesCollection col = new TimeSeriesCollection();
        for (int i = 0; i < urls.size(); i++) {
            if (!isPolicyTypeOf(urls.get(i), PolicyType.MACHINE)
                    && !isPolicyTypeOf(urls.get(i), PolicyType.PROCESS)) {
                continue;
            }
            //https://github.com/mil-oss/fgsms/issues/112
            if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) {
                continue;
            }
            String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i)));
            try {
                data.append("<tr><td>").append(url).append("</td>");
                double average = 0;
                try {
                    cmd = con.prepareStatement(
                            "select avg(memoryused) from rawdatamachineprocess where uri=? and utcdatetime > ? and utcdatetime < ?;");
                    cmd.setString(1, urls.get(i));
                    cmd.setLong(2, range.getStart().getTimeInMillis());
                    cmd.setLong(3, range.getEnd().getTimeInMillis());
                    rs = cmd.executeQuery();
                    if (rs.next()) {
                        average = rs.getDouble(1);
                    }
                } catch (Exception ex) {
                    log.log(Level.WARN, null, ex);
                } finally {
                    DBUtils.safeClose(rs);
                    DBUtils.safeClose(cmd);
                }

                data.append("<td>").append(average + "").append("</td></tr>");

                TimeSeries ts = new TimeSeries(url, Millisecond.class);
                try {
                    //ok now get the raw data....
                    cmd = con.prepareStatement(
                            "select memoryused,utcdatetime from rawdatamachineprocess where uri=? and utcdatetime > ? and utcdatetime < ?;");
                    cmd.setString(1, urls.get(i));
                    cmd.setLong(2, range.getStart().getTimeInMillis());
                    cmd.setLong(3, range.getEnd().getTimeInMillis());
                    rs = cmd.executeQuery();

                    while (rs.next()) {
                        GregorianCalendar gcal = new GregorianCalendar();
                        gcal.setTimeInMillis(rs.getLong(2));
                        Millisecond m = new Millisecond(gcal.getTime());
                        ts.addOrUpdate(m, rs.getDouble(1));
                    }
                } catch (Exception ex) {
                    log.log(Level.WARN, null, ex);
                } finally {
                    DBUtils.safeClose(rs);
                    DBUtils.safeClose(cmd);
                }
                col.addSeries(ts);

            } catch (Exception ex) {
                log.log(Level.ERROR, "Error opening or querying the database.", ex);
            }

        }
        chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "Bytes", col,
                true, false, false);

        data.append("</table>");
        try {
            //if (set.getRowCount() != 0) {
            ChartUtilities.saveChartAsPNG(new File(
                    path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart,
                    1500, 400);
            data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">");
            files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png");
            // }
        } catch (IOException ex) {
            log.log(Level.ERROR, "Error saving chart image for request", ex);
        }
    } catch (Exception ex) {
        log.log(Level.ERROR, null, ex);
    } finally {
        DBUtils.safeClose(con);
    }
}

From source file:net.alexjf.tmm.fragments.MoneyNodeEditorFragment.java

public void onDateSet(DatePicker view, int year, int month, int day) {
    GregorianCalendar calendar = new GregorianCalendar(year, month, day);
    creationDateButton.setText(dateFormat.format(calendar.getTime()));
}

From source file:com.sami.chart.util.LineChartDemo1.java

private CategoryDataset createDataset(boolean a) {
    final String series1 = "First";
    final String series2 = "Second";
    final String series3 = "Third";

    GregorianCalendar gc = new GregorianCalendar();
    gc.set(2007, 9, 7);//from   w  w w.  j a v a2 s .  co  m

    //       Date yesterday = new Date(System.currentTimeMillis() - 86400000);
    Date yesterday = gc.getTime();
    DateChecker checker = new DateChecker();
    checker.setDate(yesterday);

    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    try {
        TempReader reader = (TempReader) getClass().forName(getProperty("reader.Class")).newInstance();
        String line = "";
        while ((line = reader.readLine()) != null) {
            if (checker.isFromToday(line)) {
                String[] items = line.split(",");

                dataset.addValue(Float.parseFloat(items[1]), series1, items[0]);
                dataset.addValue(Float.parseFloat(items[2]), series2, items[0]);
                dataset.addValue(Float.parseFloat(items[3]), series3, items[0]);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return dataset;
}

From source file:ve.zoonosis.controller.modulos.estadistica.ComparativaAnualController.java

private void generarEstadistica() {
    panel.removeAll();//from w  w  w.  ja va  2  s .  com
    // Primer ao
    String year;
    for (int j = 0; j < 2; j++) {
        if (j == 0) {
            year = years1.getSelectedItem().toString();
        } else {
            year = years2.getSelectedItem().toString();
        }

        for (Integer i = 1; i < 13; i++) {
            int mes;

            if (i < 10) {

                mes = Integer.parseInt(0 + i.toString());
            } else {
                mes = i;
            }
            GregorianCalendar gc = new GregorianCalendar(Integer.parseInt(year), mes - 1, 1);

            final Date fecha = gc.getTime();
            RequestBuilder rb = new RequestBuilder();
            if (porCasoJornada.getSelectedItem().toString().equalsIgnoreCase("Jornadas")) {
                try {
                    rb = new RequestBuilder("services/funcionales/AnimalWs/ObtenerListaAnimalesDeJornada.php",
                            new HashMap<String, Object>() {
                                {
                                    put("dia", fecha);
                                }
                            });

                    // System.out.println("Cantidad animales = " + cantidadAnimales);
                } catch (URISyntaxException ex) {
                    java.util.logging.Logger.getLogger(ComparativaAnualController.class.getName())
                            .log(Level.SEVERE, null, ex);
                }

            } else {
                try {
                    rb = new RequestBuilder("services/funcionales/AnimalWs/ObtenerListaAnimalesDeCaso.php",
                            new HashMap<String, Object>() {
                                {
                                    put("dia", fecha);
                                }
                            });

                    // System.out.println("Cantidad animales = " + cantidadAnimales);
                } catch (URISyntaxException ex) {
                    java.util.logging.Logger.getLogger(ComparativaAnualController.class.getName())
                            .log(Level.SEVERE, null, ex);
                }

            }
            Integer cantidadAnimales = rb.ejecutarJson(Integer.class);
            if (cantidadAnimales == null) {
                cantidadAnimales = 0;
            }
            System.out.println(mes);
            System.out.println(cantidadAnimales + " - " + obtenerNombreMes(mes));
            Datos.addValue(cantidadAnimales, year, obtenerNombreMes(mes));

        }
    }
    grafica = ChartFactory.createBarChart("Animales Por ao", "Meses", "Animales", Datos,
            PlotOrientation.VERTICAL, true, true, false);
    grafica.setBackgroundPaint(Color.white);
    final CategoryPlot plot = grafica.getCategoryPlot();
    plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF));
    ChartPanel Panel = new ChartPanel(grafica);
    JFrame a = new JFrame();
    // frame b = new frame();
    a.getContentPane().add(Panel);
    a.pack();
    panel.add(a.getContentPane());
    panel.repaint();

}