/** * Creates a range from the given minimum and maximum values, inclusive. * The default implementation creates a range of {@code float}, but this method is * overridden by {@code ArrayVector.Decimal} which create a range of {@code double}. */ NumberRange<?> createRange(final float min, final float max) { return NumberRange.create(min, true, max, true); }
/** * Tests the {@link NumberRange#createBestFit(Number, boolean, Number, boolean)} method. */ @Test public void testCreateBestFit() { assertEquals(NumberRange.create((short) 2, true, (short) 200, true), NumberRange.createBestFit(2, true, 200.0, true)); }
/** Finds the minimum and maximum values in the array or in a subset of the array. */ @Override NumberRange<Double> range(final IntSupplier indices, int n) { // TODO: try to paralellize with streams. double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; while (--n >= 0) { final double value = array[(indices != null) ? indices.getAsInt() : n]; if (value < min) min = value; if (value > max) max = value; } return NumberRange.create(min, true, max, true); }
/** Finds the minimum and maximum values in the array or in a subset of the array. */ @Override NumberRange<?> range(final IntSupplier indices, int n) { long min = Long.MAX_VALUE; long max = Long.MIN_VALUE; while (--n >= 0) { final long value = array[(indices != null) ? indices.getAsInt() : n]; if (value < min) min = value; if (value > max) max = value; } return NumberRange.create(min, true, max, true); }
/** Finds the minimum and maximum values in the array or in a subset of the array. */ @Override NumberRange<?> range(final IntSupplier indices, int n) { short min = Short.MAX_VALUE; short max = Short.MIN_VALUE; while (--n >= 0) { final short value = array[(indices != null) ? indices.getAsInt() : n]; if (value < min) min = value; if (value > max) max = value; } return NumberRange.create(min, true, max, true); }
/** Finds the minimum and maximum values in the array or in a subset of the array. */ @Override NumberRange<Double> range(final IntSupplier indices, int n) { double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; while (--n >= 0) { final double value = array[(indices != null) ? indices.getAsInt() : n]; if (value < min) min = value; if (value > max) max = value; } return NumberRange.create(min, true, max, true); }
/** Finds the minimum and maximum values in the array or in a subset of the array. */ @Override NumberRange<?> range(final IntSupplier indices, int n) { int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; while (--n >= 0) { final int value = array[(indices != null) ? indices.getAsInt() : n]; if (value < min) min = value; if (value > max) max = value; } return NumberRange.create(min, true, max, true); }
/** Finds the minimum and maximum values in the array or in a subset of the array. */ @Override NumberRange<?> range(final IntSupplier indices, int n) { byte min = Byte.MAX_VALUE; byte max = Byte.MIN_VALUE; while (--n >= 0) { final byte value = array[(indices != null) ? indices.getAsInt() : n]; if (value < min) min = value; if (value > max) max = value; } return NumberRange.create(min, true, max, true); }
/** Finds the minimum and maximum values in the array or in a subset of the array. */ @Override NumberRange<?> range(final IntSupplier indices, int n) { byte min = Byte.MAX_VALUE; byte max = Byte.MIN_VALUE; while (--n >= 0) { final byte value = array[(indices != null) ? indices.getAsInt() : n]; if (value < min) min = value; if (value > max) max = value; } return NumberRange.create(min, true, max, true); }
@Override public boolean addAll(final Collection<? extends E> collection) throws IllegalArgumentException, UnsupportedOperationException { final int startIndex = super.size(); final boolean added = super.addAll(collection); if (added) { notifyAdd(collection, NumberRange.create(startIndex, true, super.size()-1, true) ); } return added; }
@Override public boolean addAll(final int index, final Collection<? extends E> collection) throws IllegalArgumentException, UnsupportedOperationException { final boolean added = super.addAll(index, collection); if (added) { notifyAdd(collection, NumberRange.create(index, true, index + collection.size(), true) ); } return added; }
/** Finds the minimum and maximum values in the array or in a subset of the array. */ @Override NumberRange<?> range(final IntSupplier indices, int n) { short min = Short.MAX_VALUE; short max = Short.MIN_VALUE; while (--n >= 0) { final short value = shortValue((indices != null) ? indices.getAsInt() : n); if (value < min) min = value; if (value > max) max = value; } return NumberRange.create(min, true, max, true); } }
/** Finds the minimum and maximum values in the array or in a subset of the array. */ @Override NumberRange<?> range(final IntSupplier indices, int n) { short min = Short.MAX_VALUE; short max = Short.MIN_VALUE; while (--n >= 0) { final short value = shortValue((indices != null) ? indices.getAsInt() : n); if (value < min) min = value; if (value > max) max = value; } return NumberRange.create(min, true, max, true); } }
/** Creates a range from the given minimum and maximum values. */ @Override NumberRange<?> createRange(final float min, final float max) { return NumberRange.create(DecimalFunctions.floatToDouble(min), true, DecimalFunctions.floatToDouble(max), true); } }
/** Finds the minimum and maximum values in the array or in a subset of the array. */ @Override NumberRange<Double> range(final IntSupplier indices, int n) { double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; while (--n >= 0) { final double value = doubleValue((indices != null) ? indices.getAsInt() : n); if (value < min) min = value; if (value > max) max = value; } return NumberRange.create(min, true, max, true); } }
/** Finds the minimum and maximum values in the array or in a subset of the array. */ @Override NumberRange<Double> range(final IntSupplier indices, int n) { double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; while (--n >= 0) { final double value = doubleValue((indices != null) ? indices.getAsInt() : n); if (value < min) min = value; if (value > max) max = value; } return NumberRange.create(min, true, max, true); } }
/** Finds the minimum and maximum values in the array or in a subset of the array. */ @Override NumberRange<?> range(final IntSupplier indices, int n) { long min = Long.MAX_VALUE; long max = Long.MIN_VALUE; while (--n >= 0) { final long value = longValue((indices != null) ? indices.getAsInt() : n); if (value < min) min = value; if (value > max) max = value; } return NumberRange.create(min, true, max, true); } }
/** Finds the minimum and maximum values in the array or in a subset of the array. */ @Override NumberRange<?> range(final IntSupplier indices, int n) { int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; while (--n >= 0) { final int value = intValue((indices != null) ? indices.getAsInt() : n); if (value < min) min = value; if (value > max) max = value; } return NumberRange.create(min, true, max, true); } }
/** Finds the minimum and maximum values in the array or in a subset of the array. */ @Override NumberRange<?> range(final IntSupplier indices, int n) { long min = Long.MAX_VALUE; long max = Long.MIN_VALUE; while (--n >= 0) { final long value = longValue((indices != null) ? indices.getAsInt() : n); if (value < min) min = value; if (value > max) max = value; } return NumberRange.create(min, true, max, true); } }
/** * Tests union and intersection with {@link Double} values. */ @Test public void testWithDoubles() { NumberRange<Double> r1 = NumberRange.create(10.0, true, 20.0, true); NumberRange<Double> r2 = NumberRange.create(15.0, true, 30.0, true); assertEquals(Double.class, r1.getElementType()); assertEquals(Double.class, r2.getElementType()); assertEquals(NumberRange.create(10.0, true, 30.0, true), r1.union(r2)); assertEquals(NumberRange.create(15.0, true, 20.0, true), r1.intersect(r2)); }