• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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: 17065
298
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: 76395
364
  • 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.
 
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic