How can i split an ArrayList of Shapes into partit

2019-03-05 12:18发布

问题:

I just want an advice or suggestions of how i can do it. i've been thinking about it for hours now and can't find a solution.

My aim is to convert this ER Diagram to tables.

So i have a Rectangle(Entity) that is linked to an ellipse(Attribute). I've already worked out on the collisions of the shapes where the line will retrieve the object that is linked to it. See the picture below:

the result will be as follows when the above diagram is drawn:

LINE(1) COLLIDES WITH RECTANGLE OF INDEX(0)

LINE(1) COLLIDES WITH ELLIPSE OF INDEX(2)

My Shapes are being stored in an ArrayList of shapes and what am trying to achieve is :

1- I want to be able to enter text inside the shapes. That text(e.g "Student") i will also need it later on when i want to make the conversion of ER Diagram to tables. I'm already using an Array List of Shapes, is it possible to add pointers to each index of this Array List of Shapes, stating that this index(0) (which is a rectangle) is named "Student"? (See picture below)

Where should the text be stored so that i can later on retrieve the text "Student" using a specific index of that rectangle. If my approach is not good, i will appreciate other suggestions of how i can do it. Can i use partitions?

Advice!

Please help guys?

回答1:

The easiest way to do it is to create a new object with your shape and text attribute, and override the equals method. So you could be able to retrieve the shape and the text inside the shape.

You can also manage a second arraylist with your text, with matching index, like the shape in 0 have the text attribute in your text list in 0, but i do not recommand it, because it is really easy to create new issues.