下面列出了com.google.common.base.CharMatcher#is ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static int[] indicesOf(String input, char c) {
CharMatcher matcher = CharMatcher.is(c);
int count = matcher.countIn(input);
int[] indices = new int[count];
int lastIndex = 0;
for (int i = 0; i < count; i++) {
indices[i] = input.indexOf(c, lastIndex + 1);
lastIndex = indices[i];
}
return indices;
}
@Override
protected Object convertValue(String... values) {
final Object result = Array.newInstance(field.getType().getComponentType(), values.length);
final CharMatcher matcher = CharMatcher.is('"');
for (int i = 0; i < values.length; i++) {
final String value = matcher.trimFrom(StringUtils.strip(values[i]));
final Object converted = converter.readFromString(value);
Array.set(result, i, converted);
}
return result;
}
@Override
CharMatcher padding() {
return (paddingChar == null)
? CharMatcher.none()
: CharMatcher.is(paddingChar.charValue());
}
@Override
CharMatcher padding() {
return (paddingChar == null)
? CharMatcher.none()
: CharMatcher.is(paddingChar.charValue());
}
@Override
CharMatcher padding() {
return (paddingChar == null)
? CharMatcher.none()
: CharMatcher.is(paddingChar.charValue());
}
@Override
CharMatcher padding() {
return (paddingChar == null)
? CharMatcher.none()
: CharMatcher.is(paddingChar.charValue());
}
@Override
CharMatcher padding() {
return (paddingChar == null) ? CharMatcher.none() : CharMatcher.is(paddingChar.charValue());
}
private boolean configureWorkspace(ResourceSet resourceSet) {
List<File> sourceFileList = getSourcePathFileList();
File outputFile = getOutputPathFile();
if (sourceFileList == null || outputFile == null) {
return false;
}
File commonRoot = determineCommonRoot(outputFile, sourceFileList);
// We don't want to use root ("/") as a workspace folder, didn't we?
if (commonRoot == null || commonRoot.getParent() == null || commonRoot.getParentFile().getParent() == null) {
log.error("All source folders and the output folder should have "
+ "a common parent non-top level folder (like project folder)");
for (File sourceFile : sourceFileList) {
log.error("(Source folder: '" + sourceFile + "')");
}
log.error("(Output folder: '" + outputFile + "')");
return false;
}
projectConfig = new FileProjectConfig(commonRoot, commonRoot.getName());
java.net.URI commonURI = commonRoot.toURI();
java.net.URI relativizedTarget = commonURI.relativize(outputFile.toURI());
if (relativizedTarget.isAbsolute()) {
log.error("Target folder '" + outputFile + "' must be a child of the project folder '" + commonRoot + "'");
return false;
}
CharMatcher slash = CharMatcher.is('/');
String relativeTargetFolder = slash.trimTrailingFrom(relativizedTarget.getPath());
outputConfiguration = Iterables.getOnlyElement(outputConfigurationProvider.getOutputConfigurations());
outputConfiguration.setOutputDirectory(relativeTargetFolder);
for (File source : sourceFileList) {
java.net.URI relativizedSrc = commonURI.relativize(source.toURI());
if (relativizedSrc.isAbsolute()) {
log.error("Source folder '" + source + "' must be a child of the project folder '" + commonRoot + "'");
return false;
}
projectConfig.addSourceFolder(slash.trimTrailingFrom(relativizedSrc.getPath()));
}
Map<String, Set<OutputConfiguration>> outputConfigurations = newHashMap();
outputConfigurations.put(languageName, newHashSet(outputConfiguration));
ProjectConfigAdapter.install(resourceSet, projectConfig);
resourceSet.eAdapters().add(new OutputConfigurationAdapter(outputConfigurations));
return true;
}