Java Code Examples for org.apache.commons.lang3.StringUtils.abbreviate()

The following are Jave code examples for showing how to use abbreviate() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: dremio-oss   File: IndexKey.java   View Source Code Vote up 6 votes
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])));
  }
}
 
Example 2
Project: syndesis   File: SwaggerUnifiedShapeConnectorGenerator.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 3
Project: PastaBot   File: PastaCommand.java   View Source Code Vote up 5 votes
@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.";
}
 
Example 4
Project: PastaBot   File: JokeCommand.java   View Source Code Vote up 5 votes
@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";
}
 
Example 5
Project: nixmash-blog   File: JsoupUtil.java   View Source Code Vote up 4 votes
public static String getTwitterDescription(String text) {
    return StringUtils.abbreviate(text, 200);
}
 
Example 6
Project: myfaces-trinidad   File: RenderKitTestCase.java   View Source Code Vote up 4 votes
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 + "\"");
  }
}
 
Example 7
Project: rufus   File: FeedUtils.java   View Source Code Vote up 4 votes
public static String truncate(String value, int maxLength) {
    String ret;
    ret = value.length() > maxLength ? StringUtils.abbreviate(value, maxLength) : value;
    return ret;
}
 
Example 8
Project: convertigo-engine   File: LogStep.java   View Source Code Vote up 4 votes
@Override
public String toString() {
	return "(" + logger + ") : log." + level + "(" + StringUtils.abbreviate(expression, 25) + ")";
}
 
Example 9
Project: convertigo-engine   File: GetNodesStatement.java   View Source Code Vote up 4 votes
@Override
public String toString() {
	return StringUtils.abbreviate(variableName, 20);
}
 
Example 10
Project: convertigo-engine   File: ContextAddTextNodeStatement.java   View Source Code Vote up 4 votes
public String toString() {
	String name = "<" + tagname + ">eval('" + StringUtils.abbreviate(expression, 15) + "')</" + tagname + ">";
	return name;
}
 
Example 11
Project: convertigo-engine   File: GetUrlStatement.java   View Source Code Vote up 4 votes
@Override		
public String toString() {
	return StringUtils.abbreviate(variableName, 20);
}
 
Example 12
Project: convertigo-engine   File: ContextSetStatement.java   View Source Code Vote up 4 votes
public String toString() {
	return "set(" + key + ")=" + StringUtils.abbreviate(expression, 25);
}
 
Example 13
Project: convertigo-engine   File: LogStatement.java   View Source Code Vote up 4 votes
@Override
public String toString() {
	return "log." + level + "(" +(StringUtils.abbreviate(expression, 25)) + ")";
}
 
Example 14
Project: convertigo-engine   File: WaitTriggerStatement.java   View Source Code Vote up 4 votes
@Override
public String toString() {
	String msg = "Wait " + trigger.toString();
	return  StringUtils.abbreviate(msg, 30);
}
 
Example 15
Project: convertigo-engine   File: CookiesAddStatement.java   View Source Code Vote up 4 votes
@Override
public String toString() {
	return "cookies.add(eval('" + StringUtils.abbreviate(expression, 25) + "'))";
}