类org.joda.time.ReadableInterval源码实例Demo

下面列出了怎么用org.joda.time.ReadableInterval的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: astor   文件: BaseInterval.java
/**
 * Constructs a time interval converting or copying from another object
 * that describes an interval.
 * 
 * @param interval  the time interval to copy
 * @param chrono  the chronology to use, null means let converter decide
 * @throws IllegalArgumentException if the interval is invalid
 */
protected BaseInterval(Object interval, Chronology chrono) {
    super();
    IntervalConverter converter = ConverterManager.getInstance().getIntervalConverter(interval);
    if (converter.isReadableInterval(interval, chrono)) {
        ReadableInterval input = (ReadableInterval) interval;
        iChronology = (chrono != null ? chrono : input.getChronology());
        iStartMillis = input.getStartMillis();
        iEndMillis = input.getEndMillis();
    } else if (this instanceof ReadWritableInterval) {
        converter.setInto((ReadWritableInterval) this, interval, chrono);
    } else {
        MutableInterval mi = new MutableInterval();
        converter.setInto(mi, interval, chrono);
        iChronology = mi.getChronology();
        iStartMillis = mi.getStartMillis();
        iEndMillis = mi.getEndMillis();
    }
    checkInterval(iStartMillis, iEndMillis);
}
 
