Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6CE805B27 for ; Tue, 10 May 2011 20:29:30 +0000 (UTC) Received: (qmail 13025 invoked by uid 500); 10 May 2011 20:29:30 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 12799 invoked by uid 500); 10 May 2011 20:29:30 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 12791 invoked by uid 99); 10 May 2011 20:29:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 May 2011 20:29:30 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 May 2011 20:29:27 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 6F42244DD8 for ; Tue, 10 May 2011 20:28:47 +0000 (UTC) Date: Tue, 10 May 2011 20:28:47 +0000 (UTC) From: =?utf-8?Q?Arne_Pl=C3=B6se_=28JIRA=29?= To: issues@commons.apache.org Message-ID: <1979696841.1148.1305059327452.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1429529368.32442.1304950683151.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (MATH-571) make FieldVector generic MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/MATH-571?page=3Dcom.atlassian.j= ira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D130313= 60#comment-13031360 ]=20 Arne Pl=C3=B6se commented on MATH-571: --------------------------------- Maybe this code works ... Yes it looks ugly ... I want to extend FieldElement and wnt it use in vector and matrix. =20 so the problem is getting the right "backing class" for the interface. For the matrix is a third generics needed.... Maybe someone has a better solution here is my "draft". public class App=20 { public static interface FieldElement { T add(T a); } public static interface FieldVector, V extend= s FieldVector> { V multiply(FieldVector v); V createVector(T[] data); } public static interface ComplexFieldElement> extends FieldElement { double getReal(); T conjugate(); } public static class Complex implements ComplexFieldElement { @Override public double getReal() { return 1; } @Override public Complex add(Complex a) { return new Complex(); } @Override public Complex conjugate() { throw new UnsupportedOperationException("Not supported yet."); } } public static interface GenericComplexFieldVector, V extends GenericComplexFieldVector> extends FieldVector= { V conjugate(); double[] getReal(); } public abstract static class AbstractArrayFieldVector, V extends FieldVector> implements FieldVector { protected T[] data; @Override public V multiply(FieldVector v) { return createVector(data); } } public static class ArrayFieldVector> extends= AbstractArrayFieldVector { @Override public ArrayFieldVector createVector(T[] data) { ArrayFieldVector result =3D new ArrayFieldVector(); result.data =3D data; return result; } } public abstract static class AbstractArrayComplexVector, V extends GenericComplexFieldVector> extends AbstractArr= ayFieldVector implements GenericComplexFieldVector{ @Override public double[] getReal() { throw new UnsupportedOperationException("Not supported yet."); } @Override public V conjugate() { throw new UnsupportedOperationException("Not supported yet."); } } public static interface ComplexVector extends GenericComplexFieldVector= { } public static class ArrayComplexVector extends AbstractArrayComplexVect= or implements ComplexVector { @Override public ComplexVector createVector(Complex[] data) { ArrayComplexVector result =3D new ArrayComplexVector(); result.data =3D data; return (ComplexVector)result; } } public static void main(String [] args) { ArrayComplexVector v =3D new ArrayComplexVector(); ComplexVector v1 =3D v.multiply(new ArrayComplexVector()); // File= dVector type survives ... FieldVector v2 =3D v1.multiply(v); FieldVector v3 =3D v2.multiply(v2); } } > 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=C3=B6se > Priority: Minor > > make FieldVector generic, so one can extend i.e. ArrayVieldVector to ArrayComplexVector an introduce new methoids (getReal())... > if one has an equation complexvector.copy the original type ArrayComplexV= ector is lost thus access to getReal() is not possible. > solution: > public class InheritationTest { > public static interface FieldVector, R exte= nds FieldVector> { > R copy(); > } > public abstract static class ArrayFieldVectorExtendable, R extends FieldVector> implements FieldVector, Serializ= able { > protected T[] data; > @Override > public R copy() { > return createVector(data); > } > abstract protected R createVector(T[] data); > } > public static class ArrayFieldVector> exten= ds ArrayFieldVectorExtendable { > @Override > protected ArrayFieldVector createVector(T[] data) { > ArrayFieldVector result =3D new ArrayFieldVector(); > result.data =3D data; > return result; > } > } > public static class ArrayComplexVector extends ArrayFieldVectorExtend= able { > @Override > protected ArrayComplexVector createVector(Complex[] data) { > ArrayComplexVector result =3D new ArrayComplexVector(); > result.data =3D data; > return result; > } > public double[] getReal() { > return null; > } > public double[] getImaginary() { > return null; > } > } > public void test() { > ArrayComplexVector v =3D new ArrayComplexVector(); > ArrayComplexVector v1 =3D v.copy(); // FiledVector type survives= ... > } > } -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira