I am having issues understanding the concepts of positions. What are their purpose and how do they work? My resources say this:
-It gives a unified view of diverse ways of storing data, such as:
– a cell of an array
– a node of a linked list
-Just one method:
- object element():
returns the element stored at the position
I don't really understand this. I understand they return an element, but how does it know which element to return. If you were to implement positions with an array for example, would each block of the array point to a position object that would then return an element. I am confused.
Luke Winter wrote:I am having issues understanding the concepts of positions. What are their purpose and how do they work?...I am confused.
Me too. The only Position in the Java API (v7) is javax.swing.text.Position, and it's an interface (and it doesn't have an element() method). Yours sounds like it might be too, but I have no idea what Position you're talking about.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
You'd have to post some code from the Position class or if it's an interface, code from a concrete implementation of it.
If Position is an interface, I'd imagine it would have concrete implementations like MapPosition and ArrayPosition. The implementations would have a way to associate a specific kind of collection to it. Seems like there would also have to be some way to move the Position from one element of the collection to another. I think the point of having a Position interface would be so you could treat any collection, whether it's a Map or List or array or whatever, as something that you can get elements from by moving a Position object over it. To get the element of the collection at the current position, you'd just call Position.element().
An interesting concept, actually. Makes me go "hmmm..."