1

I have the following code. I want to return both series of the TimeSeries Collection from the one method. I have investigated multiple returns from a method but i cant get them to work.

private XYDataset createDataset(ArrayList<rollingS> lst,ArrayList<rollingS> lst1)
    {
        final TimeSeries series = new TimeSeries("Random Data");
        final TimeSeries series1 = new TimeSeries("Random Data1");

        for (rollingS elem_ : lst) {

            Integer.parseInt(elem_.getFuelTypeGeneration());
            String datetimestring = elem_.getSettDate() + elem_.getPublishingPeriodCommencingTime();

            series.addOrUpdate(new Minute(Integer.parseInt(datetimestring.substring(13, 15)), Integer.parseInt(datetimestring.substring(10, 12)), Integer.parseInt(datetimestring.substring(8, 10)), Integer.parseInt(datetimestring.substring(5, 7)), Integer.parseInt(datetimestring.substring(0, 4))), Integer.parseInt(elem_.getFuelTypeGeneration()));

        }

         for (rollingS elem_ : lst1) {

            Integer.parseInt(elem_.getFuelTypeGeneration());
            String datetimestring = elem_.getSettDate() + elem_.getPublishingPeriodCommencingTime();

            series1.addOrUpdate(new Minute(Integer.parseInt(datetimestring.substring(13, 15)), Integer.parseInt(datetimestring.substring(10, 12)), Integer.parseInt(datetimestring.substring(8, 10)), Integer.parseInt(datetimestring.substring(5, 7)), Integer.parseInt(datetimestring.substring(0, 4))), Integer.parseInt(elem_.getFuelTypeGeneration()));

        }


        return new TimeSeriesCollection(series);
    }
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
inky
  • 137
  • 7

2 Answers2

1
  1. Return a Collection of TimeSeries objects
private List<TimeSeries> createDataset(ArrayList<rollingS> lst,ArrayList<rollingS> lst1) {
    // your code
    List<TimeSeries> timeSeriesList = new ArrayList<>();
    timeSeriesList.add(series);
    timeSeriesList.add(series1);
    return timeSeriesList;
}
  1. Create a new Class containing both the XYset
class XY {
   private TimeSeries X;
   private TimeSeries Y;

   // GETTERS AND SETTERS
    public TimeSeries getX() {
        return X;
    }

    public void setX(TimeSeries x) {
        X = x;
    }

    public TimeSeries getY() {
        return Y;
    }

    public void setY(TimeSeries y) {
        Y = y;
    }

}

private XY createDataset(ArrayList<rollingS> lst,ArrayList<rollingS> lst1) {

    // your code
    XY obj = new XY<>();
    obj.setX(series);
    obj.sety(series1);
    return obj;
}
Sahil Garg
  • 167
  • 6
  • Could i have some help creating the getters and setters? – inky Jun 12 '20 at 17:49
  • check my last edit. I recommend to use IDE (like intellij, eclipse etc.) to create getters and setters. please follow [create getter setters in intellij](https://stackoverflow.com/questions/16988504/intellij-code-completion-for-all-setter-getter-methods-of-local-variable-object) and [create getter setters in eclipse](https://stackoverflow.com/questions/7221691/is-there-a-way-to-automatically-generate-getters-and-setters-in-eclipse) – Sahil Garg Jun 13 '20 at 02:52
0

Returning multiple values from a method is not possible. How would you access them otherwise?

Best alternative is to return a small DataStructure containing both return values.

You can choose to return an Array or a Collection (hint Arrays#asList).

Or you could create a small wrapper class containing both values which you can return.

n247s
  • 1,898
  • 1
  • 12
  • 30