Skip to content

Commit

Permalink
converted to new api
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCookieLab committed Sep 23, 2024
1 parent 02cccff commit c9a3187
Showing 1 changed file with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@
public class BuildBarSeries {

/**
* Calls different functions that shows how a BaseBarSeries could be created and
* how Bars could be added
* Calls different functions that shows how a BaseBarSeries could be created
* and how Bars could be added
*
* @param args command line arguments (ignored)
*/
@SuppressWarnings("unused")
public static void main(String[] args) {
BarSeries a = buildAndAddData();
System.out.println("a: " + a.getBar(0).getClosePrice().getName());
BaseBarSeriesBuilder.setDefaultFunction(DoubleNum::valueOf);
BaseBarSeriesBuilder.setDefaultNum(DoubleNum::valueOf);
a = buildAndAddData();
System.out.println("a: " + a.getBar(0).getClosePrice().getName());
BarSeries b = buildWithDouble();
Expand All @@ -60,23 +60,23 @@ public static void main(String[] args) {
BarSeries g = buildAndAddBarsFromList();
// Fix: Reset default function, such that this test case does not influence the
// following test cases in a combined test run
BaseBarSeriesBuilder.setDefaultFunction(DecimalNum::valueOf);
BaseBarSeriesBuilder.setDefaultNum(DecimalNum::valueOf);
}

private static BarSeries buildAndAddData() {
BarSeries series = new BaseBarSeriesBuilder().withName("mySeries").build();

ZonedDateTime endTime = ZonedDateTime.now();
series.addBar(endTime, 105.42, 112.99, 104.01, 111.42, 1337);
series.addBar(endTime.plusDays(1), 111.43, 112.83, 107.77, 107.99, 1234);
series.addBar(endTime.plusDays(2), 107.90, 117.50, 107.90, 115.42, 4242);
// ...
return series;
}

private static BarSeries buildWithDouble() {
BarSeries series = new BaseBarSeriesBuilder().withName("mySeries").withNumTypeOf(DoubleNum.class).build();

ZonedDateTime endTime = ZonedDateTime.now();
series.addBar(endTime, 105.42, 112.99, 104.01, 111.42, 1337);
series.addBar(endTime.plusDays(1), 111.43, 112.83, 107.77, 107.99, 1234);
Expand All @@ -85,10 +85,10 @@ private static BarSeries buildWithDouble() {

return series;
}

private static BarSeries buildWithBigDecimal() {
BarSeries series = new BaseBarSeriesBuilder().withName("mySeries").withNumTypeOf(DecimalNum.class).build();

ZonedDateTime endTime = ZonedDateTime.now();
series.addBar(endTime, 105.42, 112.99, 104.01, 111.42, 1337);
series.addBar(endTime.plusDays(1), 111.43, 112.83, 107.77, 107.99, 1234);
Expand All @@ -97,7 +97,7 @@ private static BarSeries buildWithBigDecimal() {

return series;
}

private static BarSeries buildManually() {
BarSeries series = new BaseBarSeries("mySeries"); // uses BigDecimalNum

Expand All @@ -109,9 +109,9 @@ private static BarSeries buildManually() {

return series;
}

private static BarSeries buildManuallyDoubleNum() {
BarSeries series = new BaseBarSeries("mySeries", DoubleNum::valueOf); // uses DoubleNum
BarSeries series = new BaseBarSeries("mySeries", DoubleNum.ZERO); // uses DoubleNum
ZonedDateTime endTime = ZonedDateTime.now();
series.addBar(endTime, 105.42, 112.99, 104.01, 111.42, 1337);
series.addBar(endTime.plusDays(1), 111.43, 112.83, 107.77, 107.99, 1234);
Expand All @@ -120,9 +120,9 @@ private static BarSeries buildManuallyDoubleNum() {

return series;
}

private static BarSeries buildManuallyAndAddBarManually() {
BarSeries series = new BaseBarSeries("mySeries", DoubleNum::valueOf); // uses DoubleNum
BarSeries series = new BaseBarSeries("mySeries", DoubleNum.ZERO); // uses DoubleNum

// create bars and add them to the series. The bars must have the same Num type
// as the series
Expand Down Expand Up @@ -159,10 +159,10 @@ private static BarSeries buildManuallyAndAddBarManually() {
series.addBar(b1);
series.addBar(b2);
series.addBar(b3);

return series;
}

private static BarSeries buildAndAddBarsFromList() {
// Store Bars in a list and add them later. The bars must have the same Num type
// as the series
Expand Down Expand Up @@ -192,14 +192,14 @@ private static BarSeries buildAndAddBarsFromList() {
.volume("4242")
.build();
List<Bar> bars = Arrays.asList(b1, b2, b3);

return new BaseBarSeriesBuilder().withName("mySeries")
.withNumTypeOf(DoubleNum::valueOf)
.withMaxBarCount(5)
.withBars(bars)
.build();
}

private static ConvertibleBaseBarBuilder<String> barBuilderFromString() {
return BaseBar.builder(DoubleNum::valueOf, String.class);
}
Expand Down

0 comments on commit c9a3187

Please sign in to comment.