You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2011/03/08 22:09:49 UTC
svn commit: r1079545 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/exception/
main/java/org/apache/commons/math/util/
test/java/org/apache/commons/math/ode/sampling/
Author: erans
Date: Tue Mar 8 21:09:48 2011
New Revision: 1079545
URL: http://svn.apache.org/viewvc?rev=1079545&view=rev
Log:
[Previous commit was a mistake.]
Created a "SerializablePair" for use in "MathRuntimeException".
Uncommented the test in "DummyStepInterpolatorTest".
Added:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/SerializablePair.java (with props)
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/Pair.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java?rev=1079545&r1=1079544&r2=1079545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java Tue Mar 8 21:09:48 2011
@@ -26,7 +26,7 @@ import java.util.Locale;
import org.apache.commons.math.exception.util.ArgUtils;
import org.apache.commons.math.exception.util.Localizable;
-import org.apache.commons.math.util.Pair;
+import org.apache.commons.math.util.SerializablePair;
/**
* This class is the base class for all exceptions.
@@ -41,8 +41,8 @@ public class MathRuntimeException extend
/**
* Various informations that enrich the informative message.
*/
- private final List<Pair<Localizable, Object[]>> messages
- = new ArrayList<Pair<Localizable, Object[]>>();
+ private final List<SerializablePair<Localizable, Object[]>> messages
+ = new ArrayList<SerializablePair<Localizable, Object[]>>();
/**
* Arbitrary context information.
*/
@@ -65,7 +65,8 @@ public class MathRuntimeException extend
/** {@inheritDoc} */
public void addMessage(Localizable pattern,
Object ... arguments) {
- messages.add(new Pair<Localizable, Object[]>(pattern, ArgUtils.flatten(arguments)));
+ messages.add(new SerializablePair<Localizable, Object[]>(pattern,
+ ArgUtils.flatten(arguments)));
}
/** {@inheritDoc} */
@@ -129,8 +130,9 @@ public class MathRuntimeException extend
final StringBuilder sb = new StringBuilder();
int count = 0;
final int len = messages.size();
- for (Pair<Localizable, Object[]> pair : messages) {
- final MessageFormat fmt = new MessageFormat(pair.getKey().getLocalizedString(locale), locale);
+ for (SerializablePair<Localizable, Object[]> pair : messages) {
+ final MessageFormat fmt = new MessageFormat(pair.getKey().getLocalizedString(locale),
+ locale);
sb.append(fmt.format(pair.getValue()));
if (++count < len) {
// Add a separator if there are other messages.
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/Pair.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/Pair.java?rev=1079545&r1=1079544&r2=1079545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/Pair.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/Pair.java Tue Mar 8 21:09:48 2011
@@ -49,7 +49,7 @@ public class Pair<K, V> {
*
* @param entry Entry to copy.
*/
- Pair(Pair<? extends K, ? extends V> entry) {
+ public Pair(Pair<? extends K, ? extends V> entry) {
key = entry.getKey();
value = entry.getValue();
}
Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/SerializablePair.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/SerializablePair.java?rev=1079545&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/SerializablePair.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/SerializablePair.java Tue Mar 8 21:09:48 2011
@@ -0,0 +1,53 @@
+/*
+ * 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.util;
+
+import java.io.Serializable;
+
+/**
+ * Generic pair.
+ * Immutable class.
+ *
+ * @param <K> Key type.
+ * @param <V> Value type.
+ *
+ * @version $Revision$ $Date$
+ * @since 3.0
+ */
+public class SerializablePair<K extends Serializable, V extends Serializable>
+ extends Pair<K, V>
+ implements Serializable {
+ /**
+ * Create an entry representing a mapping from the specified key to the
+ * specified value.
+ *
+ * @param k Key.
+ * @param v Value.
+ */
+ public SerializablePair(K k, V v) {
+ super(k, v);
+ }
+
+ /**
+ * Create an entry representing the same mapping as the specified entry.
+ *
+ * @param entry Entry to copy.
+ */
+ public SerializablePair(SerializablePair<? extends K, ? extends V> entry) {
+ super(entry);
+ }
+}
Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/SerializablePair.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java?rev=1079545&r1=1079544&r2=1079545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java Tue Mar 8 21:09:48 2011
@@ -123,11 +123,8 @@ public class DummyStepInterpolatorTest {
fail("an exception should have been thrown");
} catch (IOException ioe) {
// expected behavior
- // XXX Why was the message supposed to be empty?
- // With the current code it is "org.apache.commons.math.util.Pair".
- // assertEquals(0, ioe.getMessage().length());
+ assertEquals(0, ioe.getMessage().length());
}
-
}
private static class BadStepInterpolator extends DummyStepInterpolator {
@@ -139,7 +136,7 @@ public class DummyStepInterpolatorTest {
}
@Override
protected void doFinalize() throws MathUserException {
- throw new MathUserException();
+ throw new MathUserException(LocalizedFormats.SIMPLE_MESSAGE, "");
}
}
}