コード例 #1
0
 public void testConstructor_long_long2() throws Throwable {
   DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
   Interval test = new Interval(dt1.getMillis(), dt1.getMillis());
   assertEquals(dt1.getMillis(), test.getStartMillis());
   assertEquals(dt1.getMillis(), test.getEndMillis());
   assertEquals(ISOChronology.getInstance(), test.getChronology());
 }
コード例 #2
0
 // -----------------------------------------------------------------------
 public void testConstructor_Object1() throws Throwable {
   DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
   DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
   Interval test = new Interval(dt1.toString() + '/' + dt2.toString());
   assertEquals(dt1.getMillis(), test.getStartMillis());
   assertEquals(dt2.getMillis(), test.getEndMillis());
 }
コード例 #3
0
 public void testConstructor_RI_RI2() throws Throwable {
   Instant dt1 = new Instant(new DateTime(2004, 6, 9, 0, 0, 0, 0));
   Instant dt2 = new Instant(new DateTime(2005, 7, 10, 1, 1, 1, 1));
   Interval test = new Interval(dt1, dt2);
   assertEquals(dt1.getMillis(), test.getStartMillis());
   assertEquals(dt2.getMillis(), test.getEndMillis());
 }
コード例 #4
0
  public void testConstructor_Object5() throws Throwable {
    IntervalConverter oldConv = ConverterManager.getInstance().getIntervalConverter("");
    IntervalConverter conv =
        new IntervalConverter() {
          public boolean isReadableInterval(Object object, Chronology chrono) {
            return false;
          }

          public void setInto(ReadWritableInterval interval, Object object, Chronology chrono) {
            interval.setChronology(chrono);
            interval.setInterval(1234L, 5678L);
          }

          public Class<?> getSupportedType() {
            return String.class;
          }
        };
    try {
      ConverterManager.getInstance().addIntervalConverter(conv);
      DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
      DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
      Interval test = new Interval(dt1.toString() + '/' + dt2.toString());
      assertEquals(1234L, test.getStartMillis());
      assertEquals(5678L, test.getEndMillis());
    } finally {
      ConverterManager.getInstance().addIntervalConverter(oldConv);
    }
  }
コード例 #5
0
 /**
  * compareTo
  *
  * @param that a {@link org.opennms.features.poller.remote.gwt.client.utils.Interval} object.
  * @return a int.
  */
 public int compareTo(final Interval that) {
   if (that == null) return -1;
   return new CompareToBuilder()
       .append(this.getStartMillis(), that.getStartMillis())
       .append(this.getEndMillis(), that.getEndMillis())
       .toComparison();
 }
コード例 #6
0
  public void testConstructor_Object6() throws Throwable {
    IntervalConverter oldConv =
        ConverterManager.getInstance().getIntervalConverter(new Interval(0L, 0L));
    IntervalConverter conv =
        new IntervalConverter() {
          public boolean isReadableInterval(Object object, Chronology chrono) {
            return false;
          }

          public void setInto(ReadWritableInterval interval, Object object, Chronology chrono) {
            interval.setChronology(chrono);
            interval.setInterval(1234L, 5678L);
          }

          public Class<?> getSupportedType() {
            return ReadableInterval.class;
          }
        };
    try {
      ConverterManager.getInstance().addIntervalConverter(conv);
      Interval base = new Interval(-1000L, 1000L);
      Interval test = new Interval(base);
      assertEquals(1234L, test.getStartMillis());
      assertEquals(5678L, test.getEndMillis());
    } finally {
      ConverterManager.getInstance().addIntervalConverter(oldConv);
    }
  }
