org.geotools.temporal.object.DefaultPeriod Java Examples

The following examples show how to use org.geotools.temporal.object.DefaultPeriod. 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: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBeforeFilterPeriod() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    org.opengis.filter.temporal.Before filter = ff.before(ff.property("dateAttr"), ff.literal(period));
    Map<String,Object> expected = ImmutableMap.of("range",
            ImmutableMap.of("dateAttr", ImmutableMap.of("lt", "1970-07-19T01:02:03.456Z")));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #2
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBeforeFilterPeriodSwapped() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    org.opengis.filter.temporal.Before filter = ff.before(ff.literal(period), ff.property("dateAttr"));
    Map<String,Object> expected = ImmutableMap.of("range",
            ImmutableMap.of("dateAttr", ImmutableMap.of("gt", "1970-07-19T07:08:09.101Z")));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #3
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBegins() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    Begins filter = ff.begins(ff.property("dateAttr"), ff.literal(period));
    Map<String,Object> expected = ImmutableMap.of("term",
            ImmutableMap.of("dateAttr", "1970-07-19T01:02:03.456Z"));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #4
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBegunBy() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    BegunBy filter = ff.begunBy(ff.literal(period), ff.property("dateAttr"));
    Map<String,Object> expected = ImmutableMap.of("term",
            ImmutableMap.of("dateAttr", "1970-07-19T01:02:03.456Z"));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #5
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDuring() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    During filter = ff.during(ff.property("dateAttr"), ff.literal(period));
    Map<String,Object> expected = ImmutableMap.of("range", ImmutableMap.of("dateAttr", 
            ImmutableMap.of("gt", "1970-07-19T01:02:03.456Z", "lt", "1970-07-19T07:08:09.101Z")));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #6
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testEnds() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    Ends filter = ff.ends(ff.property("dateAttr"), ff.literal(period));
    Map<String,Object> expected = ImmutableMap.of("term",
            ImmutableMap.of("dateAttr", "1970-07-19T07:08:09.101Z"));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #7
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testEndedBy() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    EndedBy filter = ff.endedBy(ff.literal(period), ff.property("dateAttr"));
    Map<String,Object> expected = ImmutableMap.of("term",
            ImmutableMap.of("dateAttr", "1970-07-19T07:08:09.101Z"));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #8
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testTContains() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    TContains filter = ff.tcontains(ff.literal(period), ff.property("dateAttr"));
    Map<String,Object> expected = ImmutableMap.of("range", ImmutableMap.of("dateAttr", 
            ImmutableMap.of("gt", "1970-07-19T01:02:03.456Z", "lt", "1970-07-19T07:08:09.101Z")));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #9
Source File: TimePeriod.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Decode a DefaultPeriod object.
 *
 * @param objValue the obj value
 */
public void decode(DefaultPeriod objValue) {
    DefaultPeriod defaultPeriod = objValue;
    Instant beginning = defaultPeriod.getBeginning();
    Duration startDuration = new Duration();
    startDuration.setDate(
            beginning.getPosition().getDate().toInstant().atZone(ZoneId.systemDefault()));
    setStart(startDuration);

    Instant localEnd = defaultPeriod.getEnding();
    Duration endDuration = new Duration();
    endDuration.setDate(
            localEnd.getPosition().getDate().toInstant().atZone(ZoneId.systemDefault()));
    setEnd(endDuration);
}
 
Example #10
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAfterFilterPeriod() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);
    After filter = ff.after(ff.property("dateAttr"), ff.literal(period));
    Map<String,Object> expected = ImmutableMap.of("range",
            ImmutableMap.of("dateAttr", ImmutableMap.of("gt", "1970-07-19T07:08:09.101Z")));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #11
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAfterFilterPeriodSwapped() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);
    After filter = ff.after(ff.literal(period), ff.property("dateAttr"));
    Map<String,Object> expected = ImmutableMap.of("range",
            ImmutableMap.of("dateAttr", ImmutableMap.of("lt", "1970-07-19T01:02:03.456Z")));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #12
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected=IllegalArgumentException.class)
public void testBeginsWithSwap() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    Begins filter = ff.begins(ff.literal(period), ff.property("dateAttr"));

    builder.visit(filter, null);
}
 
Example #13
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected=IllegalArgumentException.class)
public void testTEqualsWithPeriod() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    TEquals filter = ff.tequals(ff.property("dateAttr"), ff.literal(period));

    builder.visit(filter, null);
}
 
Example #14
Source File: TimeUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
/**
 * @param startTimeMillis start time (inclusive)
 * @param endTimeMillis end time (exclusive)
 * @param singleTimeField
 * @return the during filter
 */
public static Filter toDuringFilter(
    final long startTimeMillis,
    final long endTimeMillis,
    final String singleTimeField) {
  final FilterFactory2 factory = CommonFactoryFinder.getFilterFactory2();
  final Position ip1 = new DefaultPosition(new Date(startTimeMillis - 1));
  final Position ip2 = new DefaultPosition(new Date(endTimeMillis));
  final Period period = new DefaultPeriod(new DefaultInstant(ip1), new DefaultInstant(ip2));
  return factory.during(factory.property(singleTimeField), factory.literal(period));
}
 
Example #15
Source File: ElasticTestSupport.java    From elasticgeo with GNU General Public License v3.0 4 votes vote down vote up
Period period(String d1, String d2) throws ParseException {
    return new DefaultPeriod(instant(d1), instant(d2));
}