Le 24/06/2010 14:09, er...@apache.org a écrit :
> Author: erans
> Date: Thu Jun 24 12:09:14 2010
> New Revision: 957518
> 
> URL: http://svn.apache.org/viewvc?rev=957518&view=rev
> Log:
> MATH-361
> 
> Added:
>     commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/
>     
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java
>    (with props)
>     
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
>    (with props)
>     
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MessageFactory.java
>    (with props)
>     
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java
>    (with props)
> Modified:
>     commons/proper/math/trunk/src/site/xdoc/changes.xml
> 
> Added: 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java
> URL: 
> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java?rev=957518&view=auto
> ==============================================================================
> --- 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java
>  (added)
> +++ 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java
>  Thu Jun 24 12:09:14 2010
> @@ -0,0 +1,60 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements.  See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License.  You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.commons.math.exception;
> +
> +import org.apache.commons.math.util.LocalizedFormats;
> +
> +/**
> + * Exception to be thrown when two dimensions differ.
> + *
> + * @since 2.2
> + * @version $Revision$ $Date$
> + */
> +public class DimensionMismatchException extends MathIllegalArgumentException 
> {
> +    /** First dimension. */
> +    private final int dimension1;
> +
> +    /** Second dimension. */
> +    private final int dimension2;
> +
> +    /**
> +     * Construct an exception from the mismatched dimensions.
> +     *
> +     * @param dimension1 First dimension.
> +     * @param dimension2 Second dimension.
> +     */
> +    public DimensionMismatchException(int dimension1,
> +                                      int dimension2) {
> +        super(LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, dimension1, 
> dimension2);
> +
> +        this.dimension1 = dimension1;
> +        this.dimension2 = dimension2;
> +    }
> +
> +    /**
> +     * @return the first dimension.
> +     */
> +    public int getDimension1() {
> +        return dimension1;
> +    }
> +    /**
> +     * @return the second dimension.
> +     */
> +    public int getDimension2() {
> +        return dimension2;
> +    }
> +}
> 
> Propchange: 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java
> ------------------------------------------------------------------------------
>     svn:eol-style = native
> 
> Added: 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
> URL: 
> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java?rev=957518&view=auto
> ==============================================================================
> --- 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
>  (added)
> +++ 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
>  Thu Jun 24 12:09:14 2010
> @@ -0,0 +1,63 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements.  See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License.  You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.commons.math.exception;
> +
> +import java.util.Locale;
> +import org.apache.commons.math.util.Localizable;
> +
> +/**
> + * Base class for all preconditions violation exceptions.
> + * This class is not intended to be instantiated directly in most case: it
> + * should serve as a base class to create all the exceptions that share the
> + * semantics of the standard {...@link IllegalArgumentException}, but must 
> also
> + * provide a localized message.
> + *
> + * @since 2.2
> + * @version $Revision$ $Date$
> + */
> +public class MathIllegalArgumentException extends IllegalArgumentException {
> +    /**
> +     * Pattern used to build the message.
> +     */
> +    private final Localizable pattern;
> +    /**
> +     * Arguments used to build the message.
> +     */
> +    private final Object[] arguments;
> +    
> +    /**
> +     * @param pattern Message pattern.
> +     * @param arguments Arguments.
> +     */
> +    protected MathIllegalArgumentException(Localizable pattern,
> +                                           Object ... arguments) {
> +        this.pattern = pattern;
> +        this.arguments = arguments.clone();

I would have used something like:

 this.arguments = (arguments == null) ? new Object[0] : arguments.clone();

I think this would prevent problems for message patterns without any
arguments.

Luc

> +    }
> +
> +    /** {...@inheritdoc} */
> +    @Override
> +    public String getMessage() {
> +        return MessageFactory.buildMessage(Locale.US, pattern, arguments);
> +    }
> +    
> +    /** {...@inheritdoc} */
> +    @Override
> +    public String getLocalizedMessage() {
> +        return MessageFactory.buildMessage(Locale.getDefault(), pattern, 
> arguments);
> +    }
> +}
> 
> Propchange: 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
> ------------------------------------------------------------------------------
>     svn:eol-style = native
> 
> Added: 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MessageFactory.java
> URL: 
> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MessageFactory.java?rev=957518&view=auto
> ==============================================================================
> --- 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MessageFactory.java
>  (added)
> +++ 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MessageFactory.java
>  Thu Jun 24 12:09:14 2010
> @@ -0,0 +1,49 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements.  See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License.  You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.commons.math.exception;
> +
> +import java.text.MessageFormat;
> +import java.util.Locale;
> +import org.apache.commons.math.util.Localizable;
> +
> +/**
> + * Class for constructing localized messages.
> + *
> + * @since 2.2
> + * @version $Revision$ $Date$
> + */
> +public class MessageFactory {
> +    /**
> +     * Class contains only static methods.
> +     */
> +    private MessageFactory() {}
> +
> +    /**
> +     * Builds a message string by from a pattern and its arguments.
> +     *
> +     * @param locale Locale in which the message should be translated.
> +     * @param pattern Format specifier.
> +     * @param arguments Format arguments.
> +     * @return a message string.
> +     * @since 2.2
> +     */
> +    public static String buildMessage(Locale locale,
> +                                      Localizable pattern,
> +                                      Object ... arguments) {
> +        return new MessageFormat(pattern.getLocalizedString(locale), 
> locale).format(arguments);
> +    }
> +}
> 
> Propchange: 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MessageFactory.java
> ------------------------------------------------------------------------------
>     svn:eol-style = native
> 
> Added: 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java
> URL: 
> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java?rev=957518&view=auto
> ==============================================================================
> --- 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java
>  (added)
> +++ 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java
>  Thu Jun 24 12:09:14 2010
> @@ -0,0 +1,70 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements.  See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License.  You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.commons.math.exception;
> +
> +import org.apache.commons.math.util.LocalizedFormats;
> +
> +/**
> + * Exception to be thrown when some argument is out of range.
> + *
> + * @since 2.2
> + * @version $Revision$ $Date$
> + */
> +public class OutOfRangeException extends MathIllegalArgumentException {
> +    /** Lower bound. */
> +    private final Number lo;
> +    /** Higher bound. */
> +    private final Number hi;
> +    /** Requested. */
> +    private final Number requested;
> +
> +    /**
> +     * Construct an exception from the mismatched dimensions.
> +     *
> +     * @param requested Requested value.
> +     * @param lo Lower bound.
> +     * @param hi Higher bound.
> +     */
> +    public OutOfRangeException(Number requested,
> +                               Number lo,
> +                               Number hi) {
> +        super(LocalizedFormats.OUT_OF_RANGE_SIMPLE, requested, lo, hi);
> +
> +        this.requested = requested;
> +        this.lo = lo;
> +        this.hi = hi;
> +    }
> +
> +    /**
> +     * @return the requested value.
> +     */
> +    public Number getRequested() {
> +        return requested;
> +    }
> +    /**
> +     * @return the lower bound.
> +     */
> +    public Number getLo() {
> +        return lo;
> +    }
> +    /**
> +     * @return the higher bound.
> +     */
> +    public Number getHi() {
> +        return hi;
> +    }
> +}
> 
> Propchange: 
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java
> ------------------------------------------------------------------------------
>     svn:eol-style = native
> 
> Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
> URL: 
> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=957518&r1=957517&r2=957518&view=diff
> ==============================================================================
> --- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
> +++ commons/proper/math/trunk/src/site/xdoc/changes.xml Thu Jun 24 12:09:14 
> 2010
> @@ -52,6 +52,9 @@ The <action> type attribute can be add,u
>      If the output is not quite correct, check for invisible trailing spaces!
>       -->
>      <release version="2.2" date="TBD" description="TBD">
> +      <action dev="erans" type="add" issue="MATH-361">
> +        Created package "exception" to contain the new exceptions hierarchy.
> +      </action>
>        <action dev="erans" type="add" issue="MATH-378" due-to="Matthew 
> Rowles">
>          Implementation of linear interpolation.
>        </action>
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to