/** Ensures that the given range use the same element class than this range. */ @SuppressWarnings("unchecked") private Range<? extends T> ensureCompatible(final Range<?> range) throws IllegalArgumentException { ensureNonNull("range", range); ensureCompatible(range.elementClass); return (Range<? extends T>) range; }
/** * Returns {@code true} if this range intersects the given range. * * @param range The range to check for intersection with this range. * @return {@code true} if the given range intersects this range. * @throws IllegalArgumentException is the given range can not be converted to a valid type * through widening conversion. * @see javax.media.jai.util.Range#intersects */ public boolean intersects(final Range<?> range) throws IllegalArgumentException { return intersectsNC(ensureCompatible(range)); }
/** * Returns {@code true} if this range contains fully the given range. * * @param range The range to check for inclusion in this range. * @return {@code true} if the given range is included in this range. * @throws IllegalArgumentException is the given range can not be converted to a valid type * through widening conversion. */ public boolean contains(final Range<?> range) throws IllegalArgumentException { return containsNC(ensureCompatible(range)); }
/** * Returns the intersection between this range and the provided range. * * @param range The range to intersect. * @return The intersection of this range with the provided range. * @throws IllegalArgumentException is the given range can not be converted to a valid type * through widening conversion. * @see javax.media.jai.util.Range#intersect */ public Range<?> intersect(final Range<?> range) throws IllegalArgumentException { return intersectNC(ensureCompatible(range)); }
/** * Returns the union of this range with the given range. * * @param range The range to add to this range. * @return The union of this range with the given range. * @throws IllegalArgumentException is the given range can not be converted to a valid type * through widening conversion. * @see javax.media.jai.util.Range#union */ public Range<?> union(final Range<?> range) throws IllegalArgumentException { return unionNC(ensureCompatible(range)); }
/** * Returns {@code true} if this range contains the given value. A range never contains the * {@code null} value. This is consistent with the {@linkplain Range class javadoc} stating that * null {@linkplain #getMinValue minimum} or {@linkplain #getMaxValue maximum} values are * exclusive. * * @param value The value to check for inclusion in this range. * @return {@code true} if the given value is included in this range. * @throws IllegalArgumentException is the given value can not be converted to a valid type * through widening conversion. */ @SuppressWarnings("unchecked") public boolean contains(final Comparable<?> value) throws IllegalArgumentException { if (value == null) { return false; } ensureCompatible(value.getClass()); return containsNC((Comparable<T>) value); }
/** * Returns the range of values that are in this range but not in the given range. This method * returns an array of length 0, 1 or 2: * * <p> * * <ul> * <li>If the given range contains fully this range, returns an array of length 0. * <li>If the given range is in the middle of this range, then the subtraction results in two * disjoint ranges which will be returned as two elements in the array. * <li>Otherwise returns an array of length 1. * </ul> * * @param range The range to substract. * @return This range without the given range. * @throws IllegalArgumentException is the given range can not be converted to a valid type * through widening conversion. * @see javax.media.jai.util.Range#subtract */ public Range<?>[] subtract(final Range<?> range) throws IllegalArgumentException { return subtractNC(ensureCompatible(range)); }
this.isMaxIncluded = isMaxIncluded && maxValue != null; checkElementClass(); if (minValue != null) ensureCompatible(minValue.getClass()); if (maxValue != null) ensureCompatible(maxValue.getClass());
/** * Returns {@code true} if this range contains fully the given range. * * @param range The range to check for inclusion in this range. * @return {@code true} if the given range is included in this range. * @throws IllegalArgumentException is the given range can not be converted to a valid type * through widening conversion. */ public boolean contains(final Range<?> range) throws IllegalArgumentException { return containsNC(ensureCompatible(range)); }
/** * Returns {@code true} if this range intersects the given range. * * @param range The range to check for intersection with this range. * @return {@code true} if the given range intersects this range. * @throws IllegalArgumentException is the given range can not be converted to a valid type * through widening conversion. * * @see javax.media.jai.util.Range#intersects */ public boolean intersects(final Range<?> range) throws IllegalArgumentException { return intersectsNC(ensureCompatible(range)); }
/** * Ensures that the given range use the same element class than this range. */ @SuppressWarnings("unchecked") private Range<? extends T> ensureCompatible(final Range<?> range) throws IllegalArgumentException { ensureNonNull("range", range); ensureCompatible(range.elementClass); return (Range<? extends T>) range; }
/** * Returns the union of this range with the given range. * * @param range The range to add to this range. * @return The union of this range with the given range. * @throws IllegalArgumentException is the given range can not be converted to a valid type * through widening conversion. * * @see javax.media.jai.util.Range#union */ public Range<?> union(final Range<?> range) throws IllegalArgumentException { return unionNC(ensureCompatible(range)); }
/** * Returns the intersection between this range and the provided range. * * @param range The range to intersect. * @return The intersection of this range with the provided range. * @throws IllegalArgumentException is the given range can not be converted to a valid type * through widening conversion. * * @see javax.media.jai.util.Range#intersect */ public Range<?> intersect(final Range<?> range) throws IllegalArgumentException { return intersectNC(ensureCompatible(range)); }
/** * Returns {@code true} if this range contains the given value. A range never contains the * {@code null} value. This is consistent with the {@linkplain Range class javadoc} stating * that null {@linkplain #getMinValue minimum} or {@linkplain #getMaxValue maximum} values * are exclusive. * * @param value The value to check for inclusion in this range. * @return {@code true} if the given value is included in this range. * @throws IllegalArgumentException is the given value can not be converted to a valid type * through widening conversion. */ public boolean contains(final Comparable<?> value) throws IllegalArgumentException { if (value == null) { return false; } ensureCompatible(value.getClass()); @SuppressWarnings("unchecked") final T c = (T) value; return containsNC(c); }
/** * Returns the range of values that are in this range but not in the given range. * This method returns an array of length 0, 1 or 2: * <p> * <ul> * <li>If the given range contains fully this range, returns an array of length 0.</li> * <li>If the given range is in the middle of this range, then the subtraction results in * two disjoint ranges which will be returned as two elements in the array.</li> * <li>Otherwise returns an array of length 1.</li> * </ul> * * @param range The range to substract. * @return This range without the given range. * @throws IllegalArgumentException is the given range can not be converted to a valid type * through widening conversion. * * @see javax.media.jai.util.Range#subtract */ public Range<?>[] subtract(final Range<?> range) throws IllegalArgumentException { return subtractNC(ensureCompatible(range)); }
this.isMaxIncluded = isMaxIncluded && maxValue != null; checkElementClass(); if (minValue != null) ensureCompatible(minValue.getClass()); if (maxValue != null) ensureCompatible(maxValue.getClass());