コード例 #7
0
 public void testConstructor_long_long_minMax() throws Throwable {
   Interval test = new Interval(Long.MIN_VALUE, Long.MAX_VALUE);
   assertEquals(Long.MIN_VALUE, test.getStartMillis());
   assertEquals(Long.MAX_VALUE, test.getEndMillis());
   assertEquals(new DateTime(Long.MIN_VALUE), test.getStart());
   assertEquals(new DateTime(Long.MAX_VALUE), test.getEnd());
   assertEquals(ISOChronology.getInstance(), test.getChronology());
   assertEquals(test, test.toInterval());
   assertEquals(
       "-292275055-05-16T16:56:25.192+00:09:21/292278994-08-17T07:12:55.807Z", test.toString());
   try {
     test.toDuration();
     fail();
   } catch (ArithmeticException ex) {
   }
   try {
     test.toDurationMillis();
     fail();
   } catch (ArithmeticException ex) {
   }
   try {
     test.toPeriod();
     fail();
   } catch (RuntimeException ex) {
   }
 }
コード例 #8
0
 public void testConstructor_RI_RI_chronoStart() throws Throwable {
   DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0, GJChronology.getInstance());
   DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
   Interval test = new Interval(dt1, dt2);
   assertEquals(dt1.getMillis(), test.getStartMillis());
   assertEquals(dt2.getMillis(), test.getEndMillis());
   assertEquals(GJChronology.getInstance(), test.getChronology());
 }
コード例 #9
0
 public void testConstructor_RI_RI_instant() throws Throwable {
   Instant dt1 = new Instant(12345678L);
   Instant dt2 = new Instant(22345678L);
   Interval test = new Interval(dt1, dt2);
   assertEquals(12345678L, test.getStartMillis());
   assertEquals(22345678L, test.getEndMillis());
   assertEquals(ISOChronology.getInstanceUTC(), test.getChronology());
 }
コード例 #10
0
 public void testConstructor_RI_RI_zones() throws Throwable {
   DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0, LONDON);
   DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1, PARIS);
   Interval test = new Interval(dt1, dt2);
   assertEquals(dt1.getMillis(), test.getStartMillis());
   assertEquals(dt2.getMillis(), test.getEndMillis());
   assertEquals(ISOChronology.getInstance(LONDON), test.getChronology());
 }
コード例 #11
0
  public void testConstructor_Object3() throws Throwable {
    DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
    DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
    MutableInterval base = new MutableInterval(dt1, dt2);

    Interval test = new Interval(base);
    assertEquals(dt1.getMillis(), test.getStartMillis());
    assertEquals(dt2.getMillis(), test.getEndMillis());
  }
コード例 #12
0
  public void testConstructor_Object_Chronology2() throws Throwable {
    DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
    DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
    Interval base = new Interval(dt1, dt2);

    Interval test = new Interval(base, null);
    assertEquals(dt1.getMillis(), test.getStartMillis());
    assertEquals(dt2.getMillis(), test.getEndMillis());
    assertEquals(ISOChronology.getInstance(), test.getChronology());
  }
コード例 #13
0
  public void testConstructor_RP_RI7() throws Throwable {
    Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
    long result = TEST_TIME_NOW;
    result = ISOChronology.getInstance().monthOfYear().add(result, -6);
    result = ISOChronology.getInstance().hourOfDay().add(result, -1);

    Interval test = new Interval(dur, (ReadableInstant) null);
    assertEquals(result, test.getStartMillis());
    assertEquals(TEST_TIME_NOW, test.getEndMillis());
  }
コード例 #14
0
 /**
  * overlaps
  *
  * @param that a {@link org.opennms.features.poller.remote.gwt.client.utils.Interval} object.
  * @return a boolean.
  */
 public boolean overlaps(final Interval that) {
   if (this.getStartMillis() <= that.getStartMillis()
       && this.getEndMillis() >= that.getEndMillis()) {
     // completely surrounds
     return true;
   } else if (this.getStartMillis() >= that.getStartMillis()
       && this.getEndMillis() <= that.getEndMillis()) {
     // completely inside
     return true;
   } else if (this.getStartMillis() <= that.getStartMillis()
       && this.getEndMillis() >= that.getStartMillis()) {
     // overlaps start
     return true;
   } else if (this.getEndMillis() >= that.getEndMillis()
       && this.getStartMillis() <= that.getEndMillis()) {
     // overlaps end
     return true;
   }
   return false;
 }
