示例#1
0
  /**
   * If time is > 60*60*24 [seconds], it will be projected into next day, e.g. time=60*60*24+1=1
   *
   * <p>even if time is negative, it is turned into a positive time by adding number of seconds of
   * day into it consecutively
   *
   * @param time
   * @return
   */
  public static double projectTimeWithin24Hours(double time) {
    double secondsInOneDay = 60 * 60 * 24;

    if (time == Double.NEGATIVE_INFINITY || time == Double.POSITIVE_INFINITY) {
      DebugLib.stopSystemAndReportInconsistency("time is not allowed to be minus or plus infinity");
    }

    while (time < 0) {
      time += secondsInOneDay;
    }

    if (time < secondsInOneDay) {
      return time;
    } else {
      return ((time / secondsInOneDay) - (Math.floor(time / secondsInOneDay))) * secondsInOneDay;
    }
  }
示例#2
0
  public static void generateXYScatterPlot(
      String fileName, double[] x, double[] y, String title, String xLabel, String yLabel) {

    if (x.length != y.length) {
      DebugLib.stopSystemAndReportInconsistency("dimensions of arrays do not match");
    }

    final XYSeries series1 = new XYSeries(title);

    for (int i = 0; i < x.length; i++) {
      series1.add(x[i], y[i]);
    }

    final XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);

    final JFreeChart chart =
        ChartFactory.createXYLineChart(
            title, xLabel, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    int width = 500;
    int height = 300;

    try {
      ChartUtilities.saveChartAsPNG(new File(fileName), chart, width, height);
    } catch (IOException e) {

    }
  }
示例#3
0
  public static LinkedList<String> readFileRows(String fileName) {
    LinkedList<String> list = new LinkedList<String>();

    try {

      FileInputStream fis = new FileInputStream(fileName);
      InputStreamReader isr = new InputStreamReader(fis, "ISO-8859-1");

      BufferedReader br = new BufferedReader(isr);
      String line;
      line = br.readLine();
      while (line != null) {
        list.add(line);
        line = br.readLine();
      }
    } catch (Exception e) {
      e.printStackTrace();
      DebugLib.stopSystemAndReportInconsistency();
    }

    return list;
  }