当前位置: 首页>>代码示例>>Java>>正文


Java ZonedDateTime.withYear方法代码示例

本文整理汇总了Java中java.time.ZonedDateTime.withYear方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.withYear方法的具体用法?Java ZonedDateTime.withYear怎么用?Java ZonedDateTime.withYear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.ZonedDateTime的用法示例。


在下文中一共展示了ZonedDateTime.withYear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runOnSeriesSlices

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void runOnSeriesSlices(){
    ZonedDateTime dateTime = ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault());
    TimeSeries series = new MockTimeSeries(new double[]{1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d, 10d},
                new ZonedDateTime[]{dateTime.withYear(2000), dateTime.withYear(2000), dateTime.withYear(2001), dateTime.withYear(2001), dateTime.withYear(2002),
                dateTime.withYear(2002), dateTime.withYear(2002), dateTime.withYear(2003), dateTime.withYear(2004), dateTime.withYear(2005)});
    manager.setTimeSeries(series);
    
    Strategy aStrategy = new BaseStrategy(new FixedRule(0, 3, 5, 7), new FixedRule(2, 4, 6, 9));

    List<Trade> trades = manager.run(aStrategy, 0, 1).getTrades();
    assertEquals(1, trades.size());
    assertEquals(Order.buyAt(0, series.getTick(0).getClosePrice(), Decimal.NaN),trades.get(0).getEntry());
    assertEquals(Order.sellAt(2, series.getTick(2).getClosePrice(), Decimal.NaN), trades.get(0).getExit());

    trades = manager.run(aStrategy, 2, 3).getTrades();
    assertEquals(1, trades.size());
    assertEquals(Order.buyAt(3, series.getTick(3).getClosePrice(), Decimal.NaN), trades.get(0).getEntry());
    assertEquals(Order.sellAt(4, series.getTick(4).getClosePrice(), Decimal.NaN), trades.get(0).getExit());

    trades = manager.run(aStrategy, 4, 6).getTrades();
    assertEquals(1, trades.size());
    assertEquals(Order.buyAt(5, series.getTick(5).getClosePrice(), Decimal.NaN), trades.get(0).getEntry());
    assertEquals(Order.sellAt(6, series.getTick(6).getClosePrice(), Decimal.NaN), trades.get(0).getExit());

    trades = manager.run(aStrategy, 7, 7).getTrades();
    assertEquals(1, trades.size());
    assertEquals(Order.buyAt(7, series.getTick(7).getClosePrice(), Decimal.NaN), trades.get(0).getEntry());
    assertEquals(Order.sellAt(9, series.getTick(9).getClosePrice(), Decimal.NaN), trades.get(0).getExit());

    trades = manager.run(aStrategy, 8, 8).getTrades();
    assertTrue(trades.isEmpty());

    trades = manager.run(aStrategy, 9, 9).getTrades();
    assertTrue(trades.isEmpty());
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:37,代码来源:TimeSeriesManagerTest.java

示例2: test_withYear_normal

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_withYear_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withYear(2007);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withYear(2007), ZONE_0100));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:TCKZonedDateTime.java

示例3: test_withYear_noChange

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_withYear_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withYear(2008);
    assertEquals(test, base);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:TCKZonedDateTime.java


注:本文中的java.time.ZonedDateTime.withYear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。