Class CompactSet<E>

java.lang.Object
com.cedarsoftware.util.CompactSet<E>
Type Parameters:
E - the type of elements maintained by this set
All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>
Direct Known Subclasses:
CompactCIHashSet, CompactCILinkedSet, CompactLinkedSet

public class CompactSet<E> extends Object implements Set<E>
A memory-efficient Set implementation that internally uses CompactMap.

This implementation provides the same memory benefits as CompactMap while maintaining proper Set semantics. It can be configured for:

  • Case sensitivity for String elements
  • Element ordering (sorted, reverse, insertion)
  • Custom compact size threshold

Creating a CompactSet


 // Create a case-insensitive, sorted CompactSet
 CompactSet<String> set = CompactSet.<String>builder()
     .caseSensitive(false)
     .sortedOrder()
     .compactSize(80)
     .build();

 // Create a CompactSet with insertion ordering
 CompactSet<String> ordered = CompactSet.<String>builder()
     .insertionOrder()
     .build();
 
Author:
John DeRegnaucourt ([email protected])
Copyright (c) Cedar Software LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

License

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  • Constructor Details

    • CompactSet

      public CompactSet()
      Constructs an empty CompactSet with the default configuration (i.e., default CompactMap).

      This uses the no-arg CompactMap constructor, which typically yields:

      • caseSensitive = true
      • compactSize = 50
      • unordered

      If you want custom config, use the CompactSet.Builder instead.

      Throws:
      IllegalStateException - if compactSize() returns a value less than 2
    • CompactSet

      protected CompactSet(CompactMap<E,Object> map)
      Constructs a CompactSet with a pre-existing CompactMap (usually from a builder).
      Parameters:
      map - the underlying CompactMap to store elements
    • CompactSet

      public CompactSet(Collection<? extends E> c)
      Constructs a CompactSet containing the elements of the specified collection, using the default CompactMap configuration.
      Parameters:
      c - the collection whose elements are to be placed into this set
      Throws:
      NullPointerException - if the specified collection is null
  • Method Details