Class ConverterCollections


  • public abstract class ConverterCollections
    extends Object
    A collection of Collection implementation classes that use the Converter interface to convert the items stored in underlying collection objects.
    Author:
    cp 2002.02.08, jh 2007.09.28
    • Constructor Detail

      • ConverterCollections

        public ConverterCollections()
    • Method Detail

      • getIterator

        public static <F,​T> Iterator<T> getIterator​(Iterator<F> iter,
                                                          Converter<F,​T> conv)
        Returns an instance of Iterator that uses a Converter to view an underlying Iterator.
        Type Parameters:
        F - the type of elements in the underlying Iterator
        T - the type that the elements should be converted to
        Parameters:
        iter - the underlying Iterator
        conv - the Converter to view the underlying Iterator through
        Returns:
        an Iterator that views the passed Iterator through the specified Converter
      • getCollection

        public static <F,​T> ConverterCollections.ConverterCollection<F,​T> getCollection​(Collection<F> col,
                                                                                                    Converter<F,​T> convUp,
                                                                                                    Converter<T,​F> convDown)
        Returns an instance of Collection that uses a Converter to view an underlying Collection.
        Type Parameters:
        F - the type of elements in the underlying Collection
        T - the type that the elements should be converted to
        Parameters:
        col - the underlying Collection
        convUp - the Converter to view the underlying Collection through
        convDown - the Converter to pass items down to the underlying Collection through
        Returns:
        a Collection that views the passed Collection through the specified Converter
      • getSet

        public static <F,​T> ConverterCollections.ConverterSet<F,​T> getSet​(Set<F> set,
                                                                                      Converter<F,​T> convUp,
                                                                                      Converter<T,​F> convDown)
        Returns an instance of Set that uses a Converter to view an underlying Set.
        Type Parameters:
        F - the type of elements in the underlying Set
        T - the type that the elements should be converted to
        Parameters:
        set - the underlying Set
        convUp - the Converter to view the underlying Set through
        convDown - the Converter to pass items down to the underlying Set through
        Returns:
        a Set that views the passed Set through the specified Converter
      • getSortedSet

        public static <F,​T> ConverterCollections.ConverterSortedSet<F,​T> getSortedSet​(SortedSet<F> set,
                                                                                                  Converter<F,​T> convUp,
                                                                                                  Converter<T,​F> convDown)
        Returns an instance of SortedSet that uses a Converter to view an underlying SortedSet.
        Type Parameters:
        F - the type of elements in the underlying SortedSet
        T - the type that the elements should be converted to
        Parameters:
        set - the underlying SortedSet
        convUp - the Converter to view the underlying SortedSet through
        convDown - the Converter to pass items down to the underlying SortedSet through
        Returns:
        a SortedSet that views the passed SortedSet through the specified Converter
      • getList

        public static <F,​T> ConverterCollections.ConverterList<F,​T> getList​(List<F> list,
                                                                                        Converter<F,​T> convUp,
                                                                                        Converter<T,​F> convDown)
        Returns a Converter instance of List.
        Type Parameters:
        F - the type of elements in the underlying list
        T - the type that the elements should be converted to
        Parameters:
        list - the underlying List
        convUp - the Converter to view the underlying List through
        convDown - the Converter to pass items down to the underlying List through
        Returns:
        a List that views the passed List through the specified Converter
      • getListIterator

        public static <F,​T> ConverterCollections.ConverterListIterator<F,​T> getListIterator​(ListIterator<F> iter,
                                                                                                        Converter<F,​T> convUp,
                                                                                                        Converter<T,​F> convDown)
        Returns a Converter instance of ListIterator.
        Type Parameters:
        F - the type of elements in the underlying ListIterator
        T - the type that the elements should be converted to
        Parameters:
        iter - the underlying ListIterator
        convUp - the Converter to view the underlying list through
        convDown - the Converter to pass items down to the underlying ListIterator through
        Returns:
        a ListIterator that views the passed ListIterator through the specified Converter
      • getMap

        public static <FK,​TK,​FV,​TV> ConverterCollections.ConverterMap<FK,​TK,​FV,​TV> getMap​(Map<FK,​FV> map,
                                                                                                                              Converter<FK,​TK> convKeyUp,
                                                                                                                              Converter<TK,​FK> convKeyDown,
                                                                                                                              Converter<FV,​TV> convValUp,
                                                                                                                              Converter<TV,​FV> convValDown)
        Returns a Converter instance of Map.
        Type Parameters:
        FK - the type of the keys in the underlying Map
        TK - the type that the keys should be converted to
        FV - the type of the values in the underlying Map
        TV - the type that the values should be converted to
        Parameters:
        map - the underlying Map
        convKeyUp - the Converter to view the underlying Map's keys through
        convKeyDown - the Converter to use to pass keys down to the underlying Map
        convValUp - the Converter to view the underlying Map's values through
        convValDown - the Converter to use to pass values down to the underlying Map
        Returns:
        a Map that views the keys and values of the passed Map through the specified Converters
      • getSortedMap

        public static <FK,​TK,​FV,​TV> ConverterCollections.ConverterSortedMap<FK,​TK,​FV,​TV> getSortedMap​(SortedMap<FK,​FV> map,
                                                                                                                                          Converter<FK,​TK> convKeyUp,
                                                                                                                                          Converter<TK,​FK> convKeyDown,
                                                                                                                                          Converter<FV,​TV> convValUp,
                                                                                                                                          Converter<TV,​FV> convValDown)
        Returns a Converter instance of SortedMap.
        Type Parameters:
        FK - the type of the keys in the underlying SortedMap
        TK - the type that the keys should be converted to
        FV - the type of the values in the underlying SortedMap
        TV - the type that the values should be converted to
        Parameters:
        map - the underlying SortedMap
        convKeyUp - the Converter to view the underlying SortedMap's keys through
        convKeyDown - the Converter to use to pass keys down to the underlying SortedMap
        convValUp - the Converter to view the underlying SortedMap's values through
        convValDown - the Converter to use to pass values down to the underlying SortedMap
        Returns:
        a SortedMap that views the keys and values of the passed SortedMap through the specified Converters
      • getEntrySet

        public static <FK,​TK,​FV,​TV> ConverterCollections.ConverterEntrySet<FK,​TK,​FV,​TV> getEntrySet​(Collection<Map.Entry<FK,​FV>> set,
                                                                                                                                        Converter<FK,​TK> convKeyUp,
                                                                                                                                        Converter<TK,​FK> convKeyDown,
                                                                                                                                        Converter<FV,​TV> convValUp,
                                                                                                                                        Converter<TV,​FV> convValDown)
        Returns a Converter instance of a Set that holds Entry objects for a ConverterMap.
        Type Parameters:
        FK - the type of the keys in the underlying EntrySet
        TK - the type that the keys should be converted to
        FV - the type of the values in the underlying EntrySet
        TV - the type that the values should be converted to
        Parameters:
        set - the underlying Entry Set (or Collection of Map Entry objects)
        convKeyUp - the Converter to view the underlying Entry Set's keys through
        convKeyDown - the Converter to use to pass keys down to the underlying Entry Set
        convValUp - the Converter to view the underlying Entry Set's values through
        convValDown - the Converter to use to pass values down to the underlying Entry Set
        Returns:
        a Converter Set that views the keys and values of the underlying Set's Map.Entry objects through the specified key and value Converters
      • getEntry

        public static <FK,​TK,​FV,​TV> ConverterCollections.ConverterEntry<FK,​TK,​FV,​TV> getEntry​(Map.Entry<FK,​FV> entry,
                                                                                                                                  Converter<FK,​TK> convKeyUp,
                                                                                                                                  Converter<FV,​TV> convValUp,
                                                                                                                                  Converter<TV,​FV> convValDown)
        Returns an instance of a MapEntry that uses Converters to retrieve the Entry's data.
        Type Parameters:
        FK - the type of the keys in the underlying Entry
        TK - the type that the keys should be converted to
        FV - the type of the values in the underlying Entry
        TV - the type that the values should be converted to
        Parameters:
        entry - the underlying Entry
        convKeyUp - the Converter to view the underlying Entry's key
        convValUp - the Converter to view the underlying Entry's value
        convValDown - the Converter to change the underlying Entry's value
        Returns:
        a ConverterEntry that converts the passed entry data using the specified Converters
      • getConverterHolder

        public static <F,​T> ConverterCollections.ConverterHolder<F,​T> getConverterHolder​(F value,
                                                                                                     Converter<F,​T> convUp)
        Returns a Converter instance of Holder..
        Type Parameters:
        F - the type of the underlying value
        T - the type of the converted value
        Parameters:
        value - the underlying value
        convUp - the Converter to view the underlying value
        Returns:
        a ConverterHolder that converts the passed value using the specified Converter.
      • getLongArray

        public static <F,​T> LongArray<T> getLongArray​(LongArray<F> la,
                                                            Converter<F,​T> convUp,
                                                            Converter<T,​F> convDown)
        Returns a LongArray storing values with type F and converting to type V as and when required.
        Type Parameters:
        F - the raw type
        T - the desired type
        Parameters:
        la - the LongArray with raw types
        convUp - a Converter to convert to the desired type
        convDown - a Converter to convert to the raw type
        Returns:
        a LongArray storing values in a raw type and converting to the desired type
      • getConcurrentMap

        public static <FK,​TK,​FV,​TV> ConcurrentMap<TK,​TV> getConcurrentMap​(ConcurrentMap<FK,​FV> map,
                                                                                                  Converter<FK,​TK> convKeyUp,
                                                                                                  Converter<TK,​FK> convKeyDown,
                                                                                                  Converter<FV,​TV> convValUp,
                                                                                                  Converter<TV,​FV> convValDown)
        Returns a Converter instance of ConcurrentMap.
        Parameters:
        map - the underlying ConcurrentMap
        convKeyUp - the Converter to view the underlying ConcurrentMap's keys through
        convKeyDown - the Converter to use to pass keys down to the underlying ConcurrentMap
        convValUp - the Converter to view the underlying ConcurrentMap's values through
        convValDown - the Converter to use to pass values down to the underlying ConcurrentMap
        Returns:
        a ConcurrentMap that views the keys and values of the passed ConcurrentMap through the specified Converters
      • getInvocableMap

        public static <FK,​TK,​FV,​TV> InvocableMap<TK,​TV> getInvocableMap​(InvocableMap<FK,​FV> map,
                                                                                                Converter<FK,​TK> convKeyUp,
                                                                                                Converter<TK,​FK> convKeyDown,
                                                                                                Converter<FV,​TV> convValUp,
                                                                                                Converter<TV,​FV> convValDown)
        Returns a Converter instance of InvocableMap.
        Parameters:
        map - the underlying InvocableMap
        convKeyUp - the Converter to view the underlying InvocableMap's keys through
        convKeyDown - the Converter to use to pass keys down to the underlying InvocableMap
        convValUp - the Converter to view the underlying InvocableMap's values through
        convValDown - the Converter to use to pass values down to the underlying InvocableMap
        Returns:
        an InvocableMap that views the keys and values of the passed InvocableMap through the specified Converters
      • getObservableMap

        public static <FK,​TK,​FV,​TV> ObservableMap<TK,​TV> getObservableMap​(ObservableMap<FK,​FV> map,
                                                                                                  Converter<FK,​TK> convKeyUp,
                                                                                                  Converter<TK,​FK> convKeyDown,
                                                                                                  Converter<FV,​TV> convValUp,
                                                                                                  Converter<TV,​FV> convValDown)
        Returns a Converter instance of ObservableMap.
        Parameters:
        map - the underlying ObservableMap
        convKeyUp - the Converter to view the underlying ObservableMap's keys through
        convKeyDown - the Converter to use to pass keys down to the underlying ObservableMap
        convValUp - the Converter to view the underlying ObservableMap's values through
        convValDown - the Converter to use to pass values down to the underlying ObservableMap
        Returns:
        an ObservableMap that views the keys and values of the passed ObservableMap through the specified Converters
      • getQueryMap

        public static <FK,​TK,​FV,​TV> QueryMap<TK,​TV> getQueryMap​(QueryMap<FK,​FV> map,
                                                                                        Converter<FK,​TK> convKeyUp,
                                                                                        Converter<TK,​FK> convKeyDown,
                                                                                        Converter<FV,​TV> convValUp,
                                                                                        Converter<TV,​FV> convValDown)
        Returns a Converter instance of QueryMap.
        Parameters:
        map - the underlying QueryMap
        convKeyUp - the Converter to view the underlying QueryMap's keys through
        convKeyDown - the Converter to use to pass keys down to the underlying QueryMap
        convValUp - the Converter to view the underlying QueryMap's values through
        convValDown - the Converter to use to pass values down to the underlying QueryMap
        Returns:
        a QueryMap that views the keys and values of the passed QueryMap through the specified Converters
      • getCacheMap

        public static <FK,​TK,​FV,​TV> CacheMap<TK,​TV> getCacheMap​(CacheMap<FK,​FV> map,
                                                                                        Converter<FK,​TK> convKeyUp,
                                                                                        Converter<TK,​FK> convKeyDown,
                                                                                        Converter<FV,​TV> convValUp,
                                                                                        Converter<TV,​FV> convValDown)
        Returns a Converter instance of CacheMap.
        Parameters:
        map - the underlying CacheMap
        convKeyUp - the Converter to view the underlying CacheMap's keys through
        convKeyDown - the Converter to use to pass keys down to the underlying CacheMap
        convValUp - the Converter to view the underlying CacheMap's values through
        convValDown - the Converter to use to pass values down to the underlying CacheMap
        Returns:
        a CacheMap that views the keys and values of the passed CacheMap through the specified Converters
      • getNamedCache

        public static <FK,​FV,​TK,​TV> NamedCache<TK,​TV> getNamedCache​(NamedCache<FK,​FV> cache,
                                                                                            Converter<FK,​TK> convKeyUp,
                                                                                            Converter<TK,​FK> convKeyDown,
                                                                                            Converter<FV,​TV> convValUp,
                                                                                            Converter<TV,​FV> convValDown)
        Returns a Converter instance of NamedCache that converts between the raw/from types to the desired/to types.

        There is a strong disclaimer in the use of this implementation:

        This conversion is entirely performed locally and therefore when using methods such as invoke, or aggregate, or entrySet(Filter), the provided agent (EntryProcessor, or EntryAggregator, or Filter) do not go through the provided converters. Hence the given agent(s) must operate against the raw types.

        Streams are not supported.

        Parameters:
        cache - the underlying NamedCache
        convKeyUp - the Converter to view the underlying NamedCache's keys through
        convKeyDown - the Converter to use to pass keys down to the underlying NamedCache
        convValUp - the Converter to view the underlying NamedCache's values through
        convValDown - the Converter to use to pass values down to the underlying NamedCache
        Returns:
        a NamedCache that views the keys and values of the passed NamedCache through the specified Converters
      • getMapEvent

        public static MapEvent getMapEvent​(ObservableMap map,
                                           MapEvent event,
                                           Converter convKey,
                                           Converter convVal)
        Returns an instance of a MapEvent that uses Converters to retrieve the event's data.
        Parameters:
        map - the new event's source
        event - the underlying MapEvent
        convKey - the Converter to view the underlying MapEvent's key
        convVal - the Converter to view the underlying MapEvent's values
        Returns:
        a MapEvent that converts the passed event data using the specified Converter
      • getMapEvent

        public static MapEvent getMapEvent​(ObservableMap map,
                                           MapEvent event,
                                           Converter convKey,
                                           Converter convVal,
                                           BackingMapManagerContext context)
        Returns an instance of a MapEvent that uses Converters to retrieve the event's data, and additionally provides access to the BackingMapManagerContext.
        Parameters:
        map - the new event's source
        event - the underlying MapEvent
        convKey - the Converter to view the underlying MapEvent's key
        convVal - the Converter to view the underlying MapEvent's values
        context - the BackingMapManagerContext used to deserialize the underlying values
        Returns:
        a MapEvent that converts the passed event data using the specified Converters
      • getMapListener

        public static MapListener getMapListener​(ObservableMap map,
                                                 MapListener listener,
                                                 Converter convKey,
                                                 Converter convVal)
        Returns a converter listener for the specified listener and Converters.
        Parameters:
        map - the Map that should be the source for converted events
        listener - the underlying MapListener
        convKey - the Converter to view the underlying MapEvent's key
        convVal - the Converter to view the underlying MapEvent's values
        Returns:
        the converting listener
      • convertArray

        public static Object[] convertArray​(Object[] ao,
                                            Converter conv)
        Convert the contents of the passed array. The conversion is done "in place" in the passed array.

        This helper method is intended to support the functionality of Collection.toArray.

        Parameters:
        ao - an array of Objects to convert
        conv - the Converter to use to convert the objects
        Returns:
        the passed array
      • convertArray

        public static Object[] convertArray​(Object[] aoSrc,
                                            Converter conv,
                                            Object[] aoDest)
        Convert the contents of the passed source array into an array with the component type of the passed destination array, using the destination array itself if it is large enough, and placing a null in the first unused element of the destination array if it is larger than the source array.

        This helper method is intended to support the functionality of Collection.toArray.

        Parameters:
        aoSrc - an array of Objects to convert
        conv - the Converter to use to convert the objects
        aoDest - the array to use to place the converted objects in if large enough, otherwise the array from which to obtain the component type to create a new array that is large enough
        Returns:
        an array whose component type is the same as the passed destination array and whose contents are the converted objects
      • combine

        public static <F,​I,​T> Converter<F,​T> combine​(Converter<F,​I> converter1,
                                                                       Converter<I,​T> converter2)
        Create a new converter by combining two existing converters.
        Type Parameters:
        F - the "from" type for the first converter
        I - the "to" type for the first converter and the "from" type for the second
        T - the "to" type for the second converter
        Parameters:
        converter1 - the first converter
        converter2 - the second converter
        Returns:
        a combining converter that applies the converters sequentially