commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arne Plöse (JIRA) <j...@apache.org>
Subject [jira] [Updated] (MATH-571) make FieldVector generic
Date Mon, 09 May 2011 14:22:03 GMT

     [ https://issues.apache.org/jira/browse/MATH-571?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Arne Plöse updated MATH-571:
----------------------------

    Description: 
make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector
an introduce new methoids (getReal())...

if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus
access to getReal() is not possible.

solution:

public class InheritationTest {

    public static interface FieldVector<T extends FieldElement<T>, R extends FieldVector>
{

        R copy();
    }

    public abstract static class ArrayFieldVectorExtendable<T extends FieldElement<T>,
R extends FieldVector> implements FieldVector<T, R>, Serializable {

        protected T[] data;

        @Override
        public R copy() {
            return createVector(data);
        }

        abstract protected R createVector(T[] data);
    }

    public static class ArrayFieldVector<T extends FieldElement<T>> extends ArrayFieldVectorExtendable<T,
ArrayFieldVector> {

        @Override
        protected ArrayFieldVector<T> createVector(T[] data) {
            ArrayFieldVector<T> result = new ArrayFieldVector<T>();
            result.data = data;
            return result;
        }
    }

    public static class ArrayComplexVector extends ArrayFieldVectorExtendable<Complex,
ArrayComplexVector> {

        @Override
        protected ArrayComplexVector createVector(Complex[] data) {
            ArrayComplexVector result = new ArrayComplexVector();
            result.data = data;
            return result;
        }

        public double[] getReal() {
            return null;
        }

        public double[] getImaginary() {
            return null;
        }
    }

    public void test() {
        ArrayComplexVector v = new ArrayComplexVector();
        ArrayComplexVector v1 = v.copy();  // FiledVector type survives ...
    }
}

  was:
make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector
an introduce new methoids (getReal())...

if one has an equation complexvector.copy the original type ArrayComplexVector is lost thus
access to getReal() is not possible.

solution see attached code 


> make FieldVector generic
> ------------------------
>
>                 Key: MATH-571
>                 URL: https://issues.apache.org/jira/browse/MATH-571
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 3.0
>            Reporter: Arne Plöse
>            Priority: Minor
>
> make FieldVector generic, so one can extend i.e. ArrayVieldVector<Complex> to ArrayComplexVector
an introduce new methoids (getReal())...
> if one has an equation complexvector.copy the original type ArrayComplexVector is lost
thus access to getReal() is not possible.
> solution:
> public class InheritationTest {
>     public static interface FieldVector<T extends FieldElement<T>, R extends
FieldVector> {
>         R copy();
>     }
>     public abstract static class ArrayFieldVectorExtendable<T extends FieldElement<T>,
R extends FieldVector> implements FieldVector<T, R>, Serializable {
>         protected T[] data;
>         @Override
>         public R copy() {
>             return createVector(data);
>         }
>         abstract protected R createVector(T[] data);
>     }
>     public static class ArrayFieldVector<T extends FieldElement<T>> extends
ArrayFieldVectorExtendable<T, ArrayFieldVector> {
>         @Override
>         protected ArrayFieldVector<T> createVector(T[] data) {
>             ArrayFieldVector<T> result = new ArrayFieldVector<T>();
>             result.data = data;
>             return result;
>         }
>     }
>     public static class ArrayComplexVector extends ArrayFieldVectorExtendable<Complex,
ArrayComplexVector> {
>         @Override
>         protected ArrayComplexVector createVector(Complex[] data) {
>             ArrayComplexVector result = new ArrayComplexVector();
>             result.data = data;
>             return result;
>         }
>         public double[] getReal() {
>             return null;
>         }
>         public double[] getImaginary() {
>             return null;
>         }
>     }
>     public void test() {
>         ArrayComplexVector v = new ArrayComplexVector();
>         ArrayComplexVector v1 = v.copy();  // FiledVector type survives ...
>     }
> }

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message