本文整理汇总了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());
}