Collections API's provide developers with a set of classes and interfaces that makes it easier to handle collections of objects.

learn more… | top users | synonyms

8
votes
1answer
111 views

Is my C++11 generic container a good design?

After refactors and refactors and the discovery of very common patterns on many of the classes of the software I wrote, I decided that it would be fine to have something like an arbitrary-keyed map, ...
4
votes
1answer
63 views

Does the class have unnecessary and violating Single responsibility principle method?

I encountered with the following code in the work. The MyItemCoordinator should receive MyItem objects, process them, add them ...
16
votes
4answers
1k views

Just a lowly counter that turned out to be surprisingly complicated

While writing this review, I saw a need for a Counter object similar to Python's. It seemed like it would be easy to write such a class, but it turned out to be ...
6
votes
2answers
81 views

Clean, efficient and extensible code for querying collections

I recently wrote code that would query a collection of objects and rank them according to a given criteria and then filter based on an object property. I attach the code below. I would like to know if ...
10
votes
3answers
238 views

Unrolled linked list

Does anyone have any feedback on my unrolled linked list class? I did it just for fun. I am interested in the performance tradeoffs of linked lists, standard lists and unrolled linked lists. This ...
5
votes
1answer
53 views

One-line initialisation for a constant list with all entries except one from another list

I'm looking to simplify the initialisation of the second constant, preferably to just one line. Any ideas? Anything from Guava or JDK (up to 1.6) is ok to use. ...
3
votes
3answers
63 views

Forcing type-safe IDs for use with Collections and Maps

Introduction I have a hierarchically nested tree class (like SampleFolder, s.b.) that I want to serialize. The problem arises with the collection of sub items ...
5
votes
3answers
187 views

Inserting interval into a collection

The task is fairly simple. I want to create a collection of intervals and implement an Add method which would insert new intervals to the collection and merge ...
3
votes
1answer
39 views

Hierarchy with `list<self>` type

I want to establish a hierarchy, where at each level of the hierarchy, each type can contain a list<its own type>. So ...
5
votes
1answer
90 views

Is this a good way to cascade a property?

I'm trying to write a simple game. I have an Entity object, that has a list of Sprite objects. Each Sprite has a position property where it is drawn on the screen. Sometimes, an entity can contain a ...
2
votes
2answers
97 views

Assigning list index values to String

I am just trying to convert each list of values to String by index one by one. My Code is running fine. But I am thinking that I can write better code than this. I Need your good coding possibilities ...
6
votes
2answers
486 views

List<T> implementation for VB6/VBA

Recently I decided VB6's Collection wasn't enough for my needs, so I decided to implement something like C#'s List<T>. ...
3
votes
2answers
244 views

Kings Drinking Game

This Review Request evolves into this Review Request now with a custom UI and other changes. I wrote a program to simulate the drinking card game Kings. This is my third Java Project. I didn't quite ...
1
vote
1answer
229 views

How to observe nested objects

By having two model classes Conversation and Message, what are the best practices to handle the next situation: A conversation ...
1
vote
2answers
170 views

A custom Java collection which doesn't support nulls

I am making a GWT application and have to prevent client code from using null values in collections. I found an answer but GWT doesn't support Queue and its ...
1
vote
2answers
70 views

Write a class with some properties and indexed

Is there a better way to write it? I need the best way to write it. It is this principle? Please show me a better way it breaks SRP? ...
1
vote
4answers
242 views

Extension Methods for Trimming List

I'm currently working on a project that I had to create basically a running queue of items. My thought was to do this by a list, but surprisingly there weren't any methods to remove the first sequence ...
1
vote
1answer
503 views

Class for Map of Maps

After finding myself sometimes needing a map of maps, and as I couldn't find one in existing libs (like Guava), I wrote my own implementation. Do you think this version is okay? Specifically: Is it ...
2
votes
5answers
770 views

Performance: Divide group of numbers into two groups of which the sums are equal

I have a piece of code that divides a group of numbers into two groups of numbers of which the sums are equal. I created this because of a StackOverflow question: ...
0
votes
1answer
255 views

Java concurrent Map of List

I need concurrent HashMap of List as value with following behavior: count of read/write ops approximately equals support add/remove values in lists thread safe iterations over lists After some ...
-1
votes
2answers
235 views

What is a good name for bidirectional dictionary structure? [closed]

I'm writing a generic bidirectional dictionary which will be a part of a (somewhat) public API. This is how the dictionary works: It will hold key-key pairs where ...
1
vote
1answer
91 views

