Class NSSet

All Implemented Interfaces:
Cloneable, Comparable<NSObject>

public class NSSet extends NSObject
The NSSet class is an unordered collection of NSObject instances. This implementation uses a LinkedHashSet or TreeSetas the underlying data structure.
See Also:
  • Field Details

    • set

      private final Set<NSObject> set
    • ordered

      private boolean ordered
  • Constructor Details

    • NSSet

      public NSSet()
      Creates a new NSSet instance. The created set is unordered.
      See Also:
    • NSSet

      public NSSet(boolean ordered)
      Creates a new NSSet instance.
      Parameters:
      ordered - Indicates whether the created set should be ordered or unordered.
      See Also:
    • NSSet

      public NSSet(NSObject... objects)
      Creates a new NSSet instance with the specified content. The created set is unordered.
      Parameters:
      objects - The objects to populate the set.
      See Also:
    • NSSet

      public NSSet(boolean ordered, NSObject... objects)
      Create a new NSSet instance with the specified content.
      Parameters:
      ordered - Indicates whether the created set should be ordered or unordered.
      objects - The objects to populate the set.
      See Also:
  • Method Details

    • addObject

      public void addObject(NSObject obj)
      Adds an object to the set.
      Parameters:
      obj - The object to add.
    • removeObject

      public void removeObject(NSObject obj)
      Removes an object from the set.
      Parameters:
      obj - The object to remove.
    • allObjects

      public NSObject[] allObjects()
      Returns all objects contained in the set.
      Returns:
      An array of all objects in the set.
    • anyObject

      public NSObject anyObject()
      Returns one of the objects in the set, or null if the set contains no objects.
      Returns:
      The first object in the set, or null if the set is empty.
    • containsObject

      public boolean containsObject(NSObject obj)
      Finds out whether the given object is contained in the set.
      Parameters:
      obj - The object to look for.
      Returns:
      true, when the object was found, false otherwise.
    • member

      public NSObject member(NSObject obj)
      Determines whether the set contains an object equal to the given object and returns that object if it is present.
      Parameters:
      obj - The object to look for.
      Returns:
      The object if it is present, null otherwise.
    • intersectsSet

      public boolean intersectsSet(NSSet otherSet)
      Finds out whether at least one object is present in both sets.
      Parameters:
      otherSet - The other set.
      Returns:
      false if the intersection of both sets is empty, true otherwise.
    • isSubsetOfSet

      public boolean isSubsetOfSet(NSSet otherSet)
      Finds out if this set is a subset of the given set.
      Parameters:
      otherSet - The other set.
      Returns:
      true if all elements in this set are also present in the other set, false otherwise.
    • objectIterator

      public Iterator<NSObject> objectIterator()
      Returns an iterator object that lets you iterate over all elements of the set. This is the equivalent to objectEnumerator in the Cocoa implementation of NSSet.
      Returns:
      The iterator for the set.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(NSObject o)
    • count

      public int count()
      Gets the number of elements in the set.
      Returns:
      The number of elements in the set.
      See Also:
    • clone

      public NSSet clone()
      Description copied from class: NSObject
      Creates and returns a deep copy of this instance.
      Specified by:
      clone in class NSObject
      Returns:
      A clone of this instance.
    • toJavaObject

      public Object toJavaObject()
      Description copied from class: NSObject
      Converts this NSObject into an equivalent object of the Java Runtime Environment.
      • NSArray objects are converted to arrays.
      • NSDictionary objects are converted to objects extending the Map class.
      • NSSet objects are converted to objects extending the Set class.
      • NSNumber objects are converted to primitive number values (int, long, double or boolean).
      • NSString objects are converted to String objects.
      • NSData objects are converted to byte arrays.
      • NSDate objects are converted to Date objects.
      • UID objects are converted to byte arrays.
      Specified by:
      toJavaObject in class NSObject
      Returns:
      A native java object representing this NSObject's value.
    • toXML

      void toXML(StringBuilder xml, int level)
      Returns the XML representation for this set. There is no official XML representation specified for sets. In this implementation it is represented by an array.
      Specified by:
      toXML in class NSObject
      Parameters:
      xml - The XML StringBuilder
      level - The indentation level
    • assignIDs

      void assignIDs(BinaryPropertyListWriter out)
      Description copied from class: NSObject
      Assigns IDs to all the objects in this NSObject subtree.
      Overrides:
      assignIDs in class NSObject
      Parameters:
      out - The writer object that handles the binary serialization.
    • toBinary

      void toBinary(BinaryPropertyListWriter out) throws IOException
      Description copied from class: NSObject
      Generates the binary representation of the object.
      Specified by:
      toBinary in class NSObject
      Parameters:
      out - The output stream to serialize the object to.
      Throws:
      IOException - If an I/O error occurs while writing to the stream or the object structure contains data that cannot be saved.
    • toASCII

      protected void toASCII(StringBuilder ascii, int level)
      Returns the ASCII representation of this set. There is no official ASCII representation for sets. In this implementation sets are represented as arrays.
      Specified by:
      toASCII in class NSObject
      Parameters:
      ascii - The ASCII file string builder
      level - The indentation level
    • toASCIIGnuStep

      protected void toASCIIGnuStep(StringBuilder ascii, int level)
      Returns the ASCII representation of this set according to the GnuStep format. There is no official ASCII representation for sets. In this implementation sets are represented as arrays.
      Specified by:
      toASCIIGnuStep in class NSObject
      Parameters:
      ascii - The ASCII file string builder
      level - The indentation level