/** * Returns a copy of this point with another value. * * @param value the value to change the point to * @return a point based on this point with the value changed */ public LocalDateDoublePoint withValue(double value) { return LocalDateDoublePoint.of(date, value); }
/** * Returns a copy of this point with another date. * * @param date the date to change the point to * @return a point based on this point with the date changed */ public LocalDateDoublePoint withDate(LocalDate date) { return LocalDateDoublePoint.of(date, value); }
private Stream<LocalDateDoublePoint> streamEntries() { return entries.entrySet() .stream() .map(e -> LocalDateDoublePoint.of(e.getKey(), e.getValue())); }
@Override public Stream<LocalDateDoublePoint> stream() { return validIndices() .mapToObj(i -> LocalDateDoublePoint.of(calculateDateFromPosition(i), points[i])); }
@Test(expectedExceptions = IllegalArgumentException.class) public void test_withDate_nullDate() { LocalDateDoublePoint base = LocalDateDoublePoint.of(DATE_2012_06_30, 1d); base.withDate(null); }
public void test_stream() { LocalDateDoubleTimeSeries base = LocalDateDoubleTimeSeries.builder().putAll(DATES_2010_12, VALUES_10_12).build(); Object[] test = base.stream().toArray(); assertEquals(test[0], LocalDateDoublePoint.of(DATE_2010_01_01, 10)); assertEquals(test[1], LocalDateDoublePoint.of(DATE_2011_01_01, 11)); assertEquals(test[2], LocalDateDoublePoint.of(DATE_2012_01_01, 12)); }
public void test_stream() { LocalDateDoubleTimeSeries base = LocalDateDoubleTimeSeries.builder().putAll(DATES_2010_12, VALUES_10_12).build(); Object[] test = base.stream().toArray(); assertEquals(test[0], LocalDateDoublePoint.of(DATE_2010_01_01, 10)); assertEquals(test[1], LocalDateDoublePoint.of(DATE_2011_01_01, 11)); assertEquals(test[2], LocalDateDoublePoint.of(DATE_2012_01_01, 12)); }
public void test_equalsHashCode_differentValues() { LocalDateDoublePoint a1 = LocalDateDoublePoint.of(DATE_2012_06_29, 1d); LocalDateDoublePoint a2 = LocalDateDoublePoint.of(DATE_2012_06_29, 1d); LocalDateDoublePoint b = LocalDateDoublePoint.of(DATE_2012_06_29, 2d); LocalDateDoublePoint c = LocalDateDoublePoint.of(DATE_2012_06_29, 3d); assertEquals(a1.equals(a1), true); assertEquals(a1.equals(a2), true); assertEquals(a1.equals(b), false); assertEquals(a1.equals(c), false); assertEquals(a1.hashCode(), a1.hashCode()); }
public void test_equalsHashCode_differentDates() { LocalDateDoublePoint a1 = LocalDateDoublePoint.of(DATE_2012_06_29, 1d); LocalDateDoublePoint a2 = LocalDateDoublePoint.of(DATE_2012_06_29, 1d); LocalDateDoublePoint b = LocalDateDoublePoint.of(DATE_2012_06_30, 1d); LocalDateDoublePoint c = LocalDateDoublePoint.of(DATE_2012_07_01, 1d); assertEquals(a1.equals(a1), true); assertEquals(a1.equals(a2), true); assertEquals(a1.equals(b), false); assertEquals(a1.equals(c), false); assertEquals(a1.hashCode(), a1.hashCode()); }
public void test_equalsBad() { LocalDateDoublePoint a = LocalDateDoublePoint.of(DATE_2012_06_29, 1d); assertEquals(a.equals(ANOTHER_TYPE), false); assertEquals(a.equals(null), false); }
public void test_of() { LocalDateDoublePoint test = LocalDateDoublePoint.of(DATE_2012_06_30, 1d); assertEquals(test.getDate(), DATE_2012_06_30); assertEquals(test.getValue(), 1d, TOLERANCE); }
public void test_immutableDatesViaBeanGet() { LocalDateDoubleTimeSeries test = LocalDateDoubleTimeSeries.builder().putAll(DATES_2010_12, VALUES_10_12).build(); LocalDate[] array = (LocalDate[]) ((Bean) test).property("dates").get(); array[0] = DATE_2012_01_01; LocalDateDoublePoint[] points = test.stream().toArray(LocalDateDoublePoint[]::new); assertEquals(points[0], LocalDateDoublePoint.of(DATE_2010_01_01, 10d)); assertEquals(points[1], LocalDateDoublePoint.of(DATE_2011_01_01, 11d)); assertEquals(points[2], LocalDateDoublePoint.of(DATE_2012_01_01, 12d)); }
public void test_immutableValuesViaBeanGet() { LocalDateDoubleTimeSeries test = LocalDateDoubleTimeSeries.builder().putAll(DATES_2010_12, VALUES_10_12).build(); double[] array = (double[]) ((Bean) test).property("values").get(); array[0] = -1; LocalDateDoublePoint[] points = test.stream().toArray(LocalDateDoublePoint[]::new); assertEquals(points[0], LocalDateDoublePoint.of(DATE_2010_01_01, 10d)); assertEquals(points[1], LocalDateDoublePoint.of(DATE_2011_01_01, 11d)); assertEquals(points[2], LocalDateDoublePoint.of(DATE_2012_01_01, 12d)); }
public void test_immutableValuesViaBeanGet() { LocalDateDoubleTimeSeries test = LocalDateDoubleTimeSeries.builder().putAll(DATES_2015_1_WEEK, VALUES_1_WEEK).build(); double[] array = (double[]) ((Bean) test).property("points").get(); array[0] = -1; LocalDateDoublePoint[] points = test.stream().toArray(LocalDateDoublePoint[]::new); assertEquals(points[0], LocalDateDoublePoint.of(DATE_2015_01_05, 10d)); assertEquals(points[1], LocalDateDoublePoint.of(DATE_2015_01_06, 11d)); assertEquals(points[2], LocalDateDoublePoint.of(DATE_2015_01_07, 12d)); }
public void test_coverage() { TestHelper.coverImmutableBean( (ImmutableBean) DenseLocalDateDoubleTimeSeries.of(DATE_2015_01_05, DATE_2015_01_05, Stream.of(LocalDateDoublePoint.of(DATE_2015_01_05, 1d)), SKIP_WEEKENDS)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void test_of_collection_collectionWithNull() { Collection<LocalDateDoublePoint> points = Arrays.asList( LocalDateDoublePoint.of(DATE_2011_01_01, 2d), null); LocalDateDoubleTimeSeries.builder().putAll(points.stream()).build(); }
public void test_withValue() { LocalDateDoublePoint base = LocalDateDoublePoint.of(DATE_2012_06_30, 1d); LocalDateDoublePoint test = base.withValue(2d); assertEquals(test.getDate(), DATE_2012_06_30); assertEquals(test.getValue(), 2d, TOLERANCE); }
public void test_withDate() { LocalDateDoublePoint base = LocalDateDoublePoint.of(DATE_2012_06_30, 1d); LocalDateDoublePoint test = base.withDate(DATE_2012_06_29); assertEquals(test.getDate(), DATE_2012_06_29); assertEquals(test.getValue(), 1d, TOLERANCE); }
public void test_of_collection_collectionWithNull() { Collection<LocalDateDoublePoint> points = Arrays.asList( LocalDateDoublePoint.of(DATE_2011_01_01, 2d), null); assertThrowsIllegalArg(() -> LocalDateDoubleTimeSeries.builder().putAll(points.stream()).build()); }
public void test_merge_point() { LocalDateDoubleTimeSeriesBuilder test = LocalDateDoubleTimeSeries.builder(); test.put(date(2013, 1, 1), 2d); test.merge(LocalDateDoublePoint.of(date(2013, 1, 1), 3d), Double::sum); assertEquals(test.get(date(2013, 1, 1)), OptionalDouble.of(5d)); }