0

I've taken up java for about a week and a half now with an eye toward writing cytoscape plugins and using jung2 to analyze and manipulate cytoscape graph objects. Is there any way to extend the cytoscape graph object call it class xyz to include a new field of the jung2 graph type object whose fields and methods point to the corresponding ones in cytoscape without creating a completely new object in memory. Not sure if I'm making and sense here but suppose for instance I had two class representing the same type of object

public class xyz {

    public double i;

    public xyz(double a) {
        i=a;
    }
}

public class pqr {

    public double j;

    public pqr(double b) {
        j=b;
    }
} 

then something like

public class trans extends xyz {

    public pqr toPqr;

    public trans(double a) {
        super(a);
        toPqr = new pqr(i);
    }
}

where now if

trans myTrans = new trans(5);

then myTrans.toPqr.j points to myTrans.i

if I assign a new value to either then myTrans.i changes

and if I change myTrans.i then that is seen in myTrans.toPqr.j

sdasdadas
  • 23,917
  • 20
  • 63
  • 148
  • It's hard to comprehend because everything has such abstract names. Could you post an actual example involving JUNG and Cytoscape classes? – sdasdadas Jul 30 '13 at 17:46
  • I've tried to explain better below – Stephen Kauffman Jul 31 '13 at 20:13
  • Not to be fickle but you should edit that post into your question. Just click edit ^, and then remove your answer. I'll take a look at the appended information, though. – sdasdadas Jul 31 '13 at 22:36
  • I think I know what you're saying but a real example would make this a whole lot easier. To clarify, you have two graph representation classes (say, an adjacency list vs. a matrix), and you want them both to perform the same operation without having them both in memory? (if this is for SNA, I'll understand the terms you throw at me better than `xyz` :D) – sdasdadas Jul 31 '13 at 22:41

1 Answers1

0

well what I'm looking for is is there a way to define class trans which extends class xyz so that if I have for instance

public class xyz {

    public String r;
    public double i;

    public xyz(String a, double b) {
        r=a;
        i=b;
    }
}

and

public class pqr {
    public String s;
    public double j;

    public pqr(String a, double b) {
        s=a;
        j=b;
    }
}

and

public class trans extends xyz {

    public pqr toPqr; //adding a new field of type pqr

    trans(xyz myXyz) {
        super(myXyz.r, myXyz.i);
        //code
    }
}

then if

xyz xyzA = new xyz("a",8); // constructor for two fields string r and double s

and (recast?)

xyzA = new trans(xyzA); // trans takes an xyz object as constructor arg

so that

((trans)xyzA).toPqr.s is always equal to xyzA.r where changing one changes the other ((trans)xyzA).toPqr.j is always equal to xyzA.i where changing one changes the other

Basically there are two distinct java objects representing the same type of mathematical object say a graph. One package of routines deals with the first representation and another set of routines deals only with the second representation of a graph. To use the second set of routines on the first representation, I would have to recreate the graph in memory from the first representation which I don't want to do. I'd like to extend the first object with a new field of the same type as the second representation. Without shadowing the the graph in memory.

I guess the simplest and most pointless exercise would be to define a class with two distinct fields that are always equal and change with each other. IS it possible to do this?