Class StringUtil

java.lang.Object
ubic.gemma.core.util.StringUtil

public class StringUtil extends Object
String helpers (R-style name munging, common prefix/suffix, CSV split, etc.).

Ported in-tree from ubic.basecode.util.StringUtil as part of the Phase 3 baseCode util retirement (see BASECODE_DEP_AUDIT.md). Methods not called by Gemma have been dropped: containsValidCharacter, cvs2tsv, isLatinLetter, makeValidForR, twoStringHashKey. The single-arg legacy makeValidForR(String) is gone; callers use makeNames(String) directly.

Distinct from StringUtils (plural) which extends StringUtils.

Author:
pavlidis
  • Constructor Details

    • StringUtil

      public StringUtil()
  • Method Details

    • append

      public static String append(@Nullable String appendee, String appendant, String separator)
      Parameters:
      appendee - The string to be added to
      appendant - The string to add to the end of the appendee
      separator - The string to put between the joined strings, if necessary.
      Returns:
      appendee + separator + appendant unless appendee is empty, in which case the appendant is returned.
    • commonPrefix

      @Nullable public static String commonPrefix(Collection<String> strings)
      Given a set of strings, identify any prefix they have in common.
      Returns:
      the common prefix, null if there isn't one.
    • commonSuffix

      @Nullable public static String commonSuffix(Collection<String> strings)
      Given a set of strings, identify any suffix they have in common.
      Returns:
      the common suffix, null if there isn't one.
    • csvSplit

      public static String[] csvSplit(String line)
      Split a single CSV-formatted line into fields.
    • makeNames

      public static String[] makeNames(String[] strings, boolean unique)
      Mimics the make.names method in R.
      Parameters:
      strings - a list of strings to be made valid for R
      unique - if true, will ensure that the names are unique by appending a number to duplicates as per makeUnique(String[])
    • makeNames

      public static String makeNames(@Nullable String s)
      Mimics the make.names method in R for a single string.
    • makeUnique

      public static String[] makeUnique(String[] strings)
      Mimics the make.unique method in R.

      Duplicated values in the input array will be suffixed with a dot and a number, starting from 1.