当前位置: 首页>>代码示例>>Java>>正文


Java StringUtils.abbreviate方法代码示例

本文整理汇总了Java中org.apache.commons.lang3.StringUtils.abbreviate方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.abbreviate方法的具体用法?Java StringUtils.abbreviate怎么用?Java StringUtils.abbreviate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang3.StringUtils的用法示例。


在下文中一共展示了StringUtils.abbreviate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addToDoc

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
void addToDoc(Document doc, String... values){
  Preconditions.checkArgument(valueType == String.class);
  if (isSorted()) {
    Preconditions.checkArgument(values.length < 2, "sorted fields cannot have multiple values");
  }

  // add distinct elements to doc
  final Iterable<String> nonNull = FluentIterable.from(Arrays.asList(values))
      .filter(new Predicate<String>() {
        @Override
        public boolean apply(@Nullable final String input) {
          return input != null;
        }
      });

  for (final String value : ImmutableSet.copyOf(nonNull)) {
    final String truncatedValue = StringUtils.abbreviate(value, MAX_STRING_LENGTH);
    doc.add(new StringField(indexFieldName, truncatedValue, stored ? Store.YES : Store.NO));
  }

  if (isSorted() && values.length == 1) {
    Preconditions.checkArgument(sortedValueType == SearchFieldSorting.FieldType.STRING);
    doc.add(new SortedDocValuesField(indexFieldName, new BytesRef(values[0])));
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:26,代码来源:IndexKey.java

示例2: parseJsonSchema

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private static JsonNode parseJsonSchema(final String schema) {
    try {
        return Json.mapper().readTree(schema);
    } catch (final IOException e) {
        throw new IllegalStateException("Unable to parse given JSON schema: " + StringUtils.abbreviate(schema, 100), e);
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:8,代码来源:SwaggerUnifiedShapeConnectorGenerator.java

示例3: onPastaCommand

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Command(aliases = {"pasta", "copypasta"}, description = "Gets a random copypasta from /r/copypasta.", usage = "pasta")
public static String onPastaCommand(String[] args, IMessage message) throws OAuthException, RateLimitException, DiscordException, MissingPermissionsException {
    Listing<Submission> copypasta = null;
    RedditClient redditClient;
    try {
        redditClient = Reddit.getRedditClient();
        if (!redditClient.isAuthenticated()) {
            Reddit.authReddit();
        }
        FluentRedditClient fluent = new FluentRedditClient(redditClient);
        copypasta = fluent.subreddit("copypasta").fetch();
    }   catch (NetworkException | NullPointerException e) {
        Reddit.authReddit();
        onPastaCommand(args, message);
    }

    System.out.println("Serving some pasta.");
    Random random = new Random();
    if (copypasta != null) {
        Submission pasta = copypasta.get(random.nextInt(copypasta.size()));
        if (args.length > 0) {
            message.delete();
            return "Too many arguments! Use `~help` to get usages.";
        } else if (args.length == 0) {
            message.delete();
            return StringUtils.abbreviate((":spaghetti: " + "**" + pasta.getTitle() + "**\n" + pasta.getSelftext()), 2000);
        }
    }

    // Something went wrong, display error message
    message.delete();
    return "An error occurred, please try again later.";
}
 
开发者ID:nbd9,项目名称:PastaBot,代码行数:34,代码来源:PastaCommand.java

示例4: onJokeCommand

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Command(aliases = {"joke", "prank"}, description = "Gets a random joke from /r/jokes.", usage = "joke")
public static String onJokeCommand(String[] args, IMessage message) throws OAuthException, RateLimitException, DiscordException, MissingPermissionsException {
    Listing<Submission> jokes = null;
    RedditClient redditClient;
    try {
        redditClient = Reddit.getRedditClient();
        if (!redditClient.isAuthenticated()) {
            Reddit.authReddit();
        }
        FluentRedditClient fluent = new FluentRedditClient(redditClient);
        jokes = fluent.subreddit("jokes").fetch();
    }   catch (NetworkException | NullPointerException e) {
        Reddit.authReddit();
        onJokeCommand(args, message);
    }

    Random random = new Random();
    System.out.println("Telling a bad joke.");

    if (jokes != null) {
        Submission joke = jokes.get(random.nextInt(jokes.size()));
        if (args.length > 0) {
            message.delete();
            return "Too many arguments! Use `~help` to get usages.";
        } else if (args.length == 0) {
            message.delete();
            return StringUtils.abbreviate((":rofl: " + "**" + joke.getTitle() + "**\n" + joke.getSelftext()), 2000);
        }
    }

    // Something went wrong, display error message.
    message.delete();
    return "An error occurred, please try again";
}
 
开发者ID:nbd9,项目名称:PastaBot,代码行数:35,代码来源:JokeCommand.java

示例5: getTwitterDescription

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public static String getTwitterDescription(String text) {
    return StringUtils.abbreviate(text, 200);
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:4,代码来源:JsoupUtil.java

示例6: _throwAssertionFailure

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private void _throwAssertionFailure(String golden, String results, boolean forceGolden)
{
  if (golden == null)
  {
    // Don't report "no golden file" as an error when
    // forceGolden is on; but do report diffs as errors
    if (!forceGolden)
    {
      throw new AssertionFailedError("No golden file for test " +
                                     _scriptName);
    }
  } else
  {
    int index = StringUtils.indexOfDifference(golden, results);
    String difference = StringUtils.difference(golden, results);
    int diffLength = difference.length();
    if (diffLength > 50)
      difference = StringUtils.abbreviate(difference, 50);
    /*
    int resultsLength = results.length();
    int goldenLength = golden.length();
    
    if (resultsLength != goldenLength)
    {
      if (resultsLength < goldenLength)
      {
        throw new AssertionFailedError("golden file longer by:" + (goldenLength - resultsLength) + " char='" + ((int)golden.charAt(index)) + "'");
      }
      else
      {
        throw new AssertionFailedError("results file longer by:" + (resultsLength - goldenLength));            
      }
    }
    
    if (index >= resultsLength)
      throw new AssertionFailedError("golden file longer by:" + (goldenLength - resultsLength));
      
    if (results.length() < 50)
    {
      throw new AssertionFailedError(
           "Golden file for test "+ _scriptName + " did not match; " +
           "first difference at " + index + ", difference of length " +
           diffLength + ", \"" + difference + "\"" + "\ngolden:\n" + golden + "\nnew:\n" + results + "\ndiffChars g='" + golden.charAt(index) + "' r='" + results.charAt(index) + "'");
      
    }
    */
    throw new AssertionFailedError(
        "Golden file for test " + _scriptName + " did not match; " +
        "first difference at " + index + ", difference of length " +
        diffLength + ", \"" + difference + "\"");
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:53,代码来源:RenderKitTestCase.java

示例7: truncate

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public static String truncate(String value, int maxLength) {
    String ret;
    ret = value.length() > maxLength ? StringUtils.abbreviate(value, maxLength) : value;
    return ret;
}
 
开发者ID:jtanza,项目名称:rufus,代码行数:6,代码来源:FeedUtils.java

示例8: toString

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public String toString() {
	return "(" + logger + ") : log." + level + "(" + StringUtils.abbreviate(expression, 25) + ")";
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:5,代码来源:LogStep.java

示例9: toString

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public String toString() {
	return StringUtils.abbreviate(variableName, 20);
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:5,代码来源:GetNodesStatement.java

示例10: toString

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public String toString() {
	String name = "<" + tagname + ">eval('" + StringUtils.abbreviate(expression, 15) + "')</" + tagname + ">";
	return name;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:5,代码来源:ContextAddTextNodeStatement.java

示例11: toString

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override		
public String toString() {
	return StringUtils.abbreviate(variableName, 20);
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:5,代码来源:GetUrlStatement.java

示例12: toString

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public String toString() {
	return "set(" + key + ")=" + StringUtils.abbreviate(expression, 25);
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:4,代码来源:ContextSetStatement.java

示例13: toString

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public String toString() {
	return "log." + level + "(" +(StringUtils.abbreviate(expression, 25)) + ")";
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:5,代码来源:LogStatement.java

示例14: toString

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public String toString() {
	String msg = "Wait " + trigger.toString();
	return  StringUtils.abbreviate(msg, 30);
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:6,代码来源:WaitTriggerStatement.java

示例15: toString

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public String toString() {
	return "cookies.add(eval('" + StringUtils.abbreviate(expression, 25) + "'))";
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:5,代码来源:CookiesAddStatement.java


注:本文中的org.apache.commons.lang3.StringUtils.abbreviate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。