• Post Reply Bookmark Topic Watch Topic
  • New Topic

Understanding the concept of positions  RSS feed

 
Luke Winter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Winston
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..."
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I think position may not be a standard piece of Java jargon; it might be used in the common English sense of the word.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!