コード例 #15
0
  public void testConstructor_RD_RI4() throws Throwable {
    long result = TEST_TIME_NOW;
    result = ISOChronology.getInstance().monthOfYear().add(result, -6);
    result = ISOChronology.getInstance().hourOfDay().add(result, -1);

    Duration dur = new Duration(TEST_TIME_NOW - result);

    Interval test = new Interval(dur, (ReadableInstant) null);
    assertEquals(result, test.getStartMillis());
    assertEquals(TEST_TIME_NOW, test.getEndMillis());
  }
コード例 #16
0
  public void testConstructor_RP_RI4() throws Throwable {
    DateTime dt = new DateTime(TEST_TIME_NOW);
    Period dur = new Period(1 * DateTimeConstants.MILLIS_PER_HOUR + 23L);
    long result = TEST_TIME_NOW;
    result = ISOChronology.getInstance().hours().add(result, -1);
    result = ISOChronology.getInstance().millis().add(result, -23);

    Interval test = new Interval(dur, dt);
    assertEquals(result, test.getStartMillis());
    assertEquals(dt.getMillis(), test.getEndMillis());
  }
コード例 #17
0
  // -----------------------------------------------------------------------
  public void testConstructor_RP_RI1() throws Throwable {
    DateTime dt = new DateTime(TEST_TIME_NOW);
    Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
    long result = TEST_TIME_NOW;
    result = ISOChronology.getInstance().months().add(result, -6);
    result = ISOChronology.getInstance().hours().add(result, -1);

    Interval test = new Interval(dur, dt);
    assertEquals(result, test.getStartMillis());
    assertEquals(dt.getMillis(), test.getEndMillis());
  }
コード例 #18
0
  public void testConstructor_RI_RP2() throws Throwable {
    Instant dt = new Instant(new DateTime(TEST_TIME_NOW));
    Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0);
    long result = TEST_TIME_NOW;
    result = ISOChronology.getInstanceUTC().months().add(result, 6);
    result = ISOChronology.getInstanceUTC().days().add(result, 3);
    result = ISOChronology.getInstanceUTC().hours().add(result, 1);

    Interval test = new Interval(dt, dur);
    assertEquals(dt.getMillis(), test.getStartMillis());
    assertEquals(result, test.getEndMillis());
  }
コード例 #19
0
  // -----------------------------------------------------------------------
  public void testConstructor_RD_RI1() throws Throwable {
    long result = TEST_TIME_NOW;
    result = ISOChronology.getInstance().months().add(result, -6);
    result = ISOChronology.getInstance().hours().add(result, -1);

    DateTime dt = new DateTime(TEST_TIME_NOW);
    Duration dur = new Duration(TEST_TIME_NOW - result);

    Interval test = new Interval(dur, dt);
    assertEquals(result, test.getStartMillis());
    assertEquals(dt.getMillis(), test.getEndMillis());
  }
コード例 #20
0
  public void testConstructor_RP_RI3() throws Throwable {
    DateTime dt = new DateTime(TEST_TIME_NOW, CopticChronology.getInstanceUTC());
    Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0, PeriodType.standard());
    long result = TEST_TIME_NOW;
    result = CopticChronology.getInstanceUTC().months().add(result, -6);
    result = CopticChronology.getInstanceUTC().days().add(result, -3);
    result = CopticChronology.getInstanceUTC().hours().add(result, -1);

    Interval test = new Interval(dur, dt);
    assertEquals(result, test.getStartMillis());
    assertEquals(dt.getMillis(), test.getEndMillis());
  }
