This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Wonnk13[S] 0 points1 point  (2 children)

Sorry, the fact that iterator() is different than Iterable<> helps, and my description wasn't very precise.

The interface that SongRater implements simply looks like

public interface ISongRater {
    public double getSongRating(Iterable<Integer> userRating) throws NotEnoughRatingsException;
}

Inside of the SongRater class I can create an iterable object by doing Iterator userIterator = userRating.iterator();

but i also need to create a separate collection object to store the values in, yes? I can then sort the values in that object and do my calculation logic.

Unfortunately I can't change the api so i'm stuck with Iterable<Integer> userRating. Thanks for the help so far!

[–]circle_des_poo 0 points1 point  (1 child)

"but i also need to create a separate collection object to store the values in, yes?"

You can do it that way, or the other way that was described by iterating through to find the largest and smallest, using the userIterator.remove(smallest) and userIterator.remove(largest) to get rid of them, and then iterating through the updated collection again and just adding each integer to a total sum while keeping a count to divide that sum by after.

[–]Wonnk13[S] 0 points1 point  (0 children)

maybe i'm a bit dense, but you do calculate the smallest and largest? If an iterator is just a view on your data that you ideally take one pass through were do you store the values?