Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.util.StringUtil Class Reference

Static Public Member Functions

static< TextendsCollection<?superString > T copyPartialMatches (final String token, final Iterable< String > originals, final T collection) throws UnsupportedOperationException, IllegalArgumentException
static boolean startsWithIgnoreCase (final String string, final String prefix) throws IllegalArgumentException, NullPointerException

Detailed Description

Definition at line 6 of file StringUtil.java.

Member Function Documentation

static <TextendsCollection<?superString> T org.bukkit.util.StringUtil.copyPartialMatches ( final String  token,
final Iterable< String >  originals,
final T  collection 
) throws UnsupportedOperationException, IllegalArgumentException

Copies all elements from the iterable collection of originals to the collection provided.

tokenString to search for
originalsAn iterable collection of strings to filter.
collectionThe collection to add matches to
the collection provided that would have the elements copied into
UnsupportedOperationExceptionif the collection is immutable and originals contains a string which starts with the specified search string.
IllegalArgumentExceptionif any parameter is is null
IllegalArgumentExceptionif originals contains a null element. Note: the collection may be modified before this is thrown

Definition at line 24 of file StringUtil.java.

References org.bukkit.util.StringUtil.startsWithIgnoreCase().

24  {
25  Validate.notNull(token, "Search token cannot be null");
26  Validate.notNull(collection, "Collection cannot be null");
27  Validate.notNull(originals, "Originals cannot be null");
29  for (String string : originals) {
30  if (startsWithIgnoreCase(string, token)) {
31  collection.add(string);
32  }
33  }
35  return collection;
36  }
static boolean startsWithIgnoreCase(final String string, final String prefix)
Definition: StringUtil.java:50
static boolean org.bukkit.util.StringUtil.startsWithIgnoreCase ( final String  string,
final String  prefix 
) throws IllegalArgumentException, NullPointerException

This method uses a region to check case-insensitive equality. This means the internal array does not need to be copied like a toLowerCase() call would.

stringString to check
prefixPrefix of string to compare
true if provided string starts with, ignoring case, the prefix provided
NullPointerExceptionif prefix is null
IllegalArgumentExceptionif string is null

Definition at line 50 of file StringUtil.java.

Referenced by org.bukkit.util.StringUtil.copyPartialMatches(), org.bukkit.command.Command.tabComplete(), and org.bukkit.command.SimpleCommandMap.tabComplete().

50  {
51  Validate.notNull(string, "Cannot check a null string for a match");
52  if (string.length() < prefix.length()) {
53  return false;
54  }
55  return string.regionMatches(true, 0, prefix, 0, prefix.length());
56  }

The documentation for this class was generated from the following file: