Class TypeRefSet

java.lang.Object
net.okapia.osid.torrefacto.collect.TypeRefSet
All Implemented Interfaces:
Iterable<Type>, Types

public final class TypeRefSet extends Object implements Types
A reference-counted Types collection. Each type is uniquely identified by its namespace, authority, and identifier, and the same type may be added more than once. A type is reported as present until it has been removed as many times as it was added; only the removal that matches the last outstanding add drops it. This suits a provider that registers type support from several independent sources and must keep a type available until the last source withdraws it. For plain set behavior, where repeated adds collapse to one, use TypeSet instead. The backing map is synchronized.
  • Constructor Details

    • TypeRefSet

      public TypeRefSet()
      Creates a new TypeRefSet.
    • TypeRefSet

      public TypeRefSet(Collection<Type> types)
      Creates a new TypeRefSet for a given collection of types.
      Parameters:
      types - the initial types
      Throws:
      NullArgumentException - types is null
    • TypeRefSet

      public TypeRefSet(Type[] types)
      Creates a new TypeRefSet for a given array of types.
      Parameters:
      types - the initial types
      Throws:
      NullArgumentException - types is null
  • Method Details

    • add

      public void add(Type type)
      Tracks a supported type, incrementing its reference count.
      Specified by:
      add in interface Types
      Parameters:
      type - the type to add
      Throws:
      NullArgumentException - type is null
    • remove

      public void remove(Type type)
      Removes a reference to a type. The type is dropped only when its last outstanding reference is removed; removing a type that is not present has no effect.
      Specified by:
      remove in interface Types
      Parameters:
      type - the type to remove
      Throws:
      NullArgumentException - type is null
    • contains

      public boolean contains(Type type)
      Tests for the existience of a type.
      Specified by:
      contains in interface Types
      Parameters:
      type - the type to test for
      Returns:
      true if the type exists, false otherwise
      Throws:
      NullArgumentException - type is null
    • toCollection

      public Collection<Type> toCollection()
      Gets an iterable collection of the types. Each distinct type appears once, regardless of its reference count.
      Specified by:
      toCollection in interface Types
      Returns:
      a collection
    • toArray

      public Type[] toArray()
      Gets an array of the types.
      Specified by:
      toArray in interface Types
      Returns:
      an array of types
    • clear

      public void clear()
      Removes all types and their reference counts.
      Specified by:
      clear in interface Types
    • iterator

      public Iterator<Type> iterator()
      Returns an iterator of Types.
      Specified by:
      iterator in interface Iterable<Type>
      Returns:
      an iterator