git clone of logicmail with some fixes/features added
at master 63 lines 2.1 kB view raw
1//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2// This file is part of J2MEUnit, a Java 2 Micro Edition unit testing framework. 3// 4// J2MEUnit is free software distributed under the Common Public License (CPL). 5// It may be redistributed and/or modified under the terms of the CPL. You 6// should have received a copy of the license along with J2MEUnit. It is also 7// available from the website of the Open Source Initiative at 8// http://www.opensource.org. 9// 10// J2MEUnit is distributed in the hope that it will be useful, but WITHOUT ANY 11// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12// FOR A PARTICULAR PURPOSE. 13//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 14package j2meunit.util; 15 16/******************************************************************** 17 * A class with junit related String utilities. 18 */ 19public class StringUtil 20{ 21 //~ Constructors ----------------------------------------------------------- 22 23 /*************************************** 24 * Creates a new StringUtil object. 25 */ 26 protected StringUtil() 27 { 28 } 29 30 //~ Methods ---------------------------------------------------------------- 31 32 /*************************************** 33 * Assumes the argument to be a decimal number of milliseconds and formats 34 * it into a string. 35 * 36 * @param nTime The time value to convert 37 * 38 * @return A string containing the converted value 39 */ 40 public static String elapsedTimeAsString(long nTime) 41 { 42 return nTime + "ms"; 43 } 44 45 /*************************************** 46 * Truncates a string to a maximum length. 47 * 48 * @param s The string to truncate 49 * @param length The maximum length of the string 50 * 51 * @return If the string is longer than length, the truncated string, else 52 * the original string 53 */ 54 public static String truncate(String s, int length) 55 { 56 length -= 3; 57 58 if (s.length() > length) 59 s = s.substring(0, length) + "..."; 60 61 return s; 62 } 63}