org.knime.core.node.util
Class StringFormat

java.lang.Object
  extended by org.knime.core.node.util.StringFormat

public final class StringFormat
extends Object

Collection of convenience methods to format strings (such as elapsed time or urls).

Author:
Bernd Wiswedel, University of Konstanz

Method Summary
static String formatElapsedTime(long timeInMS)
          Formats a time difference into a string stating elapsed days, hours etc.
static String formatPath(String str, int size)
          Formats paths such as file locations or URLs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

formatPath

public static String formatPath(String str,
                                int size)
Formats paths such as file locations or URLs. This method is used for instance in KNIME's file reader dialog to shrink the file location while maintaining the most important parts of the location (protocol and file name).

The pattern is as follows: If size is smaller than 30, return the last size chars in the string (plus some dots in front); if the size is larger than 30: return the first 12 chars + ... + chars from the end. If it is larger than 55: the first 28 + ... + rest from the end.

Parameters:
str - The string to format. If null an empty string is returned.
size - The requested size. Negative or too small (< 3) values are treated with respect, i.e. no exception is thrown.
Returns:
The formatted string.

formatElapsedTime

public static String formatElapsedTime(long timeInMS)
Formats a time difference into a string stating elapsed days, hours etc. Days, hours, and minutes are only printed if they need to (meaning that for instance formatElapsedTime(3000L) will only return "3 secs").

Parameters:
timeInMS - The time in milliseconds, negative values will be preceded by a minus sign
Returns:
The formatted string.


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.