本文整理匯總了Java中com.google.common.primitives.Chars類的典型用法代碼示例。如果您正苦於以下問題:Java Chars類的具體用法?Java Chars怎麽用?Java Chars使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Chars類屬於com.google.common.primitives包,在下文中一共展示了Chars類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: randomSecurely
import com.google.common.primitives.Chars; //導入依賴的package包/類
/**
* 윈도우의 암호 정책 사항
* <ul>
* <li>사용자의 계정 이름이나 연속되는 문자 2개를 초과하는 사용자 전체 이름의 일부를 포함하지 않음</li>
* <li>길이가 최소한 6자 이상이어야 함</li>
* <li>영문 대문자(A - Z),영문 소문자(a - z),기본 10개 숫자(0 - 9),알파벳 이외의 문자(예: !, $, #, %) 중 세 가지 범주의 문자를 포함해야 함</li>
* </ul>
*
* @param length
* @return
*/
public static String randomSecurely() {
RandomString strings = RandomString.getInstance();
StringBuilder pw = new StringBuilder();
{
pw.append(strings.randomAlpha(3).toLowerCase());
pw.append(strings.randomAlpha(3).toUpperCase());
pw.append(strings.randomNumeric(3));
pw.append(strings.random(2, "[email protected]#$%^&*"));
}
List<Character> chars = Lists.charactersOf(pw);
{
Collections.shuffle(chars, random);
}
return String.valueOf(Chars.toArray(chars));
}
示例4: 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);
}
示例5: RegexListSearcher
import com.google.common.primitives.Chars; //導入依賴的package包/類
public RegexListSearcher(String re) {
if (re.startsWith("^")) {
re = re.substring(1);
}
if (re.endsWith("$") && !re.endsWith("\\$")) {
re = re.substring(0, re.length() - 1);
}
Automaton automaton = new RegExp(re).toAutomaton();
prefixBegin = automaton.getCommonPrefix();
prefixLen = prefixBegin.length();
if (0 < prefixLen) {
char max = Chars.checkedCast(prefixBegin.charAt(prefixLen - 1) + 1);
prefixEnd = prefixBegin.substring(0, prefixLen - 1) + max;
prefixOnly = re.equals(prefixBegin + ".*");
} else {
prefixEnd = "";
prefixOnly = false;
}
pattern = prefixOnly ? null : new RunAutomaton(automaton);
}
示例6: readConstantField
import com.google.common.primitives.Chars; //導入依賴的package包/類
private BmdConstantField readConstantField() throws IOException {
int index = readInt32();
BmdBasicType type = BmdBasicType.fromInt(readInt32());
log("Field: " + type);
switch (type) {
case OBJECT:
case INT:
return new BmdConstantField(index, type, readInt32());
case BOOLEAN:
return new BmdConstantField(index, type, readBool());
case BYTE:
return new BmdConstantField(index, type, readRawByte());
case CHAR:
return new BmdConstantField(index, type, Chars.fromByteArray(readRawBytes(2)));
case FLOAT:
return new BmdConstantField(index, type, readFloat());
case DOUBLE:
return new BmdConstantField(index, type, readDouble());
case LONG:
return new BmdConstantField(index, type, readInt64());
case SHORT:
return new BmdConstantField(index, type, (short) readInt32());
default:
throw new IllegalArgumentException("Invalid field type: " + type);
}
}
示例7: 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);
}
示例8: getPropertyReservedNamingFirstChars
import com.google.common.primitives.Chars; //導入依賴的package包/類
public char[] getPropertyReservedNamingFirstChars() {
char[] reservedChars = anonymousFunctionNaming.getReservedCharacters();
if (polymerVersion != null && polymerVersion > 1) {
if (reservedChars == null) {
reservedChars = POLYMER_PROPERTY_RESERVED_FIRST_CHARS;
} else {
reservedChars = Chars.concat(reservedChars, POLYMER_PROPERTY_RESERVED_FIRST_CHARS);
}
} else if (angularPass) {
if (reservedChars == null) {
reservedChars = ANGULAR_PROPERTY_RESERVED_FIRST_CHARS;
} else {
reservedChars = Chars.concat(reservedChars, ANGULAR_PROPERTY_RESERVED_FIRST_CHARS);
}
}
return reservedChars;
}
示例9: testCharArrayValue
import com.google.common.primitives.Chars; //導入依賴的package包/類
@Test
public void testCharArrayValue() throws ExecutionException, InterruptedException, IOException {
int valueSize = 10;
char[] expected = new char[valueSize];
Arrays.fill(expected, 'X');
ChronicleMapBuilder<CharSequence, char[]> builder = ChronicleMapBuilder
.of(CharSequence.class, char[].class)
.entries(1);
try (ChronicleMap<CharSequence, char[]> map = newInstance(builder)) {
map.put("Key", expected);
assertEquals(Chars.asList(expected), Chars.asList(map.get("Key")));
mapChecks();
}
}
示例10: 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;
}
示例11: 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;
}
示例12: escape
import com.google.common.primitives.Chars; //導入依賴的package包/類
static String escape(String s) {
StringBuilder builder = new StringBuilder();
int len = s.length();
for (int i = 0; i < len; i++) {
char c = s.charAt(i);
int index = Chars.indexOf(SPECIAL_CHARS, c);
if (index != -1) {
builder.append(ESCAPED_SPECIAL_CHARS[index]);
} else if (isControlChar(c)) {
String hex = Integer.toHexString(c);
builder.append("\\u");
for (int j = 4; j > hex.length(); j--) {
builder.append('0');
}
builder.append(hex);
} else {
builder.append(c);
}
}
return builder.toString();
}
示例13: 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);
}
示例14: indexOf
import com.google.common.primitives.Chars; //導入依賴的package包/類
/**
* {@inheritDoc}
*
* @throws NullPointerException
* if the wrapped array was <code>null</code>.
*/
@Override
public int indexOf(Object o) {
// Will make the method fail if array is null.
if (size() < 1) {
return -1;
}
if (o instanceof Character) {
return Chars.indexOf(array, ((Character) o).charValue());
}
return -1;
}
示例15: lastIndexOf
import com.google.common.primitives.Chars; //導入依賴的package包/類
/**
* {@inheritDoc}
*
* @throws NullPointerException
* if the wrapped array was <code>null</code>.
*/
@Override
public int lastIndexOf(Object o) {
// Will make the method fail if array is null.
if (size() < 1) {
return -1;
}
if (o instanceof Character) {
return Chars.lastIndexOf(array, ((Character) o).charValue());
}
return -1;
}