ConcreteSet is a basic java.util.Set implementation, very much like java.util.HashSet. Duplicate entries are ignored. Adds, removes, the “contains” method, and data extraction are extremely efficient. The ordering of elements within the set is random and not under the user's control. Unlike a HashSet, there is no need for an “initial capacity” or a “load factor”, and it never needs to allocate large, contiguous blocks of memory. Built using a java.util.TreeMap, it uses more memory as objects are added and releases memory as they are removed.
If what you need is a basic java.util.Set implementation, ConcreteSet is simpler and easier to use than any other Collection or Map. It speeds coding and greatly eases maintenance, and it is faster and makes better use of memory than any collection or map in java.util. (Except HashSet, when you know in advance the amount of data you will be storing.)
A basic set is useful:
- for storing a bunch of objects when you only want an object stored once, even if you add it several times. (That is, it is the best way to get rid of duplicates.)
- when you do not care about the order.
- when names, keys, or other identifiers are not needed, irrelevant, or unavailable.
- for merging collections and discarding duplicates.
In these cases, ConcreteSet is faster, more flexible, and makes better use of memory than any of the standard Java classes. It was designed for ease of use, speed, and microsecond-by-microsecond scalability.
It can be used as part of a one-time calculation, or maintained to track a set of objects over time. If you commonly use various collections and maps (TreeMap, HashMap, dictionaries) from Java's collections framework, you will want to have ConcreteSet in your library for its simplicity, ease-of-use, and raw speed.
ConcreteSet is a good example of a java.util.Set or java.util.Collection, and follows all the rules. It is written with generics. It is fully Javadoc'ed. It is not inherently thread-safe, and if used with multiple threads it should be accessed only in synchronized blocks, or be used only for reading. Objects placed in it should have well-distributed hash codes.
The source code includes a sample program, which can also serve as tests for any Java Set.