源代码2 项目: astor   文件: TestConverterManager.java
public void testGetDurationConverter() {
    DurationConverter c = ConverterManager.getInstance().getDurationConverter(new Long(0L));
    assertEquals(Long.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getDurationConverter(new Duration(123L));
    assertEquals(ReadableDuration.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getDurationConverter(new Interval(0L, 1000L));
    assertEquals(ReadableInterval.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getDurationConverter("");
    assertEquals(String.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getDurationConverter(null);
    assertEquals(null, c.getSupportedType());
    
    try {
        ConverterManager.getInstance().getDurationConverter(Boolean.TRUE);
        fail();
    } catch (IllegalArgumentException ex) {}
}
 
源代码3 项目: astor   文件: TestConverterManager.java
public void testGetPeriodConverter() {
    PeriodConverter c = ConverterManager.getInstance().getPeriodConverter(new Period(1, 2, 3, 4, 5, 6, 7, 8));
    assertEquals(ReadablePeriod.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getPeriodConverter(new Duration(123L));
    assertEquals(ReadableDuration.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getPeriodConverter(new Interval(0L, 1000L));
    assertEquals(ReadableInterval.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getPeriodConverter("");
    assertEquals(String.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getPeriodConverter(null);
    assertEquals(null, c.getSupportedType());
    
    try {
        ConverterManager.getInstance().getPeriodConverter(Boolean.TRUE);
        fail();
    } catch (IllegalArgumentException ex) {}
}
 
源代码4 项目: astor   文件: BaseInterval.java
/**
 * Constructs a time interval converting or copying from another object
 * that describes an interval.
 * 
 * @param interval  the time interval to copy
 * @param chrono  the chronology to use, null means let converter decide
 * @throws IllegalArgumentException if the interval is invalid
 */
protected BaseInterval(Object interval, Chronology chrono) {
    super();
    IntervalConverter converter = ConverterManager.getInstance().getIntervalConverter(interval);
    if (converter.isReadableInterval(interval, chrono)) {
        ReadableInterval input = (ReadableInterval) interval;
        iChronology = (chrono != null ? chrono : input.getChronology());
        iStartMillis = input.getStartMillis();
        iEndMillis = input.getEndMillis();
    } else if (this instanceof ReadWritableInterval) {
        converter.setInto((ReadWritableInterval) this, interval, chrono);
    } else {
        MutableInterval mi = new MutableInterval();
        converter.setInto(mi, interval, chrono);
        iChronology = mi.getChronology();
        iStartMillis = mi.getStartMillis();
        iEndMillis = mi.getEndMillis();
    }
    checkInterval(iStartMillis, iEndMillis);
}
 
源代码5 项目: astor   文件: TestConverterManager.java
public void testGetDurationConverter() {
    DurationConverter c = ConverterManager.getInstance().getDurationConverter(new Long(0L));
    assertEquals(Long.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getDurationConverter(new Duration(123L));
    assertEquals(ReadableDuration.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getDurationConverter(new Interval(0L, 1000L));
    assertEquals(ReadableInterval.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getDurationConverter("");
    assertEquals(String.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getDurationConverter(null);
    assertEquals(null, c.getSupportedType());
    
    try {
        ConverterManager.getInstance().getDurationConverter(Boolean.TRUE);
        fail();
    } catch (IllegalArgumentException ex) {}
}
 
源代码6 项目: astor   文件: TestConverterManager.java
public void testGetPeriodConverter() {
    PeriodConverter c = ConverterManager.getInstance().getPeriodConverter(new Period(1, 2, 3, 4, 5, 6, 7, 8));
    assertEquals(ReadablePeriod.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getPeriodConverter(new Duration(123L));
    assertEquals(ReadableDuration.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getPeriodConverter(new Interval(0L, 1000L));
    assertEquals(ReadableInterval.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getPeriodConverter("");
    assertEquals(String.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getPeriodConverter(null);
    assertEquals(null, c.getSupportedType());
    
    try {
        ConverterManager.getInstance().getPeriodConverter(Boolean.TRUE);
        fail();
    } catch (IllegalArgumentException ex) {}
}
 
源代码7 项目: jfixture   文件: ReadableIntervalRelay.java
@Override
public Object create(Object request, SpecimenContext context) {
    if (!(request.equals(ReadableInterval.class) || request.equals(ReadWritableInterval.class)))
        return new NoSpecimen();

    Interval interval = (Interval) context.resolve(Interval.class);
    return new MutableInterval(interval);
}
 
@Test
public void creates_instance_of_ReadableInterval() {
    ReadableInterval interval = fixture.create(ReadableInterval.class);
    assertThat(interval, notNullValue());
    assertThat(interval.getStart().toDate(), is(date));
    assertThat(interval.getEnd().toDate(), is(secondDate));
}
 
源代码9 项目: astor   文件: AbstractInterval.java
/**
 * Is this time interval entirely after the specified interval.
 * <p>
 * Intervals are inclusive of the start instant and exclusive of the end.
 * Only the end time of the specified interval is used in the comparison.
 * 
 * @param interval  the interval to compare to, null means now
 * @return true if this time interval is after the interval specified
 */
public boolean isAfter(ReadableInterval interval) {
    long endMillis;
    if (interval == null) {
        endMillis = DateTimeUtils.currentTimeMillis();
    } else {
        endMillis = interval.getEndMillis();
    }
    return (getStartMillis() >= endMillis);
}
 
源代码10 项目: astor   文件: AbstractInterval.java
/**
 * Compares this object with the specified object for equality based
 * on start and end millis plus the chronology.
 * All ReadableInterval instances are accepted.
 * <p>
 * To compare the duration of two time intervals, use {@link #toDuration()}
 * to get the durations and compare those.
 *
 * @param readableInterval  a readable interval to check against
 * @return true if the intervals are equal comparing the start millis,
 *  end millis and chronology
 */
public boolean equals(Object readableInterval) {
    if (this == readableInterval) {
        return true;
    }
    if (readableInterval instanceof ReadableInterval == false) {
        return false;
    }
    ReadableInterval other = (ReadableInterval) readableInterval;
    return 
        getStartMillis() == other.getStartMillis() &&
        getEndMillis() == other.getEndMillis() &&
        FieldUtils.equals(getChronology(), other.getChronology());
}
 
源代码11 项目: astor   文件: ReadableIntervalConverter.java
/**
 * Sets the values of the mutable duration from the specified interval.
 * 
 * @param writablePeriod  the period to modify
 * @param object  the interval to set from
 * @param chrono  the chronology to use
 */
public void setInto(ReadWritablePeriod writablePeriod, Object object, Chronology chrono) {
    ReadableInterval interval = (ReadableInterval) object;
    chrono = (chrono != null ? chrono : DateTimeUtils.getIntervalChronology(interval));
    long start = interval.getStartMillis();
    long end = interval.getEndMillis();
    int[] values = chrono.get(writablePeriod, start, end);
    for (int i = 0; i < values.length; i++) {
        writablePeriod.setValue(i, values[i]);
    }
}
 
源代码12 项目: astor   文件: ReadableIntervalConverter.java
/**
 * Extracts interval endpoint values from an object of this converter's
 * type, and sets them into the given ReadWritableInterval.
 *
 * @param writableInterval interval to get modified, not null
 * @param object  the object to convert, must not be null
 * @param chrono  the chronology to use, may be null
 * @throws ClassCastException if the object is invalid
 */
public void setInto(ReadWritableInterval writableInterval, Object object, Chronology chrono) {
    ReadableInterval input = (ReadableInterval) object;
    writableInterval.setInterval(input);
    if (chrono != null) {
        writableInterval.setChronology(chrono);
    } else {
        writableInterval.setChronology(input.getChronology());
    }
}
 
源代码13 项目: astor   文件: AbstractInterval.java
/**
 * Is this time interval entirely after the specified interval.
 * <p>
 * Intervals are inclusive of the start instant and exclusive of the end.
 * Only the end time of the specified interval is used in the comparison.
 * 
 * @param interval  the interval to compare to, null means now
 * @return true if this time interval is after the interval specified
 */
public boolean isAfter(ReadableInterval interval) {
    long endMillis;
    if (interval == null) {
        endMillis = DateTimeUtils.currentTimeMillis();
    } else {
        endMillis = interval.getEndMillis();
    }
    return (getStartMillis() >= endMillis);
}
 
源代码14 项目: astor   文件: AbstractInterval.java
/**
 * Compares this object with the specified object for equality based
 * on start and end millis plus the chronology.
 * All ReadableInterval instances are accepted.
 * <p>
 * To compare the duration of two time intervals, use {@link #toDuration()}
 * to get the durations and compare those.
 *
 * @param readableInterval  a readable interval to check against
 * @return true if the start and end millis are equal
 */
public boolean equals(Object readableInterval) {
    if (this == readableInterval) {
        return true;
    }
    if (readableInterval instanceof ReadableInterval == false) {
        return false;
    }
    ReadableInterval other = (ReadableInterval) readableInterval;
    return 
        getStartMillis() == other.getStartMillis() &&
        getEndMillis() == other.getEndMillis() &&
        FieldUtils.equals(getChronology(), other.getChronology());
}
 
源代码15 项目: astor   文件: ReadableIntervalConverter.java
/**
 * Sets the values of the mutable duration from the specified interval.
 * 
 * @param writablePeriod  the period to modify
 * @param object  the interval to set from
 * @param chrono  the chronology to use
 */
public void setInto(ReadWritablePeriod writablePeriod, Object object, Chronology chrono) {
    ReadableInterval interval = (ReadableInterval) object;
    chrono = (chrono != null ? chrono : DateTimeUtils.getIntervalChronology(interval));
    long start = interval.getStartMillis();
    long end = interval.getEndMillis();
    int[] values = chrono.get(writablePeriod, start, end);
    for (int i = 0; i < values.length; i++) {
        writablePeriod.setValue(i, values[i]);
    }
}
 
源代码16 项目: astor   文件: ReadableIntervalConverter.java
/**
 * Extracts interval endpoint values from an object of this converter's
 * type, and sets them into the given ReadWritableInterval.
 *
 * @param writableInterval interval to get modified, not null
 * @param object  the object to convert, must not be null
 * @param chrono  the chronology to use, may be null
 * @throws ClassCastException if the object is invalid
 */
public void setInto(ReadWritableInterval writableInterval, Object object, Chronology chrono) {
    ReadableInterval input = (ReadableInterval) object;
    writableInterval.setInterval(input);
    if (chrono != null) {
        writableInterval.setChronology(chrono);
    } else {
        writableInterval.setChronology(input.getChronology());
    }
}
 
源代码17 项目: astor   文件: ReadableIntervalConverter.java
/**
 * Returns ReadableInterval.class.
 */
public Class<?> getSupportedType() {
    return ReadableInterval.class;
}
 
源代码18 项目: astor   文件: TestReadableIntervalConverter.java
public void testSupportedType() throws Exception {
    assertEquals(ReadableInterval.class, ReadableIntervalConverter.INSTANCE.getSupportedType());
}
 
源代码19 项目: astor   文件: ReadableIntervalConverter.java
/**
 * Returns ReadableInterval.class.
 */
public Class<?> getSupportedType() {
    return ReadableInterval.class;
}
 
源代码20 项目: astor   文件: TestReadableIntervalConverter.java
public void testSupportedType() throws Exception {
    assertEquals(ReadableInterval.class, ReadableIntervalConverter.INSTANCE.getSupportedType());
}
 
源代码21 项目: activitystreams   文件: GsonWrapper.java
/**
 * Method initGsonBuilder.
 * @param builder Builder

 * @return GsonBuilder */
private static GsonBuilder initGsonBuilder(
  Builder builder, 
  Schema schema, 
  ASObjectAdapter base,
  Iterable<AdapterEntry<?>> adapters) {
  
  GsonBuilder gson = new GsonBuilder()
  .registerTypeHierarchyAdapter(TypeValue.class, new TypeValueAdapter(schema))
  .registerTypeHierarchyAdapter(LinkValue.class, new LinkValueAdapter(schema))
  .registerTypeHierarchyAdapter(Iterable.class, ITERABLE)
  .registerTypeHierarchyAdapter(ASObject.class, base)
  .registerTypeHierarchyAdapter(Collection.class, base)
  .registerTypeHierarchyAdapter(Activity.class, base)
  .registerTypeHierarchyAdapter(NLV.class, NLV)
  .registerTypeHierarchyAdapter(ActionsValue.class, ACTIONS)
  .registerTypeHierarchyAdapter(Optional.class, OPTIONAL)
  .registerTypeHierarchyAdapter(Range.class, RANGE)
  .registerTypeHierarchyAdapter(Table.class, TABLE)
  .registerTypeHierarchyAdapter(LazilyParsedNumber.class, NUMBER)
  .registerTypeHierarchyAdapter(LazilyParsedNumberComparable.class, NUMBER)
  .registerTypeHierarchyAdapter(ReadableDuration.class, DURATION)
  .registerTypeHierarchyAdapter(ReadablePeriod.class, PERIOD)
  .registerTypeHierarchyAdapter(ReadableInterval.class, INTERVAL)
  .registerTypeAdapter(
    Activity.Status.class, 
    forEnum(
      Activity.Status.class, 
      Activity.Status.OTHER))
  .registerTypeAdapter(Date.class, DATE)
  .registerTypeAdapter(DateTime.class, DATETIME)
  .registerTypeAdapter(MediaType.class, MIMETYPE)
  .registerTypeHierarchyAdapter(Multimap.class, MULTIMAP);
  
  for (AdapterEntry<?> entry : adapters) {
    if (entry.hier)
      gson.registerTypeHierarchyAdapter(
        entry.type, 
        entry.adapter!=null ?
          entry.adapter : base);
    else
      gson.registerTypeAdapter(
        entry.type, 
        entry.adapter!=null ? 
          entry.adapter:base);
  }
  
  return gson;

}
 
源代码22 项目: astor   文件: AbstractInterval.java
/**
 * Does this time interval contain the specified time interval.
 * <p>
 * Non-zero duration intervals are inclusive of the start instant and
 * exclusive of the end. The other interval is contained if this interval
 * wholly contains, starts, finishes or equals it.
 * A zero duration interval cannot contain anything.
 * <p>
 * When two intervals are compared the result is one of three states:
 * (a) they abut, (b) there is a gap between them, (c) they overlap.
 * The <code>contains</code> method is not related to these states.
 * In particular, a zero duration interval is contained at the start of
 * a larger interval, but does not overlap (it abuts instead).
 * <p>
 * For example:
 * <pre>
 * [09:00 to 10:00) contains [09:00 to 10:00)  = true
 * [09:00 to 10:00) contains [09:00 to 09:30)  = true
 * [09:00 to 10:00) contains [09:30 to 10:00)  = true
 * [09:00 to 10:00) contains [09:15 to 09:45)  = true
 * [09:00 to 10:00) contains [09:00 to 09:00)  = true
 * 
 * [09:00 to 10:00) contains [08:59 to 10:00)  = false (otherStart before thisStart)
 * [09:00 to 10:00) contains [09:00 to 10:01)  = false (otherEnd after thisEnd)
 * [09:00 to 10:00) contains [10:00 to 10:00)  = false (otherStart equals thisEnd)
 * 
 * [14:00 to 14:00) contains [14:00 to 14:00)  = false (zero duration contains nothing)
 * </pre>
 * Passing in a <code>null</code> parameter will have the same effect as
 * calling {@link #containsNow()}.
 *
 * @param interval  the time interval to compare to, null means a zero duration interval now
 * @return true if this time interval contains the time interval
 */
public boolean contains(ReadableInterval interval) {
    if (interval == null) {
        return containsNow();
    }
    long otherStart = interval.getStartMillis();
    long otherEnd = interval.getEndMillis();
    long thisStart = getStartMillis();
    long thisEnd = getEndMillis();
    return (thisStart <= otherStart && otherStart < thisEnd && otherEnd <= thisEnd);
}
 
源代码23 项目: astor   文件: AbstractInterval.java
/**
 * Does this time interval overlap the specified time interval.
 * <p>
 * Intervals are inclusive of the start instant and exclusive of the end.
 * An interval overlaps another if it shares some common part of the
 * datetime continuum. 
 * <p>
 * When two intervals are compared the result is one of three states:
 * (a) they abut, (b) there is a gap between them, (c) they overlap.
 * The abuts state takes precedence over the other two, thus a zero duration
 * interval at the start of a larger interval abuts and does not overlap.
 * <p>
 * For example:
 * <pre>
 * [09:00 to 10:00) overlaps [08:00 to 08:30)  = false (completely before)
 * [09:00 to 10:00) overlaps [08:00 to 09:00)  = false (abuts before)
 * [09:00 to 10:00) overlaps [08:00 to 09:30)  = true
 * [09:00 to 10:00) overlaps [08:00 to 10:00)  = true
 * [09:00 to 10:00) overlaps [08:00 to 11:00)  = true
 * 
 * [09:00 to 10:00) overlaps [09:00 to 09:00)  = false (abuts before)
 * [09:00 to 10:00) overlaps [09:00 to 09:30)  = true
 * [09:00 to 10:00) overlaps [09:00 to 10:00)  = true
 * [09:00 to 10:00) overlaps [09:00 to 11:00)  = true
 * 
 * [09:00 to 10:00) overlaps [09:30 to 09:30)  = true
 * [09:00 to 10:00) overlaps [09:30 to 10:00)  = true
 * [09:00 to 10:00) overlaps [09:30 to 11:00)  = true
 * 
 * [09:00 to 10:00) overlaps [10:00 to 10:00)  = false (abuts after)
 * [09:00 to 10:00) overlaps [10:00 to 11:00)  = false (abuts after)
 * 
 * [09:00 to 10:00) overlaps [10:30 to 11:00)  = false (completely after)
 * 
 * [14:00 to 14:00) overlaps [14:00 to 14:00)  = false (abuts before and after)
 * [14:00 to 14:00) overlaps [13:00 to 15:00)  = true
 * </pre>
 *
 * @param interval  the time interval to compare to, null means a zero length interval now
 * @return true if the time intervals overlap
 */
public boolean overlaps(ReadableInterval interval) {
    long thisStart = getStartMillis();
    long thisEnd = getEndMillis();
    if (interval == null) {
        long now = DateTimeUtils.currentTimeMillis();
        return (thisStart < now && now < thisEnd);
    }  else {
        long otherStart = interval.getStartMillis();
        long otherEnd = interval.getEndMillis();
        return (thisStart < otherEnd && otherStart < thisEnd);
    }
}
 
源代码24 项目: astor   文件: AbstractInterval.java
/**
 * Is this time interval entirely before the specified instant.
 * <p>
 * Intervals are inclusive of the start instant and exclusive of the end.
 * 
 * @param interval  the interval to compare to, null means now
 * @return true if this time interval is before the interval specified
 */
public boolean isBefore(ReadableInterval interval) {
    if (interval == null) {
        return isBeforeNow();
    }
    return isBefore(interval.getStartMillis());
}
 
源代码25 项目: astor   文件: AbstractInterval.java
/**
 * Does this time interval contain the specified time interval.
 * <p>
 * Non-zero duration intervals are inclusive of the start instant and
 * exclusive of the end. The other interval is contained if this interval
 * wholly contains, starts, finishes or equals it.
 * A zero duration interval cannot contain anything.
 * <p>
 * When two intervals are compared the result is one of three states:
 * (a) they abut, (b) there is a gap between them, (c) they overlap.
 * The <code>contains</code> method is not related to these states.
 * In particular, a zero duration interval is contained at the start of
 * a larger interval, but does not overlap (it abuts instead).
 * <p>
 * For example:
 * <pre>
 * [09:00 to 10:00) contains [09:00 to 10:00)  = true
 * [09:00 to 10:00) contains [09:00 to 09:30)  = true
 * [09:00 to 10:00) contains [09:30 to 10:00)  = true
 * [09:00 to 10:00) contains [09:15 to 09:45)  = true
 * [09:00 to 10:00) contains [09:00 to 09:00)  = true
 * 
 * [09:00 to 10:00) contains [08:59 to 10:00)  = false (otherStart before thisStart)
 * [09:00 to 10:00) contains [09:00 to 10:01)  = false (otherEnd after thisEnd)
 * [09:00 to 10:00) contains [10:00 to 10:00)  = false (otherStart equals thisEnd)
 * 
 * [14:00 to 14:00) contains [14:00 to 14:00)  = false (zero duration contains nothing)
 * </pre>
 * Passing in a <code>null</code> parameter will have the same effect as
 * calling {@link #containsNow()}.
 *
 * @param interval  the time interval to compare to, null means a zero duration interval now
 * @return true if this time interval contains the time interval
 */
public boolean contains(ReadableInterval interval) {
    if (interval == null) {
        return containsNow();
    }
    long otherStart = interval.getStartMillis();
    long otherEnd = interval.getEndMillis();
    long thisStart = getStartMillis();
    long thisEnd = getEndMillis();
    return (thisStart <= otherStart && otherStart < thisEnd && otherEnd <= thisEnd);
}
 
源代码26 项目: astor   文件: AbstractInterval.java
/**
 * Does this time interval overlap the specified time interval.
 * <p>
 * Intervals are inclusive of the start instant and exclusive of the end.
 * An interval overlaps another if it shares some common part of the
 * datetime continuum. 
 * <p>
 * When two intervals are compared the result is one of three states:
 * (a) they abut, (b) there is a gap between them, (c) they overlap.
 * The abuts state takes precedence over the other two, thus a zero duration
 * interval at the start of a larger interval abuts and does not overlap.
 * <p>
 * For example:
 * <pre>
 * [09:00 to 10:00) overlaps [08:00 to 08:30)  = false (completely before)
 * [09:00 to 10:00) overlaps [08:00 to 09:00)  = false (abuts before)
 * [09:00 to 10:00) overlaps [08:00 to 09:30)  = true
 * [09:00 to 10:00) overlaps [08:00 to 10:00)  = true
 * [09:00 to 10:00) overlaps [08:00 to 11:00)  = true
 * 
 * [09:00 to 10:00) overlaps [09:00 to 09:00)  = false (abuts before)
 * [09:00 to 10:00) overlaps [09:00 to 09:30)  = true
 * [09:00 to 10:00) overlaps [09:00 to 10:00)  = true
 * [09:00 to 10:00) overlaps [09:00 to 11:00)  = true
 * 
 * [09:00 to 10:00) overlaps [09:30 to 09:30)  = true
 * [09:00 to 10:00) overlaps [09:30 to 10:00)  = true
 * [09:00 to 10:00) overlaps [09:30 to 11:00)  = true
 * 
 * [09:00 to 10:00) overlaps [10:00 to 10:00)  = false (abuts after)
 * [09:00 to 10:00) overlaps [10:00 to 11:00)  = false (abuts after)
 * 
 * [09:00 to 10:00) overlaps [10:30 to 11:00)  = false (completely after)
 * 
 * [14:00 to 14:00) overlaps [14:00 to 14:00)  = false (abuts before and after)
 * [14:00 to 14:00) overlaps [13:00 to 15:00)  = true
 * </pre>
 *
 * @param interval  the time interval to compare to, null means a zero length interval now
 * @return true if the time intervals overlap
 */
public boolean overlaps(ReadableInterval interval) {
    long thisStart = getStartMillis();
    long thisEnd = getEndMillis();
    if (interval == null) {
        long now = DateTimeUtils.currentTimeMillis();
        return (thisStart < now && now < thisEnd);
    }  else {
        long otherStart = interval.getStartMillis();
        long otherEnd = interval.getEndMillis();
        return (thisStart < otherEnd && otherStart < thisEnd);
    }
}
 
源代码27 项目: astor   文件: AbstractInterval.java
/**
 * Is this time interval entirely before the specified instant.
 * <p>
 * Intervals are inclusive of the start instant and exclusive of the end.
 * 
 * @param interval  the interval to compare to, null means now
 * @return true if this time interval is before the interval specified
 */
public boolean isBefore(ReadableInterval interval) {
    if (interval == null) {
        return isBeforeNow();
    }
    return isBefore(interval.getStartMillis());
}
 
源代码28 项目: astor   文件: AbstractInterval.java
/**
 * Is this interval equal to the specified interval ignoring the chronology.
 * <p>
 * This compares the underlying instants, ignoring the chronology.
 *
 * @param other  a readable interval to check against
 * @return true if the intervals are equal comparing the start and end millis
 * @since 2.3
 */
public boolean isEqual(ReadableInterval other) {
    return getStartMillis() == other.getStartMillis() &&
            getEndMillis() == other.getEndMillis();
}
 
源代码29 项目: astor   文件: ReadableIntervalConverter.java
/**
 * Gets the millisecond length of the interval.
 * 
 * @param object  the interval
 */
public long getDurationMillis(Object object) {
    return (((ReadableInterval) object)).toDurationMillis();
}
 
源代码30 项目: astor   文件: ReadableIntervalConverter.java
/**
 * Gets the millisecond length of the interval.
 * 
 * @param object  the interval
 */
public long getDurationMillis(Object object) {
    return (((ReadableInterval) object)).toDurationMillis();
}
 
 类所在包
 同包方法