本文整理匯總了Java中com.google.common.primitives.Chars.asList方法的典型用法代碼示例。如果您正苦於以下問題:Java Chars.asList方法的具體用法?Java Chars.asList怎麽用?Java Chars.asList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.primitives.Chars
的用法示例。
在下文中一共展示了Chars.asList方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: filter
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
@Override
public Object filter(Object var, JinjavaInterpreter interpreter, String... args) {
List<?> result;
if (var instanceof String) {
result = Chars.asList(((String) var).toCharArray());
}
else if (Collection.class.isAssignableFrom(var.getClass())) {
result = Lists.newArrayList((Collection<?>) var);
}
else {
result = Lists.newArrayList(var);
}
return result;
}
示例2: split
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
/**
* Split iterable.
*
* @param str the str
* @param separators the separators
* @return the iterable
*/
public static Iterable<String> split(final String str, final char... separators) {
if (isEmpty(str))
return Lists.newArrayList();
List<String> result = Lists.newArrayList();
List<Character> seps = Chars.asList(separators);
int length = str.length();
int startIndex = 0;
for (int i = 0; i < length; i++) {
if (seps.contains(str.charAt(i))) {
if (i - 1 - startIndex > 0) {
result.add(str.substring(startIndex, i - 1));
}
startIndex = i + 1;
}
}
return result;
}
示例3: testSanitizesRegularProperty
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
public void testSanitizesRegularProperty() {
// Test boundaries.
char[] boundaryChars = {/* '/' is allowed */ ':', '@', '[', '`', '{'};
for (Character c : Chars.asList(boundaryChars)) {
assertBackgroundSizeStringSanitized(c.toString());
}
// Empty strings.
assertBackgroundSizeStringSanitized("");
assertBackgroundSizeStringSanitized(" ");
assertBackgroundSizeStringSanitized("\t");
// Unlike jslayout, comma is not allowed.
assertBackgroundSizeStringSanitized(",");
// Non-whitelisted characters.
assertBackgroundSizeStringSanitized(";");
// Function call characters.
assertBackgroundSizeStringSanitized("(");
assertBackgroundSizeStringSanitized(")");
assertBackgroundSizeStringSanitized("calc()");
// Newlines.
assertBackgroundSizeStringSanitized("\n");
assertBackgroundSizeStringSanitized("\r");
// Comments.
assertBackgroundSizeStringSanitized("foo /*");
assertBackgroundSizeStringSanitized("foo //foo");
// Escape sequences.
assertBackgroundSizeStringSanitized("\\ff ");
}
示例4: replace
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
/**
* Replaces all values in the input with the corresponding values from the {@link ArenaScoreboard#replacements}
*
* @param input the input string
* @param player the player
* @return the new string
* @since 5.3.0
*/
@NotNull
@Contract(value = "null, _ -> fail", pure = true)
private String replace(String input, Player player) {
List<Character> list = new ArrayList<>(Chars.asList(input.toCharArray()));
Matcher matcher = Pattern.compile("%([^%]+)%").matcher(input);
while (matcher.find()) {
for (int i = matcher.start(); i < matcher.end(); i++)
list.remove(matcher.start());
Function<Player, String> function = replacements.get(matcher.group(1));
if (function == null)
continue;
char[] replacement = function.apply(player).toCharArray();
int length = replacement.length;
for (int i = 0; i < length; i++)
list.add(matcher.start() + i, replacement[i]);
StringBuilder builder = new StringBuilder();
for (char c : list)
builder.append(c);
input = builder.toString();
matcher.reset(input);
}
return input;
}
示例5: asCharList
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
/**
* Wrap a character sequence in a list so it can be scanned by a pattern.
*
* @param charSequence The backing sequence.
* @return A list wrapping the sequence.
*/
public static List<Character> asCharList(CharSequence charSequence) {
// TODO: no copies - wrap the sequence for real.
if (charSequence instanceof String) {
char[] chars = ((String) charSequence).toCharArray();
return Chars.asList(chars);
}
ArrayList<Character> charList = new ArrayList<>(charSequence.length());
for (int i = 0; i < charSequence.length(); i++) {
charList.add(charSequence.charAt(i));
}
return charList;
}
示例6: deleteCharAny
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
/**
* Delete char any.
*
* @param str the str
* @param chars the chars
* @return the string
*/
public static String deleteCharAny(final String str, final char... chars) {
if (isEmpty(str))
return str;
StringBuilder builder = new StringBuilder();
final List<Character> charList = Chars.asList(chars);
char[] strArray = str.toCharArray();
for (char c : strArray) {
if (!charList.contains(c))
builder.append(c);
}
return builder.toString();
}
示例7: deleteChar
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
/**
* Delete char.
*
* @param str the str
* @param chars the chars
* @return the string
*/
public static String deleteChar(final String str, final char[] chars) {
if (isEmpty(str))
return str;
StringBuilder builder = new StringBuilder();
final List<Character> charList = Chars.asList(chars);
char[] strArray = str.toCharArray();
for (char c : strArray) {
if (!charList.contains(c))
builder.append(c);
}
return builder.toString();
}
示例8:
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
public static Iterable<Character> $in(char[] elements) {
return Chars.asList(elements);
}
示例9: swapCase
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
public static String swapCase(String str) {
List<Character> chars = Chars.asList(nullToEmpty(str).toCharArray());
return from(chars).transform(flip()).join(on(""));
}
示例10: translate
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
public static String translate(String str, HashMap<Character, Character> dictionary, HashSet<Character> deletedChars) {
List<Character> chars = Chars.asList(nullToEmpty(str).toCharArray());
return from(chars).filter(without(deletedChars)).transform(in(dictionary)).filter(without(new HashSet<Character>() {{
add(null);
}})).join(on(""));
}
示例11: ascii
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
public static Optional<String> ascii(String s) {
List<Character> chars = Chars.asList(nullToEmpty(s).toCharArray());
return from(chars).transform(isAscii()).allMatch(is(true)) ? Optional.<String>of(s) : Optional.<String>absent();
}
示例12: getSpecialChars
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
static List<Character> getSpecialChars() {
return Chars.asList(SPECIAL_CHARS);
}
示例13: MyCompletionProvider
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
MyCompletionProvider(@Nonnull Collection<String> values, boolean supportsNegativeValues) {
super(new DefaultTextCompletionValueDescriptor.StringValueDescriptor(),
supportsNegativeValues ? ContainerUtil.append(Chars.asList(SEPARATORS), '-') : Chars.asList(SEPARATORS), values, false);
}