Class CollectionHelper

java.lang.Object
de.edgesoft.edgeutils.collections.CollectionHelper

public class CollectionHelper
extends java.lang.Object
Helpful methods for collections.

Legal stuff

Copyright 2010-2020 Ekkart Kleinod ekleinod@edgesoft.de

This file is part of edgeutils.

edgeutils is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

edgeutils is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with edgeutils. If not, see http://www.gnu.org/licenses/.

Since:
0.2
Version:
0.13.0
Author:
Ekkart Kleinod
  • Constructor Summary

    Constructors 
    Constructor Description
    CollectionHelper()  
  • Method Summary

    Modifier and Type Method Description
    static int countOccurrences​(java.lang.String haystack, char needle)
    Returns the number of occurrences of needle in haystack.
    static java.util.List<java.lang.String> fromCSVString​(java.lang.String theLine, java.lang.String theSeparator)
    Creates a list from the line with the given separator character.
    static <T> java.util.List<T> getFilledList​(T theValue, int theSize)
    Returns a list of the given size containing value.
    static <T> boolean isEmptyString​(java.util.Collection<T> theCollection)
    Returns if the collection contains only empty objects (i.e.
    static <T> java.lang.String toCSVString​(java.util.Collection<T> theCollection, java.lang.String theSeparator)
    Returns a csv string of the given values.
    static java.util.List<java.lang.String> trimSplit​(java.lang.String theLine, java.lang.String theSeparator)
    Creates a list from the line with the given separator character, trimming all entries.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • toCSVString

      public static <T> java.lang.String toCSVString​(java.util.Collection<T> theCollection, java.lang.String theSeparator)
      Returns a csv string of the given values.
      Type Parameters:
      T - stringable element type
      Parameters:
      theCollection - collection to stringify
      theSeparator - separator string
      Returns:
      csv string (empty if collection is empty or any parameter is null)
    • fromCSVString

      public static java.util.List<java.lang.String> fromCSVString​(java.lang.String theLine, java.lang.String theSeparator)
      Creates a list from the line with the given separator character. The method returns a list with as many entries as are expected, i.e. it fills the list with empty strings if needed.
      Parameters:
      theLine - line to split
      theSeparator - separator between entries
      Returns:
      list with splitted, trimmed entries
    • trimSplit

      public static java.util.List<java.lang.String> trimSplit​(java.lang.String theLine, java.lang.String theSeparator)
      Creates a list from the line with the given separator character, trimming all entries.
      Parameters:
      theLine - line to split
      theSeparator - separator between entries
      Returns:
      list with splitted, trimmed entries
      Since:
      0.12.0
    • countOccurrences

      public static int countOccurrences​(java.lang.String haystack, char needle)
      Returns the number of occurrences of needle in haystack.
      Parameters:
      haystack - string to search through
      needle - character to find
      Returns:
      number of occurences of needle in haystack
    • isEmptyString

      public static <T> boolean isEmptyString​(java.util.Collection<T> theCollection)
      Returns if the collection contains only empty objects (i.e. every contained object.toString returns "").
      Type Parameters:
      T - element type
      Parameters:
      theCollection - collection to check
      Returns:
      does collection contain only empty objects (true == only empty objects; false == at least one nonempty object)
    • getFilledList

      public static <T> java.util.List<T> getFilledList​(T theValue, int theSize)
      Returns a list of the given size containing value.
      Type Parameters:
      T - element type
      Parameters:
      theValue - value to be filled with
      theSize - size of the collection
      Returns:
      list containing value