本文整理汇总了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])));
}
}
示例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);
}
}
示例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.";
}
示例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";
}
示例5: getTwitterDescription
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public static String getTwitterDescription(String text) {
return StringUtils.abbreviate(text, 200);
}
示例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 + "\"");
}
}
示例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;
}
示例8: toString
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public String toString() {
return "(" + logger + ") : log." + level + "(" + StringUtils.abbreviate(expression, 25) + ")";
}
示例9: toString
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public String toString() {
return StringUtils.abbreviate(variableName, 20);
}
示例10: toString
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public String toString() {
String name = "<" + tagname + ">eval('" + StringUtils.abbreviate(expression, 15) + "')</" + tagname + ">";
return name;
}
示例11: toString
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public String toString() {
return StringUtils.abbreviate(variableName, 20);
}
示例12: toString
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public String toString() {
return "set(" + key + ")=" + StringUtils.abbreviate(expression, 25);
}
示例13: toString
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public String toString() {
return "log." + level + "(" +(StringUtils.abbreviate(expression, 25)) + ")";
}
示例14: toString
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public String toString() {
String msg = "Wait " + trigger.toString();
return StringUtils.abbreviate(msg, 30);
}
示例15: toString
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public String toString() {
return "cookies.add(eval('" + StringUtils.abbreviate(expression, 25) + "'))";
}