hmi.util
Class StringUtil

java.lang.Object
  extended by hmi.util.StringUtil

public final class StringUtil
extends Object

Some utils for Strings

Author:
Job Zwiers

Nested Class Summary
static class StringUtil.TextPos
          Local class, for reposting positions in a String in the form of (line-number, line-pos).
 
Constructor Summary
private StringUtil()
           
 
Method Summary
static int diff(String s1, String s2)
          Returns the index where String s1 and s2 differ for the first time, or returns -1 if they actually equal strings.
static StringUtil.TextPos diffPos(String s1, String s2)
          Returns the TextPos where the two string differ for the first time.
static int getLineNumber(String s, int charPos)
          Counts the line number within a specified String, for a specified position inside that String.
static int getLinePos(String s, int charPos)
          Gets the line position of some character within a String, i.e the position within the line where the character occurs.
static StringUtil.TextPos getTextPos(String s, int charPos)
           
static boolean isInteger(String s)
           
static boolean isNumeric(String inputData)
           
static boolean isPostiveInteger(String s)
           
static String showDiff(String s1, String s2)
          Returns a String showing whether their length are equal and if so, where the first difference between two Strings occurs.
static void splitToCollection(String str, String sep, Collection<String> c)
          Add the trimmed elements of a String str seperated by some seperator sep to collection c
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

private StringUtil()
Method Detail

splitToCollection

public static void splitToCollection(String str,
                                     String sep,
                                     Collection<String> c)
Add the trimmed elements of a String str seperated by some seperator sep to collection c


isNumeric

public static boolean isNumeric(String inputData)

isInteger

public static boolean isInteger(String s)

isPostiveInteger

public static boolean isPostiveInteger(String s)

diff

public static int diff(String s1,
                       String s2)
Returns the index where String s1 and s2 differ for the first time, or returns -1 if they actually equal strings. If the two strings are not of equals size, and one of them is actually a prefix of the other, then the length of the shorter string is returned.


diffPos

public static StringUtil.TextPos diffPos(String s1,
                                         String s2)
Returns the TextPos where the two string differ for the first time. When the two strings are equal, an undefined TextPos is returned.


showDiff

public static String showDiff(String s1,
                              String s2)
Returns a String showing whether their length are equal and if so, where the first difference between two Strings occurs. If completely equal, or both are null, then the empty String is returned


getLineNumber

public static int getLineNumber(String s,
                                int charPos)
Counts the line number within a specified String, for a specified position inside that String. The first line gets number 0. A line ends at a \n char; this \n char still belongs to that line. The specified position should be less than the string length; if not, line number -1 is returned.


getLinePos

public static int getLinePos(String s,
                             int charPos)
Gets the line position of some character within a String, i.e the position within the line where the character occurs. The first line position is 0, the position of the \n that ends a line is the length of that line. The specified position should be less than the string length; if not, line position -1 is returned.


getTextPos

public static StringUtil.TextPos getTextPos(String s,
                                            int charPos)