• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Understanding the concept of positions

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..."
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic