Class FilteredStringOrderedSet

All Implemented Interfaces:
Arrangeable, EnhancedCollection<String>, Ordered<String>, Iterable<String>, Collection<String>, Set<String>

public class FilteredStringOrderedSet extends ObjectOrderedSet<String>
A customizable variant on ObjectOrderedSet that always uses String keys, but only considers any character in an item (for equality and hashing purposes) if that character satisfies a predicate. This can also edit the characters that pass the filter, such as by changing their case during comparisons (and hashing). You will usually want to call setFilter(CharFilter) to change the behavior of hashing and equality before you enter any items, unless you have specified the CharFilter you want in the constructor.
You can use this class as a replacement for CaseInsensitiveOrderedSet if you set the editor to a method reference to Character.toUpperCase(char) or Casing.caseUp(char). You can go further by setting the filter to make the hashing and equality checks ignore characters that don't satisfy a predicate, such as Character.isLetter(char). CaseInsensitiveOrderedSet does allow taking arbitrary CharSequence types as keys, but it doesn't permit modifying them, so usually Strings are a good choice anyway.
Be advised that if you use some (most) checks in Character for properties of a char, and you try to use them on GWT, those checks will not work as expected for non-ASCII characters. Some other platforms might also be affected, such as TeaVM, but it isn't clear yet which platforms have full Unicode support. You can consider depending upon RegExodus for more cross-platform Unicode support; a method reference to Category.L::contains acts like Character::isLetter, but works on GWT. com.github.tommyettinger.ds.support.util.CharPredicates provides a few common CharPredicate constants that will work identically on all platforms.
This is very similar to FilteredStringSet, except that this class maintains insertion order and can be sorted with ObjectOrderedSet.sort(), ObjectOrderedSet.sort(Comparator), etc. Note that because each String is stored in here in its original form (not modified to make it use the filter and editor), the sorted order might be different than you expect. You can use FilteredComparators.makeStringComparator(CharPredicate, CharToCharFunction) to create a Comparator for Strings that uses the same rules this class does.
  • Field Details

  • Constructor Details

    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(OrderType type)
      Creates a new set with an initial capacity of Utilities.getDefaultTableCapacity() and a load factor of Utilities.getDefaultLoadFactor(). This considers all characters in a String key and does not edit them.
      Parameters:
      type - either OrderType.BAG to use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(int initialCapacity, OrderType type)
      Creates a new set with the specified initial capacity a load factor of Utilities.getDefaultLoadFactor(). This set will hold initialCapacity items before growing the backing table. This considers all characters in a String key and does not edit them.
      Parameters:
      initialCapacity - If not a power of two, it is increased to the next nearest power of two.
      type - either OrderType.BAG to use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(int initialCapacity, float loadFactor, OrderType type)
      Creates a new set with the specified initial capacity and load factor. This set will hold initialCapacity items before growing the backing table. This considers all characters in a String key and does not edit them.
      Parameters:
      initialCapacity - If not a power of two, it is increased to the next nearest power of two.
      loadFactor - what fraction of the capacity can be filled before this has to resize; 0 < loadFactor <= 1
      type - either OrderType.BAG to use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(CharFilter filter, OrderType type)
      Creates a new set with an initial capacity of Utilities.getDefaultTableCapacity() and a load factor of Utilities.getDefaultLoadFactor(). This uses the specified CharFilter.
      Parameters:
      filter - a CharFilter that can be obtained with CharFilter.getOrCreate(String, CharPredicate, CharToCharFunction)
      type - either OrderType.BAG to use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(CharFilter filter, int initialCapacity, OrderType type)
      Creates a new set with the specified initial capacity and the default load factor. This set will hold initialCapacity items before growing the backing table. This uses the specified CharFilter.
      Parameters:
      filter - a CharFilter that can be obtained with CharFilter.getOrCreate(String, CharPredicate, CharToCharFunction)
      initialCapacity - If not a power of two, it is increased to the next nearest power of two.
      type - either OrderType.BAG to use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(CharFilter filter, int initialCapacity, float loadFactor, OrderType type)
      Creates a new set with the specified initial capacity and load factor. This set will hold initialCapacity items before growing the backing table. This uses the specified CharFilter.
      Parameters:
      filter - a CharFilter that can be obtained with CharFilter.getOrCreate(String, CharPredicate, CharToCharFunction)
      initialCapacity - If not a power of two, it is increased to the next nearest power of two.
      loadFactor - what fraction of the capacity can be filled before this has to resize; 0 < loadFactor <= 1
      type - either OrderType.BAG to use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(FilteredStringOrderedSet set, OrderType type)
      Creates a new set identical to the specified set.
      Parameters:
      set - another FilteredStringOrderedSet to copy
      type - either OrderType.BAG to use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(CharFilter filter, Collection<? extends String> coll, OrderType type)
      Creates a new set that contains all distinct elements in coll. This uses the specified CharFilter, including while it enters the items in coll.
      Parameters:
      filter - a CharFilter that can be obtained with CharFilter.getOrCreate(String, CharPredicate, CharToCharFunction)
      coll - a Collection implementation to copy, such as an ObjectList or a Set that isn't a FilteredStringOrderedSet
      type - either OrderType.BAG to use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(CharFilter filter, String[] array, int offset, int length, OrderType type)
      Creates a new set using length items from the given array, starting at offset (inclusive). This uses the specified CharFilter, including while it enters the items in array.
      Parameters:
      filter - a CharFilter that can be obtained with CharFilter.getOrCreate(String, CharPredicate, CharToCharFunction)
      array - an array to draw items from
      offset - the first index in array to draw an item from
      length - how many items to take from array; bounds-checking is the responsibility of the using code
      type - either OrderType.BAG to use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(CharFilter filter, String[] array, OrderType type)
      Creates a new set containing all the items in the given array. This uses the specified CharFilter, including while it enters the items in array.
      Parameters:
      filter - a CharFilter that can be obtained with CharFilter.getOrCreate(String, CharPredicate, CharToCharFunction)
      array - an array that will be used in full, except for duplicate items
      type - either OrderType.BAG to use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(CharFilter filter, Ordered<String> ordered, int offset, int count, OrderType type)
      Creates a new set using count items from the given ordered, starting at offset (inclusive). This uses the specified CharFilter, including while it enters the items in ordered.
      Parameters:
      filter - a CharFilter that can be obtained with CharFilter.getOrCreate(String, CharPredicate, CharToCharFunction)
      ordered - an ordered to draw items from
      offset - the first index in ordered to draw an item from
      count - how many items to take from ordered; bounds-checking is the responsibility of the using code
      type - either OrderType.BAG to use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet()
      Creates a new set with an initial capacity of Utilities.getDefaultTableCapacity() and a load factor of Utilities.getDefaultLoadFactor(). This considers all characters in a String key and does not edit them.
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(int initialCapacity)
      Creates a new set with the specified initial capacity a load factor of Utilities.getDefaultLoadFactor(). This set will hold initialCapacity items before growing the backing table. This considers all characters in a String key and does not edit them.
      Parameters:
      initialCapacity - If not a power of two, it is increased to the next nearest power of two.
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(int initialCapacity, float loadFactor)
      Creates a new set with the specified initial capacity and load factor. This set will hold initialCapacity items before growing the backing table. This considers all characters in a String key and does not edit them.
      Parameters:
      initialCapacity - If not a power of two, it is increased to the next nearest power of two.
      loadFactor - what fraction of the capacity can be filled before this has to resize; 0 < loadFactor <= 1
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(CharFilter filter)
      Creates a new set with an initial capacity of Utilities.getDefaultTableCapacity() and a load factor of Utilities.getDefaultLoadFactor(). This uses the specified CharFilter.
      Parameters:
      filter - a CharFilter that can be obtained with CharFilter.getOrCreate(String, CharPredicate, CharToCharFunction)
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(CharFilter filter, int initialCapacity)
      Creates a new set with the specified initial capacity and the default load factor. This set will hold initialCapacity items before growing the backing table. This uses the specified CharFilter.
      Parameters:
      filter - a CharFilter that can be obtained with CharFilter.getOrCreate(String, CharPredicate, CharToCharFunction)
      initialCapacity - If not a power of two, it is increased to the next nearest power of two.
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(CharFilter filter, int initialCapacity, float loadFactor)
      Creates a new set with the specified initial capacity and load factor. This set will hold initialCapacity items before growing the backing table. This uses the specified CharFilter.
      Parameters:
      filter - a CharFilter that can be obtained with CharFilter.getOrCreate(String, CharPredicate, CharToCharFunction)
      initialCapacity - If not a power of two, it is increased to the next nearest power of two.
      loadFactor - what fraction of the capacity can be filled before this has to resize; 0 < loadFactor <= 1
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(FilteredStringOrderedSet set)
      Creates a new set identical to the specified set.
      Parameters:
      set - another FilteredStringOrderedSet to copy
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(CharFilter filter, Collection<? extends String> coll)
      Creates a new set that contains all distinct elements in coll. This uses the specified CharFilter, including while it enters the items in coll.
      Parameters:
      filter - a CharFilter that can be obtained with CharFilter.getOrCreate(String, CharPredicate, CharToCharFunction)
      coll - a Collection implementation to copy, such as an ObjectList or a Set that isn't a FilteredStringOrderedSet
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(CharFilter filter, String[] array, int offset, int length)
      Creates a new set using length items from the given array, starting at offset (inclusive). This uses the specified CharFilter, including while it enters the items in array.
      Parameters:
      filter - a CharFilter that can be obtained with CharFilter.getOrCreate(String, CharPredicate, CharToCharFunction)
      array - an array to draw items from
      offset - the first index in array to draw an item from
      length - how many items to take from array; bounds-checking is the responsibility of the using code
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(CharFilter filter, String[] array)
      Creates a new set containing all the items in the given array. This uses the specified CharFilter, including while it enters the items in array.
      Parameters:
      filter - a CharFilter that can be obtained with CharFilter.getOrCreate(String, CharPredicate, CharToCharFunction)
      array - an array that will be used in full, except for duplicate items
    • FilteredStringOrderedSet

      public FilteredStringOrderedSet(CharFilter filter, Ordered<String> ordered, int offset, int count)
      Creates a new set using count items from the given ordered, starting at offset (inclusive). This uses the specified CharFilter, including while it enters the items in ordered.
      Parameters:
      filter - a CharFilter that can be obtained with CharFilter.getOrCreate(String, CharPredicate, CharToCharFunction)
      ordered - an ordered to draw items from
      offset - the first index in ordered to draw an item from
      count - how many items to take from ordered; bounds-checking is the responsibility of the using code
  • Method Details