Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with an Iterator question

 
Vineeth Menon
Ranch Hand
Posts: 71
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been learning Java for 5-6 months, my friend passed me this question regarding iterator for the first time in my life I have no clue what this means, can someone help me?



[Fixed code tags and formatting - see UseCodeTags for details]
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jim Fields,

Welcome to CodeRanch!

Please, UseCodeTags. I can see a closing code tag, however, since, there is no opening code tag, the code snippet is quite difficult to read.

Also, please TellTheDetails. What exact part you are having trouble with? And what way of thinking you are following as of now?

I hope this helps.
 
S.R Paul
Ranch Hand
Posts: 30
C++ Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim, The code itself doesn't make sense, since mostly no usable body in it.
What it is actually tying to do is, create a customized Iterator class, but lack of body code, nothing more.
All the collection interfaces implements Iterator, and tats just enough for normal use.

Next time try to post your code bit formatted
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim. Welcome to the Ranch!

OK, what you've got there is a skeleton implementation of a custom Iterator. It looks like it's intended to wrap an existing iterator and add some additional functionality. Although as far as I can tell at first glance the additional functionality is just to optionally eliminate duplicates.

So the first question is, do you know what an Iterator is? If not, you need to read about those. If you do, you need to work out how to implement this one - you need to delegate to the wrapped Iterator, but then add whatever additional logic you need. What I'd suggest is as a first step get it delegating completely, so your Iterator works exactly the same as the one passed in. Then worry about the duplicates once you've got that working.

(A quick observation: getting a rough solution looks relatively straightforward. Getting a perfect one not so simple - I can see one tricky point).
 
Vineeth Menon
Ranch Hand
Posts: 71
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the input guys, I guess I need to find out a way to implement the iterator functionality in this skelital implementation of this iterator...is that it???
 
Sammy Wilson
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my solution:

[Moderator action: Solution removed. This site is NotACodeMill.(⇐click)]
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vineeth Menon wrote:Thanks a lot for the input guys, I guess I need to find out a way to implement the iterator functionality in this skelital implementation of this iterator...is that it???


Well, since we have:


I would say, yes, you need to do exactly that, as it appears to be the whole point of the exercise.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sammy Wilson, welcome to the Ranch

Please note what it says on the contents page for this forum:
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
That is why Jeff removed your post: it does not help people to be given too complete a solution too quickly.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic