Author: luc Date: Sun Apr 19 16:31:59 2009 New Revision: 766482 URL: http://svn.apache.org/viewvc?rev=766482&view=rev Log: added Field and FieldElement interfaces to allow algorithms operate on any type of field. This change is related to the discussion on dev list http://markmail.org/message/h2rmq6wo7nwqzx4w
Added: commons/proper/math/trunk/src/java/org/apache/commons/math/Field.java (with props) commons/proper/math/trunk/src/java/org/apache/commons/math/FieldElement.java (with props) Added: commons/proper/math/trunk/src/java/org/apache/commons/math/Field.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/Field.java?rev=766482&view=auto ============================================================================== --- commons/proper/math/trunk/src/java/org/apache/commons/math/Field.java (added) +++ commons/proper/math/trunk/src/java/org/apache/commons/math/Field.java Sun Apr 19 16:31:59 2009 @@ -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; + +import java.io.Serializable; + +/** + * Interface representing a <a href="http://mathworld.wolfram.com/Field.html">field</a>. + * <p> + * Classes implementing this interface will often be singletons. + * </p> + * @param <T> the type of the field elements + * @see FieldElement + * @version $Revision$ $Date$ + * @since 2.0 + */ +public interface Field<T> extends Serializable { + + /** Get the additive identity of the field. + * <p> + * The additive identity is the element e<sub>0</sub> of the field such that + * for all elements a of the field, the equalities a + e<sub>0</sub> = + * e<sub>0</sub> + a = a hold. + * </p> + * @return additive identity of the field + */ + T getZero(); + + /** Get the multiplicative identity of the field. + * <p> + * The multiplicative identity is the element e<sub>1</sub> of the field such that + * for all elements a of the field, the equalities a × e<sub>1</sub> = + * e<sub>1</sub> × a = a hold. + * </p> + * @return multiplicative identity of the field + */ + T getOne(); + +} \ No newline at end of file Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/Field.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/Field.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: commons/proper/math/trunk/src/java/org/apache/commons/math/FieldElement.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/FieldElement.java?rev=766482&view=auto ============================================================================== --- commons/proper/math/trunk/src/java/org/apache/commons/math/FieldElement.java (added) +++ commons/proper/math/trunk/src/java/org/apache/commons/math/FieldElement.java Sun Apr 19 16:31:59 2009 @@ -0,0 +1,61 @@ +/* + * 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; + +import java.io.Serializable; + +/** + * Interface representing <a href="http://mathworld.wolfram.com/Field.html">field</a> elements. + * @param <T> the type of the field elements + * @see Field + * @version $Revision$ $Date$ + * @since 2.0 + */ +public interface FieldElement<T> extends Serializable { + + /** Compute this + a. + * @param a element to add + * @return a new element representing this + a + */ + T add(T a); + + /** Compute this - a. + * @param a element to subtract + * @return a new element representing this - a + */ + T subtract(T a); + + /** Compute this × a. + * @param a element to multiply + * @return a new element representing this × a + */ + T multiply(T a); + + /** Compute this ÷ a. + * @param a element to add + * @return a new element representing this ÷ a + * @exception ArithmeticException if a is the zero of the + * additive operation (i.e. additive identity) + */ + T divide(T a) throws ArithmeticException; + + /** Get the {...@link Field} to which the instance belongs. + * @return {...@link Field} to which the instance belongs + */ + Field<T> getField(); + +} \ No newline at end of file Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/FieldElement.java ------------------------------------------------------------------------------ svn:mergeinfo =