MATH-361
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@957518 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e2d957da2f
commit
66df76d89a
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return MessageFactory.buildMessage(Locale.US, pattern, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@Override
|
||||||
|
public String getLocalizedMessage() {
|
||||||
|
return MessageFactory.buildMessage(Locale.getDefault(), pattern, arguments);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -52,6 +52,9 @@ The <action> type attribute can be add,update,fix,remove.
|
||||||
If the output is not quite correct, check for invisible trailing spaces!
|
If the output is not quite correct, check for invisible trailing spaces!
|
||||||
-->
|
-->
|
||||||
<release version="2.2" date="TBD" description="TBD">
|
<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">
|
<action dev="erans" type="add" issue="MATH-378" due-to="Matthew Rowles">
|
||||||
Implementation of linear interpolation.
|
Implementation of linear interpolation.
|
||||||
</action>
|
</action>
|
||||||
|
|
Loading…
Reference in New Issue