本文整理匯總了Java中com.google.common.primitives.Chars.toArray方法的典型用法代碼示例。如果您正苦於以下問題:Java Chars.toArray方法的具體用法?Java Chars.toArray怎麽用?Java Chars.toArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.primitives.Chars
的用法示例。
在下文中一共展示了Chars.toArray方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setUp
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
@BeforeExperiment void setUp() {
random = new Random(0xdeadbeef); // fix the seed so results are comparable across runs
int nonAlpha = size / nonAlphaRatio;
int alpha = size - nonAlpha;
List<Character> chars = Lists.newArrayListWithCapacity(size);
for (int i = 0; i < alpha; i++) {
chars.add(randomAlpha());
}
for (int i = 0; i < nonAlpha; i++) {
chars.add(randomNonAlpha());
}
Collections.shuffle(chars, random);
char[] array = Chars.toArray(chars);
this.testString = new String(array);
}
示例2: toArray
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
@SuppressWarnings({"unchecked", "rawtypes"}) // NOTE: We assume the component type matches the list
private Object toArray(Class<?> componentType, List<Object> values) {
if (componentType == boolean.class) {
return Booleans.toArray((Collection) values);
} else if (componentType == byte.class) {
return Bytes.toArray((Collection) values);
} else if (componentType == short.class) {
return Shorts.toArray((Collection) values);
} else if (componentType == int.class) {
return Ints.toArray((Collection) values);
} else if (componentType == long.class) {
return Longs.toArray((Collection) values);
} else if (componentType == float.class) {
return Floats.toArray((Collection) values);
} else if (componentType == double.class) {
return Doubles.toArray((Collection) values);
} else if (componentType == char.class) {
return Chars.toArray((Collection) values);
}
return values.toArray((Object[]) Array.newInstance(componentType, values.size()));
}
示例3: setUp
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
@BeforeExperiment void setUp() {
random = new Random();
int nonAlpha = size / nonAlphaRatio;
int alpha = size - nonAlpha;
List<Character> chars = Lists.newArrayListWithCapacity(size);
for (int i = 0; i < alpha; i++) {
chars.add(randomAlpha());
}
for (int i = 0; i < nonAlpha; i++) {
chars.add(randomNonAlpha());
}
Collections.shuffle(chars, random);
char[] array = Chars.toArray(chars);
this.testString = new String(array);
}
示例4: setUp
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
@BeforeExperiment
void setUp() {
random = new Random(0xdeadbeef); // fix the seed so results are comparable across runs
int nonAlpha = size / nonAlphaRatio;
int alpha = size - nonAlpha;
List<Character> chars = Lists.newArrayListWithCapacity(size);
for (int i = 0; i < alpha; i++) {
chars.add(randomAlpha());
}
for (int i = 0; i < nonAlpha; i++) {
chars.add(randomNonAlpha());
}
Collections.shuffle(chars, random);
char[] array = Chars.toArray(chars);
this.testString = new String(array);
}
示例5: create
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
@Override
public List<Character> create(Character[] elements) {
char[] chars = Chars.toArray(Arrays.asList(elements));
StringBuilder str = new StringBuilder();
str.append(chars);
return Lists.charactersOf(str);
}
示例6: reserveCharacters
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
/**
* Provides the array of available characters based on the specified arrays.
* @param chars The list of characters that are legal
* @param reservedCharacters The characters that should not be used
* @return An array of characters to use. Will return the chars array if
* reservedCharacters is null or empty, otherwise creates a new array.
*/
static char[] reserveCharacters(char[] chars, char[] reservedCharacters) {
if (reservedCharacters == null || reservedCharacters.length == 0) {
return chars;
}
Set<Character> charSet = Sets.newLinkedHashSet(Chars.asList(chars));
for (char reservedCharacter : reservedCharacters) {
charSet.remove(reservedCharacter);
}
return Chars.toArray(charSet);
}
示例7: reserveCharacters
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
/**
* Provides the array of available characters based on the specified arrays.
* @param chars The list of characters that are legal
* @param reservedCharacters The characters that should not be used
* @return An array of characters to use. Will return the chars array if
* reservedCharacters is null or empty, otherwise creates a new array.
*/
static char[] reserveCharacters(char[] chars, char[] reservedCharacters) {
if (reservedCharacters == null || reservedCharacters.length == 0) {
return chars;
}
Set<Character> charSet = Sets.newLinkedHashSet(Chars.asList(chars));
for (char reservedCharacter : reservedCharacters) {
charSet.remove(reservedCharacter);
}
return Chars.toArray(charSet);
}
示例8: NumberSystem
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
public NumberSystem(String digits) {
checkArgument(
checkNotNull(digits, "digits must not be null").length() > 1,
"digits must contain at least two characters");
List<Character> characters = Lists.charactersOf(digits);
checkState(Sets.newHashSet(characters).size() == digits.length(),
"Duplicates found in %s", digits);
this.digits = Chars.toArray(characters);
this.numDigits = digits.length();
}
示例9: create
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
@Override public List<Character> create(Character[] elements) {
char[] chars = Chars.toArray(Arrays.asList(elements));
return Lists.charactersOf(String.copyValueOf(chars));
}
示例10: shuffleAndCopyAlphabet
import com.google.common.primitives.Chars; //導入方法依賴的package包/類
private static String shuffleAndCopyAlphabet(Set<Character> input, Random random) {
List<Character> shuffled = new ArrayList<>(input);
Collections.shuffle(shuffled, random);
return new String(Chars.toArray(shuffled));
}