Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD
The following examples show how to use
org.apache.commons.math3.exception.util.LocalizedFormats#PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns an estimate for the pth percentile of the stored values. * <p> * The implementation provided here follows the first estimation procedure presented * <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc252.htm">here.</a> * </p><p> * <strong>Preconditions</strong>:<ul> * <li><code>0 < p ≤ 100</code> (otherwise an * <code>MathIllegalArgumentException</code> is thrown)</li> * <li>at least one value must be stored (returns <code>Double.NaN * </code> otherwise)</li> * </ul></p> * * @param p the requested percentile (scaled from 0 - 100) * @return An estimate for the pth percentile of the stored data * @throws MathIllegalStateException if percentile implementation has been * overridden and the supplied implementation does not support setQuantile * @throws MathIllegalArgumentException if p is not a valid quantile */ public double getPercentile(double p) throws MathIllegalStateException, MathIllegalArgumentException { if (percentileImpl instanceof Percentile) { ((Percentile) percentileImpl).setQuantile(p); } else { try { percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME, new Class[] {Double.TYPE}).invoke(percentileImpl, new Object[] {Double.valueOf(p)}); } catch (NoSuchMethodException e1) { // Setter guard should prevent throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD, percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME); } catch (IllegalAccessException e2) { throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD, SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName()); } catch (InvocationTargetException e3) { throw new IllegalStateException(e3.getCause()); } } return apply(percentileImpl); }
Example 2
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 3
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns an estimate for the pth percentile of the stored values. * <p> * The implementation provided here follows the first estimation procedure presented * <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc252.htm">here.</a> * </p><p> * <strong>Preconditions</strong>:<ul> * <li><code>0 < p ≤ 100</code> (otherwise an * <code>MathIllegalArgumentException</code> is thrown)</li> * <li>at least one value must be stored (returns <code>Double.NaN * </code> otherwise)</li> * </ul></p> * * @param p the requested percentile (scaled from 0 - 100) * @return An estimate for the pth percentile of the stored data * @throws MathIllegalStateException if percentile implementation has been * overridden and the supplied implementation does not support setQuantile * @throws MathIllegalArgumentException if p is not a valid quantile */ public double getPercentile(double p) throws MathIllegalStateException, MathIllegalArgumentException { if (percentileImpl instanceof Percentile) { ((Percentile) percentileImpl).setQuantile(p); } else { try { percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME, new Class[] {Double.TYPE}).invoke(percentileImpl, new Object[] {Double.valueOf(p)}); } catch (NoSuchMethodException e1) { // Setter guard should prevent throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD, percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME); } catch (IllegalAccessException e2) { throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD, SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName()); } catch (InvocationTargetException e3) { throw new IllegalStateException(e3.getCause()); } } return apply(percentileImpl); }
Example 4
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 5
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns an estimate for the pth percentile of the stored values. * <p> * The implementation provided here follows the first estimation procedure presented * <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc252.htm">here.</a> * </p><p> * <strong>Preconditions</strong>:<ul> * <li><code>0 < p ≤ 100</code> (otherwise an * <code>IllegalArgumentException</code> is thrown)</li> * <li>at least one value must be stored (returns <code>Double.NaN * </code> otherwise)</li> * </ul></p> * * @param p the requested percentile (scaled from 0 - 100) * @return An estimate for the pth percentile of the stored data * @throws IllegalStateException if percentile implementation has been * overridden and the supplied implementation does not support setQuantile */ public double getPercentile(double p) { if (percentileImpl instanceof Percentile) { ((Percentile) percentileImpl).setQuantile(p); } else { try { percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME, new Class[] {Double.TYPE}).invoke(percentileImpl, new Object[] {Double.valueOf(p)}); } catch (NoSuchMethodException e1) { // Setter guard should prevent throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD, percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME); } catch (IllegalAccessException e2) { throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD, SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName()); } catch (InvocationTargetException e3) { throw new IllegalStateException(e3.getCause()); } } return apply(percentileImpl); }
Example 6
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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 IllegalArgumentException if the supplied implementation does not * provide a <code>setQuantile</code> method * @since 1.2 */ public synchronized void setPercentileImpl( UnivariateStatistic percentileImpl) { 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; }
Example 7
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns an estimate for the pth percentile of the stored values. * <p> * The implementation provided here follows the first estimation procedure presented * <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc252.htm">here.</a> * </p><p> * <strong>Preconditions</strong>:<ul> * <li><code>0 < p ≤ 100</code> (otherwise an * <code>MathIllegalArgumentException</code> is thrown)</li> * <li>at least one value must be stored (returns <code>Double.NaN * </code> otherwise)</li> * </ul></p> * * @param p the requested percentile (scaled from 0 - 100) * @return An estimate for the pth percentile of the stored data * @throws MathIllegalStateException if percentile implementation has been * overridden and the supplied implementation does not support setQuantile * @throws MathIllegalArgumentException if p is not a valid quantile */ public double getPercentile(double p) throws MathIllegalStateException, MathIllegalArgumentException { if (percentileImpl instanceof Percentile) { ((Percentile) percentileImpl).setQuantile(p); } else { try { percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME, new Class[] {Double.TYPE}).invoke(percentileImpl, new Object[] {Double.valueOf(p)}); } catch (NoSuchMethodException e1) { // Setter guard should prevent throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD, percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME); } catch (IllegalAccessException e2) { throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD, SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName()); } catch (InvocationTargetException e3) { throw new IllegalStateException(e3.getCause()); } } return apply(percentileImpl); }
Example 8
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 9
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns an estimate for the pth percentile of the stored values. * <p> * The implementation provided here follows the first estimation procedure presented * <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc252.htm">here.</a> * </p><p> * <strong>Preconditions</strong>:<ul> * <li><code>0 < p ≤ 100</code> (otherwise an * <code>IllegalArgumentException</code> is thrown)</li> * <li>at least one value must be stored (returns <code>Double.NaN * </code> otherwise)</li> * </ul></p> * * @param p the requested percentile (scaled from 0 - 100) * @return An estimate for the pth percentile of the stored data * @throws IllegalStateException if percentile implementation has been * overridden and the supplied implementation does not support setQuantile */ public double getPercentile(double p) { if (percentileImpl instanceof Percentile) { ((Percentile) percentileImpl).setQuantile(p); } else { try { percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME, new Class[] {Double.TYPE}).invoke(percentileImpl, new Object[] {Double.valueOf(p)}); } catch (NoSuchMethodException e1) { // Setter guard should prevent throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD, percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME); } catch (IllegalAccessException e2) { throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD, SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName()); } catch (InvocationTargetException e3) { throw new IllegalStateException(e3.getCause()); } } return apply(percentileImpl); }
Example 10
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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 IllegalArgumentException if the supplied implementation does not * provide a <code>setQuantile</code> method * @since 1.2 */ public synchronized void setPercentileImpl( UnivariateStatistic percentileImpl) { 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; }
Example 11
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns an estimate for the pth percentile of the stored values. * <p> * The implementation provided here follows the first estimation procedure presented * <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc252.htm">here.</a> * </p><p> * <strong>Preconditions</strong>:<ul> * <li><code>0 < p ≤ 100</code> (otherwise an * <code>MathIllegalArgumentException</code> is thrown)</li> * <li>at least one value must be stored (returns <code>Double.NaN * </code> otherwise)</li> * </ul></p> * * @param p the requested percentile (scaled from 0 - 100) * @return An estimate for the pth percentile of the stored data * @throws MathIllegalStateException if percentile implementation has been * overridden and the supplied implementation does not support setQuantile * @throws MathIllegalArgumentException if p is not a valid quantile */ public double getPercentile(double p) throws MathIllegalStateException, MathIllegalArgumentException { if (percentileImpl instanceof Percentile) { ((Percentile) percentileImpl).setQuantile(p); } else { try { percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME, new Class[] {Double.TYPE}).invoke(percentileImpl, new Object[] {Double.valueOf(p)}); } catch (NoSuchMethodException e1) { // Setter guard should prevent throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD, percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME); } catch (IllegalAccessException e2) { throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD, SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName()); } catch (InvocationTargetException e3) { throw new IllegalStateException(e3.getCause()); } } return apply(percentileImpl); }
Example 12
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 13
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns an estimate for the pth percentile of the stored values. * <p> * The implementation provided here follows the first estimation procedure presented * <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc252.htm">here.</a> * </p><p> * <strong>Preconditions</strong>:<ul> * <li><code>0 < p ≤ 100</code> (otherwise an * <code>MathIllegalArgumentException</code> is thrown)</li> * <li>at least one value must be stored (returns <code>Double.NaN * </code> otherwise)</li> * </ul></p> * * @param p the requested percentile (scaled from 0 - 100) * @return An estimate for the pth percentile of the stored data * @throws MathIllegalStateException if percentile implementation has been * overridden and the supplied implementation does not support setQuantile * @throws MathIllegalArgumentException if p is not a valid quantile */ public double getPercentile(double p) throws MathIllegalStateException, MathIllegalArgumentException { if (percentileImpl instanceof Percentile) { ((Percentile) percentileImpl).setQuantile(p); } else { try { percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME, new Class[] {Double.TYPE}).invoke(percentileImpl, new Object[] {Double.valueOf(p)}); } catch (NoSuchMethodException e1) { // Setter guard should prevent throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD, percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME); } catch (IllegalAccessException e2) { throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD, SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName()); } catch (InvocationTargetException e3) { throw new IllegalStateException(e3.getCause()); } } return apply(percentileImpl); }
Example 14
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 15
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Returns an estimate for the pth percentile of the stored values. * <p> * The implementation provided here follows the first estimation procedure presented * <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc252.htm">here.</a> * </p><p> * <strong>Preconditions</strong>:<ul> * <li><code>0 < p ≤ 100</code> (otherwise an * <code>MathIllegalArgumentException</code> is thrown)</li> * <li>at least one value must be stored (returns <code>Double.NaN * </code> otherwise)</li> * </ul></p> * * @param p the requested percentile (scaled from 0 - 100) * @return An estimate for the pth percentile of the stored data * @throws MathIllegalStateException if percentile implementation has been * overridden and the supplied implementation does not support setQuantile * @throws MathIllegalArgumentException if p is not a valid quantile */ public double getPercentile(double p) throws MathIllegalStateException, MathIllegalArgumentException { if (percentileImpl instanceof Percentile) { ((Percentile) percentileImpl).setQuantile(p); } else { try { percentileImpl.getClass().getMethod(SET_QUANTILE_METHOD_NAME, new Class[] {Double.TYPE}).invoke(percentileImpl, new Object[] {Double.valueOf(p)}); } catch (NoSuchMethodException e1) { // Setter guard should prevent throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_UNSUPPORTED_METHOD, percentileImpl.getClass().getName(), SET_QUANTILE_METHOD_NAME); } catch (IllegalAccessException e2) { throw new MathIllegalStateException( LocalizedFormats.PERCENTILE_IMPLEMENTATION_CANNOT_ACCESS_METHOD, SET_QUANTILE_METHOD_NAME, percentileImpl.getClass().getName()); } catch (InvocationTargetException e3) { throw new IllegalStateException(e3.getCause()); } } return apply(percentileImpl); }
Example 16
Source File: DescriptiveStatistics.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }