Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Although it is not a duplicate thread there is a interesting thread discussing circular lists, with a simpler approach than starting from scratch:

http://stackoverflow.com/questions/18659792/circular-arraylist-extending-arraylist https://stackoverflow.com/questions/18659792/circular-arraylist-extending-arraylist

It shows simple extension of the ArrayList class and applying decorator pattern. essentially all you have to do is return the index referenced by the modulus(using the size of the ArrayList) of the required index and this will have circular behaviour. However this is a hack really and not a true circular list, where the last element holds reference to first element. One possibility I have not seen is just implementing Iterable interface to behave in a circular manner, this seems to be an ideal decoupled solution and it returns a Iterator, a much more mature approach. This has the advantage of multiple Iterators present on one list.

Although it is not a duplicate thread there is a interesting thread discussing circular lists, with a simpler approach than starting from scratch:

http://stackoverflow.com/questions/18659792/circular-arraylist-extending-arraylist

It shows simple extension of the ArrayList class and applying decorator pattern. essentially all you have to do is return the index referenced by the modulus(using the size of the ArrayList) of the required index and this will have circular behaviour. However this is a hack really and not a true circular list, where the last element holds reference to first element. One possibility I have not seen is just implementing Iterable interface to behave in a circular manner, this seems to be an ideal decoupled solution and it returns a Iterator, a much more mature approach. This has the advantage of multiple Iterators present on one list.

Although it is not a duplicate thread there is a interesting thread discussing circular lists, with a simpler approach than starting from scratch:

https://stackoverflow.com/questions/18659792/circular-arraylist-extending-arraylist

It shows simple extension of the ArrayList class and applying decorator pattern. essentially all you have to do is return the index referenced by the modulus(using the size of the ArrayList) of the required index and this will have circular behaviour. However this is a hack really and not a true circular list, where the last element holds reference to first element. One possibility I have not seen is just implementing Iterable interface to behave in a circular manner, this seems to be an ideal decoupled solution and it returns a Iterator, a much more mature approach. This has the advantage of multiple Iterators present on one list.

Source Link

Although it is not a duplicate thread there is a interesting thread discussing circular lists, with a simpler approach than starting from scratch:

http://stackoverflow.com/questions/18659792/circular-arraylist-extending-arraylist

It shows simple extension of the ArrayList class and applying decorator pattern. essentially all you have to do is return the index referenced by the modulus(using the size of the ArrayList) of the required index and this will have circular behaviour. However this is a hack really and not a true circular list, where the last element holds reference to first element. One possibility I have not seen is just implementing Iterable interface to behave in a circular manner, this seems to be an ideal decoupled solution and it returns a Iterator, a much more mature approach. This has the advantage of multiple Iterators present on one list.

lang-java

AltStyle によって変換されたページ (->オリジナル) /