org.threeten.extra.Interval Java Examples
The following examples show how to use
org.threeten.extra.Interval.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeoTests.java From FROST-Server with GNU Lesser General Public License v3.0 | 6 votes |
private static void createLocation0() throws ServiceFailureException { // Locations 0 Point gjo = new Point(8, 51); Location location = new Location("Location 1.0", "First Location of Thing 1.", "application/vnd.geo+json", gjo); location.getThings().add(THINGS.get(0)); service.create(location); LOCATIONS.add(location); FeatureOfInterest featureOfInterest = new FeatureOfInterest("FoI 0", "This should be FoI #0.", "application/geo+json", gjo); service.create(featureOfInterest); FEATURESOFINTEREST.add(featureOfInterest); Observation o = new Observation(1, DATASTREAMS.get(0)); o.setFeatureOfInterest(featureOfInterest); o.setPhenomenonTimeFrom(ZonedDateTime.parse("2016-01-01T01:01:01.000Z")); o.setValidTime(Interval.of(Instant.parse("2016-01-01T01:01:01.000Z"), Instant.parse("2016-01-01T23:59:59.999Z"))); service.create(o); OBSERVATIONS.add(o); }
Example #2
Source File: GeoTests.java From FROST-Server with GNU Lesser General Public License v3.0 | 6 votes |
private static void createLocation1() throws ServiceFailureException { // Locations 1 Point gjo = new Point(8, 52); Location location = new Location("Location 1.1", "Second Location of Thing 1.", "application/vnd.geo+json", gjo); location.getThings().add(THINGS.get(0)); service.create(location); LOCATIONS.add(location); FeatureOfInterest featureOfInterest = new FeatureOfInterest("FoI 1", "This should be FoI #1.", "application/geo+json", gjo); service.create(featureOfInterest); FEATURESOFINTEREST.add(featureOfInterest); Observation o = new Observation(2, DATASTREAMS.get(0)); o.setFeatureOfInterest(featureOfInterest); o.setPhenomenonTimeFrom(ZonedDateTime.parse("2016-01-02T01:01:01.000Z")); o.setValidTime(Interval.of(Instant.parse("2016-01-02T01:01:01.000Z"), Instant.parse("2016-01-02T23:59:59.999Z"))); service.create(o); OBSERVATIONS.add(o); }
Example #3
Source File: GeoTests.java From FROST-Server with GNU Lesser General Public License v3.0 | 6 votes |
private static void createLocation2() throws ServiceFailureException { // Locations 2 Point gjo = new Point(8, 53); Location location = new Location("Location 2", "Location of Thing 2.", "application/vnd.geo+json", gjo); location.getThings().add(THINGS.get(1)); service.create(location); LOCATIONS.add(location); FeatureOfInterest featureOfInterest = new FeatureOfInterest("FoI 2", "This should be FoI #2.", "application/geo+json", gjo); service.create(featureOfInterest); FEATURESOFINTEREST.add(featureOfInterest); Observation o = new Observation(3, DATASTREAMS.get(1)); o.setFeatureOfInterest(featureOfInterest); o.setPhenomenonTimeFrom(ZonedDateTime.parse("2016-01-03T01:01:01.000Z")); o.setValidTime(Interval.of(Instant.parse("2016-01-03T01:01:01.000Z"), Instant.parse("2016-01-03T23:59:59.999Z"))); service.create(o); OBSERVATIONS.add(o); }
Example #4
Source File: GeoTests.java From FROST-Server with GNU Lesser General Public License v3.0 | 6 votes |
private static void createLocation3() throws ServiceFailureException { // Locations 3 Point gjo = new Point(8, 54); Location location = new Location("Location 3", "Location of Thing 3.", "application/vnd.geo+json", gjo); location.getThings().add(THINGS.get(2)); service.create(location); LOCATIONS.add(location); FeatureOfInterest featureOfInterest = new FeatureOfInterest("FoI 3", "This should be FoI #3.", "application/geo+json", gjo); service.create(featureOfInterest); FEATURESOFINTEREST.add(featureOfInterest); Observation o = new Observation(4, DATASTREAMS.get(2)); o.setFeatureOfInterest(featureOfInterest); o.setPhenomenonTimeFrom(ZonedDateTime.parse("2016-01-04T01:01:01.000Z")); o.setValidTime(Interval.of(Instant.parse("2016-01-04T01:01:01.000Z"), Instant.parse("2016-01-04T23:59:59.999Z"))); service.create(o); OBSERVATIONS.add(o); }
Example #5
Source File: TimeUtils.java From geowave with Apache License 2.0 | 6 votes |
public static Interval getInterval(final SimpleFeature entry, final String fieldName) { final Object o = entry.getAttribute(fieldName); final Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); if (o == null) { return null; } if (o instanceof Date) { c.setTime((Date) o); } else if (o instanceof Calendar) { c.setTime(c.getTime()); } else if (o instanceof Number) { c.setTimeInMillis(((Number) o).longValue()); } final Instant time = Instant.ofEpochMilli(c.getTimeInMillis()); return Interval.of(time, time); }
Example #6
Source File: ExplicitSpatialTemporalQuery.java From geowave with Apache License 2.0 | 6 votes |
public static ConstraintsByClass createConstraints( final Interval[] intervals, final boolean isDefault) { final List<ConstraintSet> constraints = new ArrayList<>(); for (final Interval range : intervals) { constraints.add( new ConstraintSet( new ConstraintData( new NumericRange( range.getStart().toEpochMilli(), // intervals are intended to be exclusive on the end so this adjusts for // exclusivity Math.max(range.getEnd().toEpochMilli() - 1, range.getStart().toEpochMilli())), isDefault), TimeDefinition.class, SimpleTimeDefinition.class)); } return new ConstraintsByClass(constraints); }
Example #7
Source File: ExplicitTemporalQuery.java From geowave with Apache License 2.0 | 6 votes |
private static ConstraintsByClass createTemporalConstraints(final Interval[] intervals) { final List<ConstraintSet> constraints = new ArrayList<>(); for (final Interval range : intervals) { constraints.add( new ConstraintSet( new ConstraintData( new NumericRange( range.getStart().toEpochMilli(), // intervals are intended to be exclusive on the end so this adjusts for // exclusivity Math.max(range.getEnd().toEpochMilli() - 1, range.getStart().toEpochMilli())), false), TimeDefinition.class, SimpleTimeDefinition.class)); } return new ConstraintsByClass(constraints); }
Example #8
Source File: StringTimeSeriesLostColumnsIssueTest.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
@Test public void test() throws IOException { String csv = String.join(System.lineSeparator(), "Time;Version;TITLE1;TITLE2", "2016-01-01T01:00:00Z;1;VALUE;VALUE", "2016-01-01T02:00:00Z;1;VALUE;VALUE") + System.lineSeparator(); Map<Integer, List<TimeSeries>> tsMap = TimeSeries.parseCsv(csv, ';'); TimeSeriesIndex index = RegularTimeSeriesIndex.create(Interval.parse("2016-01-01T01:00:00Z/2016-01-01T02:00:00Z"), Duration.ofHours(1)); TimeSeriesTable table = new TimeSeriesTable(1, 1, index); table.load(1, tsMap.get(1)); String csv2 = table.toCsvString(';', ZoneId.of("UTC")); assertEquals(csv, csv2); }
Example #9
Source File: RegularTimeSeriesIndexTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void testEquals() { new EqualsTester() .addEqualityGroup(RegularTimeSeriesIndex.create(Interval.parse("2015-01-01T00:00:00Z/2015-01-01T01:00:00Z"), Duration.ofMinutes(15)), RegularTimeSeriesIndex.create(Interval.parse("2015-01-01T00:00:00Z/2015-01-01T01:00:00Z"), Duration.ofMinutes(15))) .addEqualityGroup(RegularTimeSeriesIndex.create(Interval.parse("2015-01-01T00:00:00Z/2015-01-01T01:15:00Z"), Duration.ofMinutes(30)), RegularTimeSeriesIndex.create(Interval.parse("2015-01-01T00:00:00Z/2015-01-01T01:15:00Z"), Duration.ofMinutes(30))) .testEquals(); }
Example #10
Source File: SpatialTemporalConstraintsBuilderImpl.java From geowave with Apache License 2.0 | 5 votes |
@Override public SpatialTemporalConstraintsBuilder setTimeRanges(final Interval[] timeRanges) { if (timeRanges == null) { this.timeRanges = new Interval[0]; } this.timeRanges = timeRanges; return this; }
Example #11
Source File: RegularTimeSeriesIndexTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void test() throws IOException { RegularTimeSeriesIndex index = RegularTimeSeriesIndex.create(Interval.parse("2015-01-01T00:00:00Z/2015-01-01T01:00:00Z"), Duration.ofMinutes(15)); // test getters assertEquals("2015-01-01T00:00:00Z", Instant.ofEpochMilli(index.getStartTime()).toString()); assertEquals("2015-01-01T01:00:00Z", Instant.ofEpochMilli(index.getEndTime()).toString()); assertEquals(15 * 60 * 1000, index.getSpacing()); assertEquals(5, index.getPointCount()); assertEquals(Instant.ofEpochMilli(index.getStartTime() + 15 * 60 * 1000).toEpochMilli(), index.getTimeAt(1)); assertEquals("2015-01-01T00:15:00Z", index.getInstantAt(1).toString()); // test iterator ans stream List<Instant> instants = Arrays.asList(Instant.parse("2015-01-01T00:00:00Z"), Instant.parse("2015-01-01T00:15:00Z"), Instant.parse("2015-01-01T00:30:00Z"), Instant.parse("2015-01-01T00:45:00Z"), Instant.parse("2015-01-01T01:00:00Z")); assertEquals(instants, index.stream().collect(Collectors.toList())); assertEquals(instants, Lists.newArrayList(index.iterator())); // test to string assertEquals("RegularTimeSeriesIndex(startTime=2015-01-01T00:00:00Z, endTime=2015-01-01T01:00:00Z, spacing=PT15M)", index.toString()); // test json String jsonRef = String.join(System.lineSeparator(), "{", " \"startTime\" : 1420070400000,", " \"endTime\" : 1420074000000,", " \"spacing\" : 900000", "}"); String json = index.toJson(); assertEquals(jsonRef, json); RegularTimeSeriesIndex index2 = JsonUtil.parseJson(json, RegularTimeSeriesIndex::parseJson); assertNotNull(index2); assertEquals(index, index2); }
Example #12
Source File: TimeRangeAggregation.java From geowave with Apache License 2.0 | 5 votes |
@Override public byte[] resultToBinary(final Interval result) { long start = Long.MAX_VALUE; long end = Long.MIN_VALUE; if (result != null) { start = result.getStart().toEpochMilli(); end = result.getEnd().toEpochMilli(); } final ByteBuffer buffer = ByteBuffer.allocate(VarintUtils.timeByteLength(start) + VarintUtils.timeByteLength(end)); VarintUtils.writeTime(start, buffer); VarintUtils.writeTime(end, buffer); return buffer.array(); }
Example #13
Source File: TimeRangeDataStatistics.java From geowave with Apache License 2.0 | 5 votes |
@Override public Interval getResult() { if (isSet()) { return Interval.of(Instant.ofEpochMilli(min), Instant.ofEpochMilli(max)); } return null; }
Example #14
Source File: DoubleDataChunkTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void baseTest() throws IOException { UncompressedDoubleDataChunk chunk = new UncompressedDoubleDataChunk(1, new double[] {1d, 2d, 3d}); assertEquals(1, chunk.getOffset()); assertEquals(3, chunk.getLength()); assertArrayEquals(new double[]{1d, 2d, 3d}, chunk.getValues(), 0d); assertEquals(24, chunk.getEstimatedSize()); assertFalse(chunk.isCompressed()); assertEquals(1d, chunk.getCompressionFactor(), 0d); DoubleBuffer buffer = DoubleBuffer.allocate(4); for (int i = 0; i < 4; i++) { buffer.put(i, Double.NaN); } chunk.fillBuffer(buffer, 0); assertArrayEquals(new double[] {Double.NaN, 1d, 2d, 3d}, buffer.array(), 0d); String jsonRef = String.join(System.lineSeparator(), "{", " \"offset\" : 1,", " \"values\" : [ 1.0, 2.0, 3.0 ]", "}"); assertEquals(jsonRef, JsonUtil.toJson(chunk::writeJson)); RegularTimeSeriesIndex index = RegularTimeSeriesIndex.create(Interval.parse("2015-01-01T00:00:00Z/2015-01-01T00:45:00Z"), Duration.ofMinutes(15)); assertEquals(ImmutableList.of(new DoublePoint(1, Instant.parse("2015-01-01T00:15:00Z").toEpochMilli(), 1d), new DoublePoint(2, Instant.parse("2015-01-01T00:30:00Z").toEpochMilli(), 2d), new DoublePoint(3, Instant.parse("2015-01-01T00:45:00Z").toEpochMilli(), 3d)), chunk.stream(index).collect(Collectors.toList())); }
Example #15
Source File: TimeRangeDataStatistics.java From geowave with Apache License 2.0 | 5 votes |
@Override public void entryIngested(final T entry, final GeoWaveRow... kvs) { final Interval range = getInterval(entry); if (range != null) { min = Math.min(min, range.getStart().toEpochMilli()); max = Math.max(max, range.getEnd().toEpochMilli()); } }
Example #16
Source File: ExplicitSpatialTemporalQuery.java From geowave with Apache License 2.0 | 5 votes |
public ExplicitSpatialTemporalQuery( final Interval[] intervals, final Geometry queryGeometry, final String crsCode, final CompareOperation compareOp) { super( createSpatialTemporalConstraints(intervals, queryGeometry), queryGeometry, crsCode, compareOp, // it seems like temporal should always use intersection and not // inherit from the spatial compare op BasicQueryCompareOperation.INTERSECTS); }
Example #17
Source File: StringDataChunkTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void compressTest() throws IOException { UncompressedStringDataChunk chunk = new UncompressedStringDataChunk(1, new String[] {"aaa", "bbb", "bbb", "bbb", "bbb", "ccc"}); StringDataChunk maybeCompressedChunk = chunk.tryToCompress(); assertTrue(maybeCompressedChunk instanceof CompressedStringDataChunk); CompressedStringDataChunk compressedChunk = (CompressedStringDataChunk) maybeCompressedChunk; assertEquals(1, compressedChunk.getOffset()); assertEquals(6, compressedChunk.getLength()); assertTrue(compressedChunk.isCompressed()); assertEquals(30, compressedChunk.getEstimatedSize()); assertEquals(30d / 36, compressedChunk.getCompressionFactor(), 0d); assertArrayEquals(new String[] {"aaa", "bbb", "ccc"}, compressedChunk.getStepValues()); assertArrayEquals(new int[] {1, 4, 1}, compressedChunk.getStepLengths()); CompactStringBuffer buffer = new CompactStringBuffer(ByteBuffer::allocate, 7); compressedChunk.fillBuffer(buffer, 0); assertArrayEquals(new String[] {null, "aaa", "bbb", "bbb", "bbb", "bbb", "ccc"}, buffer.toArray()); String jsonRef = String.join(System.lineSeparator(), "{", " \"offset\" : 1,", " \"uncompressedLength\" : 6,", " \"stepValues\" : [ \"aaa\", \"bbb\", \"ccc\" ],", " \"stepLengths\" : [ 1, 4, 1 ]", "}"); assertEquals(jsonRef, JsonUtil.toJson(compressedChunk::writeJson)); RegularTimeSeriesIndex index = RegularTimeSeriesIndex.create(Interval.parse("2015-01-01T00:00:00Z/2015-01-01T01:30:00Z"), Duration.ofMinutes(15)); assertEquals(ImmutableList.of(new StringPoint(1, Instant.parse("2015-01-01T00:15:00Z").toEpochMilli(), "aaa"), new StringPoint(2, Instant.parse("2015-01-01T00:30:00Z").toEpochMilli(), "bbb"), new StringPoint(6, Instant.parse("2015-01-01T01:30:00Z").toEpochMilli(), "ccc")), compressedChunk.stream(index).collect(Collectors.toList())); }
Example #18
Source File: DeleteFilterTests.java From FROST-Server with GNU Lesser General Public License v3.0 | 5 votes |
private void createObservation(double result, Datastream ds, TimeObject pt, ZonedDateTime rt, Interval vt) throws ServiceFailureException { Observation o = new Observation(result, ds); o.setPhenomenonTime(pt); o.setResultTime(rt); o.setValidTime(vt); service.create(o); OBSERVATIONS.add(o); }
Example #19
Source File: FilterTests.java From FROST-Server with GNU Lesser General Public License v3.0 | 5 votes |
private static void createObservationSet(Datastream datastream, long resultStart, ZonedDateTime phenomenonTimeStart, Interval validTimeStart, int count) throws ServiceFailureException { for (int i = 0; i < count; i++) { ZonedDateTime phenTime = phenomenonTimeStart.plus(i, ChronoUnit.HOURS); Interval validTime = Interval.of( validTimeStart.getStart().plus(count, ChronoUnit.HOURS), validTimeStart.getEnd().plus(count, ChronoUnit.HOURS)); createObservation(datastream, resultStart + i, phenTime, validTime); } }
Example #20
Source File: FilterTests.java From FROST-Server with GNU Lesser General Public License v3.0 | 5 votes |
private static Observation createObservation(Datastream datastream, long result, ZonedDateTime phenomenonTime, Interval validTime) throws ServiceFailureException { int idx = OBSERVATIONS.size(); Map<String, Object> parameters = new HashMap<>(); parameters.put("idx", idx); Observation obs = new Observation(result, datastream); obs.setPhenomenonTimeFrom(phenomenonTime); obs.setValidTime(validTime); obs.setParameters(parameters); service.create(obs); OBSERVATIONS.add(obs); return obs; }
Example #21
Source File: SpatialTemporalConstraintsBuilderImpl.java From geowave with Apache License 2.0 | 5 votes |
@Override public SpatialTemporalConstraintsBuilder addTimeRange(final Date startTime, final Date endTime) { return addTimeRange( Interval.of( Instant.ofEpochMilli(startTime.getTime()), Instant.ofEpochMilli(endTime.getTime()))); }
Example #22
Source File: DateTimeTests.java From FROST-Server with GNU Lesser General Public License v3.0 | 5 votes |
private static void createObservation(double result, Datastream ds, TimeObject pt, ZonedDateTime rt, Interval vt) throws ServiceFailureException { Observation o = new Observation(result, ds); o.setPhenomenonTime(pt); o.setResultTime(rt); o.setValidTime(vt); service.create(o); OBSERVATIONS.add(o); }
Example #23
Source File: XmlAdaptersTest.java From threeten-jaxb with Apache License 2.0 | 5 votes |
XmlAdaptersTest() throws JAXBException { this.jaxbContext = JAXBContext.newInstance(Bean.class); final Bean expectedBean = new Bean(); expectedBean.dayOfMonth = DayOfMonth.of(21); expectedBean.dayOfYear = DayOfYear.of(51); expectedBean.days = Days.of(12); expectedBean.hours = Hours.of(4); expectedBean.interval = Interval.of( LocalDateTime.of(2007, 12, 3, 10, 15, 30) .toInstant(ZoneOffset.UTC), LocalDateTime.of(2007, 12, 4, 10, 15, 30) .toInstant(ZoneOffset.UTC) ); expectedBean.localDateRange = LocalDateRange.of( LocalDate.of(2007, 12, 3), LocalDate.of(2007, 12, 4) ); expectedBean.minutes = Minutes.of(8); expectedBean.months = Months.of(12); expectedBean.periodDuration = PeriodDuration.of(Period.of(1, 2, 25), Duration.ofHours(8)); expectedBean.seconds = Seconds.of(8); expectedBean.weeks = Weeks.of(12); expectedBean.yearQuarter = YearQuarter.of(2017, Quarter.Q2); expectedBean.years = Years.of(12); expectedBean.yearWeek = YearWeek.of(2015, 13); this.expectedBean = expectedBean; this.expectedMarshalledBean = getClass().getResource("expectedBean.xml"); }
Example #24
Source File: VectorTimeRangeAggregation.java From geowave with Apache License 2.0 | 5 votes |
@Override protected Interval getInterval(final SimpleFeature entry) { if ((fieldNameParam != null) && !fieldNameParam.isEmpty()) { return TimeUtils.getInterval(entry, fieldNameParam.getFieldName()); } final String type = entry.getType().getName().getLocalPart(); TimeDescriptors desc = descMap.get(type); if (desc == null) { desc = TimeUtils.inferTimeAttributeDescriptor(entry.getFeatureType()); descMap.put(type, desc); } if ((desc.getStartRange() != null) && (desc.getEndRange() != null)) { final Object start = entry.getAttribute(desc.getStartRange().getName()); final Object end = entry.getAttribute(desc.getStartRange().getName()); if ((start == null) || (end == null)) { LOGGER.warn("start or end value is null, ignoring feature"); return null; } // TODO we may want to sanity check that start is less than end? return Interval.of( Instant.ofEpochMilli(TimeUtils.getTimeMillis(start)), Instant.ofEpochMilli(TimeUtils.getTimeMillis(end))); } else if (desc.getTime() != null) { final Object time = entry.getAttribute(desc.getTime().getName()); if ((time == null)) { LOGGER.warn("time attribute value is null, ignoring feature"); return null; } final Instant instant = Instant.ofEpochMilli(TimeUtils.getTimeMillis(time)); return Interval.of(instant, instant); } LOGGER.error( "time field not found for type '" + entry.getFeatureType().getTypeName() + "'. Consider explicitly setting field name."); return null; }
Example #25
Source File: TimeRangeAggregation.java From geowave with Apache License 2.0 | 5 votes |
@Override public Interval getResult() { if (!isSet()) { return null; } return Interval.of(Instant.ofEpochMilli(min), Instant.ofEpochMilli(max)); }
Example #26
Source File: TimeRangeAggregation.java From geowave with Apache License 2.0 | 5 votes |
@Override public Interval merge(final Interval result1, final Interval result2) { if (result1 == null) { return result2; } else if (result2 == null) { return result1; } final long min = Math.min(result1.getStart().toEpochMilli(), result1.getEnd().toEpochMilli()); final long max = Math.max(result2.getStart().toEpochMilli(), result2.getEnd().toEpochMilli()); return Interval.of(Instant.ofEpochMilli(min), Instant.ofEpochMilli(max)); }
Example #27
Source File: TimeRangeAggregation.java From geowave with Apache License 2.0 | 5 votes |
@Override public Interval resultFromBinary(final byte[] binary) { final ByteBuffer buffer = ByteBuffer.wrap(binary); final long minTime = VarintUtils.readTime(buffer); final long maxTime = VarintUtils.readTime(buffer); if ((min == Long.MAX_VALUE) || (max == Long.MIN_VALUE)) { return null; } return Interval.of(Instant.ofEpochMilli(minTime), Instant.ofEpochMilli(maxTime)); }
Example #28
Source File: TimeRangeAggregation.java From geowave with Apache License 2.0 | 4 votes |
protected void aggregate(final Interval interval) { if (interval != null) { min = Math.min(min, interval.getStart().toEpochMilli()); max = Math.max(max, interval.getEnd().toEpochMilli()); } }
Example #29
Source File: SpatialTemporalConstraintsBuilderImpl.java From geowave with Apache License 2.0 | 4 votes |
@Override public SpatialTemporalConstraintsBuilder addTimeRange(final Interval timeRange) { timeRanges = ArrayUtils.add(timeRanges, timeRange); return this; }
Example #30
Source File: CommonIndexTimeRangeAggregation.java From geowave with Apache License 2.0 | 4 votes |
@Override protected Interval getInterval(final CommonIndexedPersistenceEncoding entry) { return null; }