Does refactoring a while loop increase CPU usage

While upgrading our code base to take advantage of new features in .Net 4.5, I'm trying to refactor our take of the classic Producer/Consumer algorithm, but I'm concerned my refactoring is going to ...
4
votes
3answers
221 views

Cached empty collections

I often find myself in need to create empty collections. One of those days several years ago, I wrote something like the following to address that: ...
3
votes
2answers
103 views
9
votes
2answers
5k views

Add/Remove items thread-safely in List<T>

Recently I had to lock collections (of type List<T>) when items were added or removed. Because several collections were used in given code instead of creating ...
7
votes
5answers
323 views

A simple unrolled linked list implementation

I tried to implement an unrolled linked list in C#. I only needed to add things and clear the whole list so I didn't implement IList<T> (I tried but it was ...
7
votes
1answer
2k views

Thread-safe LRU Dictionary in C#

Can't seem to find one, so trying to build a very simple but fast implementation. Thought I would post on SO for review/feedback, and so that others can just copy/paste for their own use. I'm using a ...
3
votes
1answer
383 views

Generating all subsets of a given set

I am learning Java Collections Framework. Can someone look at this code for generating all subsets of a given set and tell me any issues with it. ...
3
votes
3answers
786 views

ReadOnlyCollection - my alternative to .NET one

I wanted something more flexible than System.Collections.ObjectModel.ReadOnlyCollection. The goal was: consuming classes should only see what I want to show them, not whole underlying collection. For ...
1
vote
1answer
497 views

I am trying to re-write the ATM problem using collections. This is for personal learning. Can you please provide your comments

The problem statement is Write a CashWithDrawal function from an ATM which based on user specified amount dispenses bank notes. Ensure that the following is taken care of Minimum number of bank notes ...
4
votes
2answers
321 views

Iterating thousands of times over large collections: advices

This is a pet project :) I have hundreds of playlist files .m3u whose many entries have a wrong path. I'd like to fix them programmatically. Suppose one of my .m3U contains the following entry: ...
2
votes
1answer
1k views

Android - get int array from database Cursor

I find this code quite ugly, but in fact, I don't see any finest way to achieve the goal. ...
1
vote
1answer
558 views

PHP Class to Represent a Type Collection

Here is my attempt at a PHP class to be used as a base class for typed collections. My goals with this are: to be able to access collection members with foreach to be able to access collection ...
2
votes
1answer
144 views

Defining transpose on a collection of irregular collections

I was asked to submit my request for code review on http://stackoverflow.com/questions/10672046/defining-transpose-on-a-collection-of-irregular-collections here. This is a follow-up to the post I ...
4
votes
1answer
391 views

Entity collection best practice (separation of concerns, dependency injection, …)

I build a collection to ensure only valid entities in an array so I don't have to validate after every function / method call as I could rely on the collection to have only valid entities stored. ...
3
votes
1answer
125 views

JavaScript: Whats wrong with this implementation of Collection

I am pretty new to JavaScript and learning the intricacies of this language. I wanted a unique collection which will overwrite while adding if an item already exists else add. Rest of the behavior ...
3
votes
3answers
8k views

What is the most efficient way to convert a Java ResultSet to an Object[][]?

I have a module that builds swing tables based on an Object[][], then I have another module that queries a sqlite database and returns a ...
1
vote
2answers
859 views
4
votes
2answers
2k views

Is this collection actually thread safe? Is concurrent Iterating, querying and modifying safe?

This is based on Alexey Drobyshevsky's excellent article Problems with Iteration At Alexey's suggestion, I implemented his solution using a ReaderWriterLockSlim. Then I fleshed out a ThreadSafeList : ...
13
votes
11answers
549 views

Can you think of a better way to increment this integer when looping through a collection in C#?

I have the following code that loops through a collection of objects and dumps different properties out to Excel. The whole j++ on every other line doesn't seem ...
1
vote
1answer
392 views

Persisting objects in a ListBox ObjectCollection

I have a C# WinForms app containing a ListBox control, which I populate with objects of type BukkitServer. When an object is ...
5
votes
4answers
3k views
2
votes
1answer
176 views

Scala Direction enum with Enumeration and collection usage

I've just implement direction enum ...
9
votes
1answer
6k views

LinkedHashMap as LRU cache

I have a simple implementation for a LRU cache using LinkedHashMap. I want it to be as generic as possible. This is not for production use, just practice, so ...