當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。