本文整理匯總了Java中org.codehaus.plexus.util.StringUtils.trim方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.trim方法的具體用法?Java StringUtils.trim怎麽用?Java StringUtils.trim使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.codehaus.plexus.util.StringUtils
的用法示例。
在下文中一共展示了StringUtils.trim方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getGravatarUrl
import org.codehaus.plexus.util.StringUtils; //導入方法依賴的package包/類
private String getGravatarUrl( String email )
{
if ( email == null )
{
return null;
}
email = StringUtils.trim( email );
email = email.toLowerCase();
MessageDigest md;
try
{
md = MessageDigest.getInstance( "MD5" );
md.update( email.getBytes() );
byte byteData[] = md.digest();
StringBuilder sb = new StringBuilder();
final int lowerEightBitsOnly = 0xff;
for ( byte aByteData : byteData )
{
sb.append( Integer.toString( ( aByteData & lowerEightBitsOnly ) + 0x100, 16 ).substring( 1 ) );
}
return "http://www.gravatar.com/avatar/" + sb.toString() + "?d=mm&" + AVATAR_SIZE;
}
catch ( NoSuchAlgorithmException e )
{
return null;
}
}
示例2: getVersion
import org.codehaus.plexus.util.StringUtils; //導入方法依賴的package包/類
@Override
public String getVersion( MavenProject mavenProject )
throws ExternalVersionException
{
String newVersion = System.getProperty( EXTERNAL_VERSION, mavenProject.getVersion() );
String qualifier = StringUtils.trim( System.getProperty( EXTERNAL_VERSION_QUALIFIER ) );
if ( StringUtils.isNotBlank( qualifier ) )
{
// TODO: this needs to be cleaned up, the calling method will re-add the -SNAPSHOT if needed, but this is dirty
newVersion = newVersion.replaceFirst( "-SNAPSHOT", "" ) + "-" + qualifier;
}
return newVersion;
}
示例3: getDurationBreakdown
import org.codehaus.plexus.util.StringUtils; //導入方法依賴的package包/類
/**
* Convert a millisecond duration to a string format.
* @param durationMs A duration to convert to a string form.
* @param showSign {@code true} to show if the duration is positive or negative. {@code false}
* to not display the sign.
* @return A string of the form "X Days Y Hours Z Minutes A Seconds B Milliseconds".
*/
public static String getDurationBreakdown(final long durationMs, final boolean showSign) {
long tempDurationMs = Math.abs(durationMs);
final long days = TimeUnit.MILLISECONDS.toDays(tempDurationMs);
tempDurationMs -= TimeUnit.DAYS.toMillis(days);
final long hours = TimeUnit.MILLISECONDS.toHours(tempDurationMs);
tempDurationMs -= TimeUnit.HOURS.toMillis(hours);
final long minutes = TimeUnit.MILLISECONDS.toMinutes(tempDurationMs);
tempDurationMs -= TimeUnit.MINUTES.toMillis(minutes);
final long seconds = TimeUnit.MILLISECONDS.toSeconds(tempDurationMs);
tempDurationMs -= TimeUnit.SECONDS.toMillis(seconds);
final long milliseconds = TimeUnit.MILLISECONDS.toMillis(tempDurationMs);
final StringBuilder sb = new StringBuilder();
if (tempDurationMs != 0 && showSign) {
sb.append(tempDurationMs > 0 ? "+" : "-");
}
if (days > 0) {
sb.append(days);
sb.append(days == 1 ? " Day " : " Days ");
}
if (hours > 0) {
sb.append(hours);
sb.append(hours == 1 ? " Hour " : " Hours ");
}
if (minutes > 0) {
sb.append(minutes);
sb.append(minutes == 1 ? " Minute " : " Minutes ");
}
if (seconds > 0) {
sb.append(seconds);
sb.append(seconds == 1 ? " Second " : " Seconds " );
}
if (milliseconds > 0 || (!showSign && sb.length() == 0) || (showSign && sb.length() == 1)) {
// At least show the milliseconds if nothing else has been shown so far
sb.append(milliseconds);
sb.append(milliseconds == 1 ? " Millisecond" : " Milliseconds");
}
return StringUtils.trim(sb.toString());
}