Formatting only. Eliminated tabs.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141313 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2004-06-18 04:59:06 +00:00
parent 91912d3f7e
commit 4a92f7c65e
3 changed files with 114 additions and 114 deletions

View File

@ -26,7 +26,7 @@ import org.apache.commons.math.MathException;
* into a primitive double or to turn a String representation of a Number into
* a double.
*
* @version $Revision: 1.14 $ $Date: 2004/06/01 21:35:13 $
* @version $Revision: 1.15 $ $Date: 2004/06/18 04:59:06 $
*/
public class DefaultTransformer implements NumberTransformer, Serializable {
@ -42,18 +42,18 @@ public class DefaultTransformer implements NumberTransformer, Serializable {
*/
public double transform(Object o) throws MathException{
if (o == null) {
throw new MathException("Conversion Exception in Transformation, Object is null");
}
if (o == null) {
throw new MathException("Conversion Exception in Transformation, Object is null");
}
if (o instanceof Number) {
return ((Number)o).doubleValue();
}
if (o instanceof Number) {
return ((Number)o).doubleValue();
}
try {
return new Double(o.toString()).doubleValue();
} catch (Exception e) {
throw new MathException("Conversion Exception in Transformation: " + e.getMessage(), e);
}
try {
return new Double(o.toString()).doubleValue();
} catch (Exception e) {
throw new MathException("Conversion Exception in Transformation: " + e.getMessage(), e);
}
}
}

View File

@ -28,124 +28,124 @@ import org.apache.commons.math.MathException;
* It provides a means to set NumberTransformers that will be selected
* based on the Class of the object handed to the Maps
* <code>double transform(Object o)</code> method.
* @version $Revision: 1.13 $ $Date: 2004/06/01 21:35:13 $
* @version $Revision: 1.14 $ $Date: 2004/06/18 04:59:06 $
*/
public class TransformerMap implements NumberTransformer, Serializable {
/** Serializable version identifier */
static final long serialVersionUID = -942772950698439883L;
/**
* A default Number Transformer for Numbers and numeric Strings.
*/
private NumberTransformer defaultTransformer = null;
/**
* A default Number Transformer for Numbers and numeric Strings.
*/
private NumberTransformer defaultTransformer = null;
/**
* The internal Map.
*/
private Map map = null;
/**
* The internal Map.
*/
private Map map = null;
/**
*
*/
public TransformerMap() {
map = new HashMap();
defaultTransformer = new DefaultTransformer();
}
/**
*
*/
public TransformerMap() {
map = new HashMap();
defaultTransformer = new DefaultTransformer();
}
/**
* Tests if a Class is present in the TransformerMap.
* @param key Class to check
* @return true|false
*/
public boolean containsClass(Class key) {
return map.containsKey(key);
}
/**
* Tests if a Class is present in the TransformerMap.
* @param key Class to check
* @return true|false
*/
public boolean containsClass(Class key) {
return map.containsKey(key);
}
/**
* Tests if a NumberTransformer is present in the TransformerMap.
* @param value NumberTransformer to check
* @return true|false
*/
public boolean containsTransformer(NumberTransformer value) {
return map.containsValue(value);
}
/**
* Tests if a NumberTransformer is present in the TransformerMap.
* @param value NumberTransformer to check
* @return true|false
*/
public boolean containsTransformer(NumberTransformer value) {
return map.containsValue(value);
}
/**
* Returns the Transformer that is mapped to a class
* if mapping is not present, this returns null.
* @param key The Class of the object
* @return the mapped NumberTransformer or null.
*/
public NumberTransformer getTransformer(Class key) {
return (NumberTransformer) map.get(key);
}
/**
* Returns the Transformer that is mapped to a class
* if mapping is not present, this returns null.
* @param key The Class of the object
* @return the mapped NumberTransformer or null.
*/
public NumberTransformer getTransformer(Class key) {
return (NumberTransformer) map.get(key);
}
/**
* Sets a Class to Transformer Mapping in the Map. If
* the Class is already present, this overwrites that
* mapping.
* @param key The Class
* @param transformer The NumberTransformer
* @return the replaced transformer if one is present
*/
public Object putTransformer(Class key, NumberTransformer transformer) {
return map.put(key, transformer);
}
/**
* Sets a Class to Transformer Mapping in the Map. If
* the Class is already present, this overwrites that
* mapping.
* @param key The Class
* @param transformer The NumberTransformer
* @return the replaced transformer if one is present
*/
public Object putTransformer(Class key, NumberTransformer transformer) {
return map.put(key, transformer);
}
/**
* Removes a Class to Transformer Mapping in the Map.
* @param key The Class
* @return the removed transformer if one is present or
* null if none was present.
*/
public Object removeTransformer(Class key) {
return map.remove(key);
}
/**
* Removes a Class to Transformer Mapping in the Map.
* @param key The Class
* @return the removed transformer if one is present or
* null if none was present.
*/
public Object removeTransformer(Class key) {
return map.remove(key);
}
/**
* Clears all the Class to Transformer mappings.
*/
public void clear() {
map.clear();
}
/**
* Clears all the Class to Transformer mappings.
*/
public void clear() {
map.clear();
}
/**
* Returns the Set of Classes used as keys in the map.
* @return Set of Classes
*/
public Set classes() {
return map.keySet();
}
/**
* Returns the Set of Classes used as keys in the map.
* @return Set of Classes
*/
public Set classes() {
return map.keySet();
}
/**
* Returns the Set of NumberTransformers used as values
* in the map.
* @return Set of NumberTransformers
*/
public Collection transformers() {
return map.values();
}
/**
* Returns the Set of NumberTransformers used as values
* in the map.
* @return Set of NumberTransformers
*/
public Collection transformers() {
return map.values();
}
/**
* Attempts to transform the Object against the map of
* NumberTransformers. Otherwise it returns Double.NaN.
*
* @see org.apache.commons.math.util.NumberTransformer#transform(java.lang.Object)
*/
public double transform(Object o) throws MathException {
double value = Double.NaN;
/**
* Attempts to transform the Object against the map of
* NumberTransformers. Otherwise it returns Double.NaN.
*
* @see org.apache.commons.math.util.NumberTransformer#transform(java.lang.Object)
*/
public double transform(Object o) throws MathException {
double value = Double.NaN;
if (o instanceof Number || o instanceof String) {
value = defaultTransformer.transform(o);
} else {
NumberTransformer trans = getTransformer(o.getClass());
if (trans != null) {
value = trans.transform(o);
}
}
if (o instanceof Number || o instanceof String) {
value = defaultTransformer.transform(o);
} else {
NumberTransformer trans = getTransformer(o.getClass());
if (trans != null) {
value = trans.transform(o);
}
}
return value;
}
return value;
}
}

View File

@ -14,6 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- $Revision: 1.5 $ $Date: 2004/04/26 18:28:16 $ -->
<body>Convience routines and common data structure used throughout the commons-math library.</body>
<!-- $Revision: 1.6 $ $Date: 2004/06/18 04:59:06 $ -->
<body>Convience routines and common data structure used throughout the commons-math library.</body>
</html>