/** Check equation index. * @param index index of the equation, must be between 0 included and * {@link #getNumberOfEquations()} (excluded) * @exception MathIllegalArgumentException if index is out of range */ private void checkIndex(final int index) throws MathIllegalArgumentException { if (index < 0 || index > start.length - 2) { throw new MathIllegalArgumentException(LocalizedFormats.ARGUMENT_OUTSIDE_DOMAIN, index, 0, start.length - 2); } }
/** * Verifies that (lower, upper) is a valid non-empty interval and confidence * is strictly between 0 and 1. * * @param lower lower endpoint * @param upper upper endpoint * @param confidence confidence level */ private void checkParameters(double lower, double upper, double confidence) { if (lower >= upper) { throw new MathIllegalArgumentException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, lower, upper); } if (confidence <= 0 || confidence >= 1) { throw new MathIllegalArgumentException(LocalizedFormats.OUT_OF_BOUNDS_CONFIDENCE_LEVEL, confidence, 0, 1); } } }
/** * Returns the base-2 logarithm of the specified {@code int}. Throws an * exception if {@code n} is not a power of two. * * @param n the {@code int} whose base-2 logarithm is to be evaluated * @return the base-2 logarithm of {@code n} * @throws MathIllegalArgumentException if {@code n} is not a power of two */ public static int exactLog2(final int n) throws MathIllegalArgumentException { int index = Arrays.binarySearch(TransformUtils.POWERS_OF_TWO, n); if (index < 0) { throw new MathIllegalArgumentException( LocalizedFormats.NOT_POWER_OF_TWO_CONSIDER_PADDING, Integer.valueOf(n)); } return index; } }
/** * {@inheritDoc} * * @throws MathIllegalArgumentException if the chromosomes are not an instance of {@link AbstractListChromosome} * @throws DimensionMismatchException if the length of the two chromosomes is different */ @SuppressWarnings("unchecked") public ChromosomePair crossover(final Chromosome first, final Chromosome second) throws DimensionMismatchException, MathIllegalArgumentException { if (!(first instanceof AbstractListChromosome<?> && second instanceof AbstractListChromosome<?>)) { throw new MathIllegalArgumentException(LocalizedFormats.INVALID_FIXED_LENGTH_CHROMOSOME); } return mate((AbstractListChromosome<T>) first, (AbstractListChromosome<T>) second); }
/** * {@inheritDoc} * * @throws MathIllegalArgumentException iff one of the chromosomes is * not an instance of {@link AbstractListChromosome} * @throws DimensionMismatchException if the length of the two chromosomes is different */ @SuppressWarnings("unchecked") public ChromosomePair crossover(final Chromosome first, final Chromosome second) throws DimensionMismatchException, MathIllegalArgumentException { if (!(first instanceof AbstractListChromosome<?> && second instanceof AbstractListChromosome<?>)) { throw new MathIllegalArgumentException(LocalizedFormats.INVALID_FIXED_LENGTH_CHROMOSOME); } return mate((AbstractListChromosome<T>) first, (AbstractListChromosome<T>) second); }
/** * {@inheritDoc} * * @throws MathIllegalArgumentException iff one of the chromosomes is * not an instance of {@link AbstractListChromosome} * @throws DimensionMismatchException if the length of the two chromosomes is different */ @SuppressWarnings("unchecked") public ChromosomePair crossover(final Chromosome first, final Chromosome second) throws DimensionMismatchException, MathIllegalArgumentException { if (!(first instanceof AbstractListChromosome<?> && second instanceof AbstractListChromosome<?>)) { throw new MathIllegalArgumentException(LocalizedFormats.INVALID_FIXED_LENGTH_CHROMOSOME); } return mate((AbstractListChromosome<T>) first, (AbstractListChromosome<T>) second); }
/** * Prime factors decomposition * * @param n number to factorize: must be ≥ 2 * @return list of prime factors of n * @throws MathIllegalArgumentException if n < 2. */ public static List<Integer> primeFactors(int n) { if (n < 2) { throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 2); } // slower than trial div unless we do an awful lot of computation // (then it finally gets JIT-compiled efficiently // List<Integer> out = PollardRho.primeFactors(n); return SmallPrimes.trialDivision(n); }
/** * Sets the implementation to be used by {@link #getPercentile(double)}. * The supplied <code>UnivariateStatistic</code> must provide a * <code>setQuantile(double)</code> method; otherwise * <code>IllegalArgumentException</code> is thrown. * * @param percentileImpl the percentileImpl to set * @throws MathIllegalArgumentException if the supplied implementation does not * provide a <code>setQuantile</code> method * @since 1.2 */ public synchronized void setPercentileImpl(UnivariateStatistic percentileImpl) throws MathIllegalArgumentException { try { percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME, new Class[] {Double.TYPE}).invoke(percentileImpl, new Object[] {Double.valueOf(50.0d)}); } catch (NoSuchMethodException e1) { throw new MathIllegalArgumentException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD, percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME); } catch (IllegalAccessException e2) { throw new MathIllegalArgumentException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD, SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName()); } catch (InvocationTargetException e3) { throw new IllegalArgumentException(e3.getCause()); } this.percentileImpl = percentileImpl; }
/** * @param o the object that gets transformed. * @return a double primitive representation of the Object o. * @throws NullArgumentException if Object <code>o</code> is {@code null}. * @throws MathIllegalArgumentException if Object <code>o</code> * cannot successfully be transformed * @see <a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/Transformer.html">Commons Collections Transformer</a> */ public double transform(Object o) throws NullArgumentException, MathIllegalArgumentException { if (o == null) { throw new NullArgumentException(LocalizedFormats.OBJECT_TRANSFORMATION); } if (o instanceof Number) { return ((Number)o).doubleValue(); } try { return Double.parseDouble(o.toString()); } catch (NumberFormatException e) { throw new MathIllegalArgumentException(LocalizedFormats.CANNOT_TRANSFORM_TO_DOUBLE, o.toString()); } }
throw new MathIllegalArgumentException( LocalizedFormats.INSTANCES_NOT_COMPARABLE_TO_EXISTING_VALUES, v.getClass().getName());
/** * This function allows you to control the number of elements contained * in this array, and can be used to "throw out" the last n values in an * array. This function will also expand the internal array as needed. * * @param i a new number of elements * @throws MathIllegalArgumentException if <code>i</code> is negative. */ public synchronized void setNumElements(int i) throws MathIllegalArgumentException { // If index is negative thrown an error. if (i < 0) { throw new MathIllegalArgumentException( LocalizedFormats.INDEX_NOT_POSITIVE, i); } // Test the new num elements, check to see if the array needs to be // expanded to accommodate this new number of elements. final int newSize = startIndex + i; if (newSize > internalArray.length) { expandTo(newSize); } // Set the new number of elements to new value. numElements = i; }
throw new MathIllegalArgumentException(LocalizedFormats.INVALID_FIXED_LENGTH_CHROMOSOME);
throw new MathIllegalArgumentException(LocalizedFormats.INVALID_FIXED_LENGTH_CHROMOSOME);
int index = origDataCopy.indexOf(permutedData.get(i)); if (index == -1) { throw new MathIllegalArgumentException(LocalizedFormats.DIFFERENT_ORIG_AND_PERMUTED_DATA);
/** * Simple constructor. * @param vertices the vertices of the convex hull, must be ordered * @param tolerance tolerance below which points are considered identical * @throws MathIllegalArgumentException if the vertices do not form a convex hull */ public ConvexHull2D(final Vector2D[] vertices, final double tolerance) throws MathIllegalArgumentException { // assign tolerance as it will be used by the isConvex method this.tolerance = tolerance; if (!isConvex(vertices)) { throw new MathIllegalArgumentException(LocalizedFormats.NOT_CONVEX); } this.vertices = vertices.clone(); }
/** * Throws MathIllegalArgumentException if the matrix does not have at least * two columns and two rows. * * @param matrix matrix to check for sufficiency * @throws MathIllegalArgumentException if there is insufficient data */ private void checkSufficientData(final RealMatrix matrix) { int nRows = matrix.getRowDimension(); int nCols = matrix.getColumnDimension(); if (nRows < 2 || nCols < 2) { throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_ROWS_AND_COLUMNS, nRows, nCols); } } }
/** * Throws MathIllegalArgumentException if the matrix does not have at least * one column and two rows. * @param matrix matrix to check * @throws MathIllegalArgumentException if the matrix does not contain sufficient data * to compute covariance */ private void checkSufficientData(final RealMatrix matrix) throws MathIllegalArgumentException { int nRows = matrix.getRowDimension(); int nCols = matrix.getColumnDimension(); if (nRows < 2 || nCols < 1) { throw new MathIllegalArgumentException( LocalizedFormats.INSUFFICIENT_ROWS_AND_COLUMNS, nRows, nCols); } } }
/** * Sets the <code>expansionMode</code>. The specified value must be one of * ADDITIVE_MODE, MULTIPLICATIVE_MODE. * * @param expansionMode The expansionMode to set. * @throws MathIllegalArgumentException if the specified mode value is not valid. * @deprecated As of 3.1. Please use {@link #setExpansionMode(ExpansionMode)} instead. */ @Deprecated public void setExpansionMode(int expansionMode) throws MathIllegalArgumentException { if (expansionMode != MULTIPLICATIVE_MODE && expansionMode != ADDITIVE_MODE) { throw new MathIllegalArgumentException(LocalizedFormats.UNSUPPORTED_EXPANSION_MODE, expansionMode, MULTIPLICATIVE_MODE, "MULTIPLICATIVE_MODE", ADDITIVE_MODE, "ADDITIVE_MODE"); } synchronized(this) { if (expansionMode == MULTIPLICATIVE_MODE) { setExpansionMode(ExpansionMode.MULTIPLICATIVE); } else if (expansionMode == ADDITIVE_MODE) { setExpansionMode(ExpansionMode.ADDITIVE); } } }
int length = xArray.length; if (length != yArray.length) { throw new MathIllegalArgumentException( LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, length, yArray.length); } else if (length < 2) { throw new MathIllegalArgumentException( LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, length, 2); } else {
/** * Formats a object to produce a string. {@code obj} must be either a * {@link Complex} object or a {@link Number} object. Any other type of * object will result in an {@link IllegalArgumentException} being thrown. * * @param obj the object to format. * @param toAppendTo where the text is to be appended * @param pos On input: an alignment field, if desired. On output: the * offsets of the alignment field * @return the value passed in as toAppendTo. * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition) * @throws MathIllegalArgumentException is {@code obj} is not a valid type. */ public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) throws MathIllegalArgumentException { StringBuffer ret = null; if (obj instanceof Complex) { ret = format( (Complex)obj, toAppendTo, pos); } else if (obj instanceof Number) { ret = format(new Complex(((Number)obj).doubleValue(), 0.0), toAppendTo, pos); } else { throw new MathIllegalArgumentException(LocalizedFormats.CANNOT_FORMAT_INSTANCE_AS_COMPLEX, obj.getClass().getName()); } return ret; }