Class ConverterSet


  • class ConverterSet
    extends java.lang.Object
    A set of converters, which allows exact converters to be quickly selected. This class is threadsafe because it is (essentially) immutable.
    Since:
    1.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  ConverterSet.Entry  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) ConverterSet add​(Converter converter, Converter[] removed)
      Returns a copy of this set, with the given converter added.
      (package private) void copyInto​(Converter[] converters)
      Copies all the converters in the set to the given array.
      (package private) ConverterSet remove​(int index, Converter[] removed)
      Returns a copy of this set, with the converter at the given index removed.
      (package private) ConverterSet remove​(Converter converter, Converter[] removed)
      Returns a copy of this set, with the given converter removed.
      (package private) Converter select​(java.lang.Class<?> type)
      Returns the closest matching converter for the given type, or null if none found.
      private static Converter selectSlow​(ConverterSet set, java.lang.Class<?> type)
      Returns the closest matching converter for the given type, but not very efficiently.
      (package private) int size()
      Returns the amount of converters in the set.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConverterSet

        ConverterSet​(Converter[] converters)
    • Method Detail

      • select

        Converter select​(java.lang.Class<?> type)
                  throws java.lang.IllegalStateException
        Returns the closest matching converter for the given type, or null if none found.
        Parameters:
        type - type to select, which may be null
        Throws:
        java.lang.IllegalStateException - if multiple converters match the type equally well
      • size

        int size()
        Returns the amount of converters in the set.
      • copyInto

        void copyInto​(Converter[] converters)
        Copies all the converters in the set to the given array.
      • add

        ConverterSet add​(Converter converter,
                         Converter[] removed)
        Returns a copy of this set, with the given converter added. If a matching converter is already in the set, the given converter replaces it. If the converter is exactly the same as one already in the set, the original set is returned.
        Parameters:
        converter - converter to add, must not be null
        removed - if not null, element 0 is set to the removed converter
        Throws:
        java.lang.NullPointerException - if converter is null
      • remove

        ConverterSet remove​(Converter converter,
                            Converter[] removed)
        Returns a copy of this set, with the given converter removed. If the converter was not in the set, the original set is returned.
        Parameters:
        converter - converter to remove, must not be null
        removed - if not null, element 0 is set to the removed converter
        Throws:
        java.lang.NullPointerException - if converter is null
      • remove

        ConverterSet remove​(int index,
                            Converter[] removed)
        Returns a copy of this set, with the converter at the given index removed.
        Parameters:
        index - index of converter to remove
        removed - if not null, element 0 is set to the removed converter
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is invalid
      • selectSlow

        private static Converter selectSlow​(ConverterSet set,
                                            java.lang.Class<?> type)
        Returns the closest matching converter for the given type, but not very efficiently.