コード例 #21
0
 public void testConstructor_long_long_max() throws Throwable {
   Interval test = new Interval(Long.MAX_VALUE - 9, Long.MAX_VALUE);
   assertEquals(Long.MAX_VALUE - 9, test.getStartMillis());
   assertEquals(Long.MAX_VALUE, test.getEndMillis());
   assertEquals(new DateTime(Long.MAX_VALUE - 9), test.getStart());
   assertEquals(new DateTime(Long.MAX_VALUE), test.getEnd());
   assertEquals(ISOChronology.getInstance(), test.getChronology());
   assertEquals(test, test.toInterval());
   assertEquals("292278994-08-17T07:12:55.798Z/292278994-08-17T07:12:55.807Z", test.toString());
   assertEquals(9, test.toDurationMillis());
   assertEquals(new Duration(9), test.toDuration());
 }
コード例 #22
0
 public void testConstructor_long_long_min() throws Throwable {
   Interval test = new Interval(Long.MIN_VALUE, Long.MIN_VALUE + 9);
   assertEquals(Long.MIN_VALUE, test.getStartMillis());
   assertEquals(Long.MIN_VALUE + 9, test.getEndMillis());
   assertEquals(new DateTime(Long.MIN_VALUE), test.getStart());
   assertEquals(new DateTime(Long.MIN_VALUE + 9), test.getEnd());
   assertEquals(ISOChronology.getInstance(), test.getChronology());
   assertEquals(test, test.toInterval());
   assertEquals(
       "-292275055-05-16T16:56:25.192+00:09:21/-292275055-05-16T16:56:25.201+00:09:21",
       test.toString());
   assertEquals(9, test.toDurationMillis());
   assertEquals(new Duration(9), test.toDuration());
   assertEquals(new Period(9), test.toPeriod());
 }
コード例 #23
0
 public void testConstructor_Object4() throws Throwable {
   MockInterval base = new MockInterval();
   Interval test = new Interval(base);
   assertEquals(base.getStartMillis(), test.getStartMillis());
   assertEquals(base.getEndMillis(), test.getEndMillis());
 }
コード例 #24
0
 public void testConstructor_RI_RI4() throws Throwable {
   DateTime dt1 = new DateTime(2000, 6, 9, 0, 0, 0, 0);
   Interval test = new Interval(dt1, (ReadableInstant) null);
   assertEquals(dt1.getMillis(), test.getStartMillis());
   assertEquals(TEST_TIME_NOW, test.getEndMillis());
 }
コード例 #25
0
 public void testConstructor_RI_RI5() throws Throwable {
   DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
   Interval test = new Interval((ReadableInstant) null, dt2);
   assertEquals(TEST_TIME_NOW, test.getStartMillis());
   assertEquals(dt2.getMillis(), test.getEndMillis());
 }
コード例 #26
0
 public void testConstructor_RD_RI3() throws Throwable {
   DateTime dt = new DateTime(TEST_TIME_NOW);
   Interval test = new Interval((ReadableDuration) null, dt);
   assertEquals(dt.getMillis(), test.getStartMillis());
   assertEquals(dt.getMillis(), test.getEndMillis());
 }
コード例 #27
0
 public void testConstructor_RD_RI2() throws Throwable {
   Interval test = new Interval((ReadableDuration) null, (ReadableInstant) null);
   assertEquals(TEST_TIME_NOW, test.getStartMillis());
   assertEquals(TEST_TIME_NOW, test.getEndMillis());
 }
コード例 #28
0
 public void testConstructor_RI_RP6() throws Throwable {
   DateTime dt = new DateTime(TEST_TIME_NOW);
   Interval test = new Interval(dt, (ReadablePeriod) null);
   assertEquals(dt.getMillis(), test.getStartMillis());
   assertEquals(dt.getMillis(), test.getEndMillis());
 }
コード例 #29
0
 public void testConstructor_RI_RI6() throws Throwable {
   DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
   Interval test = new Interval(dt1, dt1);
   assertEquals(dt1.getMillis(), test.getStartMillis());
   assertEquals(dt1.getMillis(), test.getEndMillis());
 }