How can i split an ArrayList of Shapes into partitions/lists in Java (Just advice)

百般思念 提交于 2019-12-02 21:05:15

问题


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.



来源:https://stackoverflow.com/questions/28834766/how-can-i-split-an-arraylist-of-shapes-into-partitions-lists-in-java-just-advic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!