Class XCollections


  • public class XCollections
    extends java.lang.Object
    Utilities to work with collections, enumerations and iterators.

    Author:
    Javier Paniza
    • Constructor Summary

      Constructors 
      Constructor Description
      XCollections()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void add​(java.util.Collection collection, java.util.Enumeration toAdd)
      Adds elements from the enumeration to the collection.
      static java.lang.Object last​(java.util.Collection collection)
      Returns the last element of sent collection.
      static void move​(java.util.List list, int from, int to)  
      static void println​(java.util.Collection c)
      Print in standard output the collection elements.
      static void println​(java.util.Iterator it)
      Print in standard output the elements by it iterate.
      static java.util.Collection toCollection​(java.util.Enumeration e)
      Returns a collection from a enumeration.
      static java.util.List toList​(java.lang.Iterable it)
      Returns a List from an Iterable.
      static java.lang.String[] toStringArray​(java.util.Collection c)
      Returns a String [] from a collection of Strings.
      • Methods inherited from class java.lang.Object

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

      • XCollections

        public XCollections()
    • Method Detail

      • last

        public static java.lang.Object last​(java.util.Collection collection)
        Returns the last element of sent collection.

        Parameters:
        collection - Can be null
        Returns:
        Last element, or null if collection is null or empty.
      • add

        public static void add​(java.util.Collection collection,
                               java.util.Enumeration toAdd)
        Adds elements from the enumeration to the collection.

        Parameters:
        collection - Not null
        toAdd - If null no elements are added.
      • println

        public static void println​(java.util.Collection c)
        Print in standard output the collection elements.

        Util to debug.

        Parameters:
        c - Can be null.
      • println

        public static void println​(java.util.Iterator it)
        Print in standard output the elements by it iterate.

        Util to debug.

        Parameters:
        c - Can be null.
      • toCollection

        public static java.util.Collection toCollection​(java.util.Enumeration e)
        Returns a collection from a enumeration.

        Parameters:
        e - If null then returns a empty collection.
        Returns:
        Not null.
      • toList

        public static java.util.List toList​(java.lang.Iterable it)
        Returns a List from an Iterable.

        Parameters:
        it - If null then returns a empty list.
        Returns:
        Not null.
        Since:
        5.6.1
      • toStringArray

        public static java.lang.String[] toStringArray​(java.util.Collection c)
        Returns a String [] from a collection of Strings.

        Parameters:
        c - Elements must be of type String. If null then returns a empty array.
        Returns:
        Not null.
      • move

        public static void move​(java.util.List list,
                                int from,
                                int to)
        Since:
        5.2