[Home] DMelt member access. Java source code: info.monitorenter.util.StringUtil
/*
* StringUtil, utility class for string operations.
* Copyright (C) 2004 - 2011 Achim Westermann.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* If you modify or optimize the code in a useful way please let me know.
* Achim.Westermann@gmx.de
*
*/
package info.monitorenter.util;
import java.lang.reflect.Array;
import java.util.List;
/**
* Nice static helpers for working with Strings.
*
* Maybe not always the fastest solution to call in here, but working. Also
* usable for seeing examples and cutting code for manual inlining.
*
*
* @author Achim.Westermann@gmx.de
*
* @version $Revision: 1.10 $
*/
public final class StringUtil {
/** Singleton instance. */
private static StringUtil instance = null;
/**
* Appends the given amount of spaces to the String.
*
*
* Not intended for big append -operations because in a loop alway just one
* space is added.
*
*
* @param s
* the base String to append spaces to.
*
* @param count
* the amount of spaces to append.
*
* @return a String consisting of s and count trailing whitespaces.
*/
public static final String appendSpaces(final String s, final int count) {
StringBuffer tmp = new StringBuffer(s);
for (int i = 0; i < count; i++) {
tmp.append(" ");
}
return tmp.toString();
}
/**
* Little String output - helper that modifies the given LinkedList by getting
* it's Objects and replace them by their toString() - representation.
*
*
* What is special?
* If an Object in the given List is an Array (of Objects or primitive data
* types) reflection will be used to create a String - representation of them.
* The changes are reflected in the Objects that are in the given List. So
* keep a reference to it. If you are sure, that your List does not contain
* Arrays do not use this method to avoid overhead.
*
*
* Avoid structural modifications (remove) of the list while using this
* method. This method or better: the given List is only thread - safe if the
* list is synchronized.
*
*
* A clever VM (hotspot) will be able to inline this function because of void
* return.
*
*
* @param objects
* the List of objects that will be changed to a list of the String
* representation of the Objects with respect to special array
* treatment.
*
*/
public static final void listOfArraysToString(final List