use of com.google.common.base.Splitter in project guava by hceylan.
the class FilesSimplifyPathTest method doExtensiveTest.
private void doExtensiveTest(String resourceName) throws IOException {
Splitter splitter = Splitter.on(CharMatcher.WHITESPACE);
URL url = getClass().getResource(resourceName);
for (String line : Resources.readLines(url, UTF_8)) {
Iterator<String> iterator = splitter.split(line).iterator();
String input = iterator.next();
String expectedOutput = iterator.next();
assertFalse(iterator.hasNext());
assertEquals(expectedOutput, simplifyPath(input));
}
}
use of com.google.common.base.Splitter in project platformlayer by platformlayer.
the class IpsecPresharedKey method handler.
@Handler
public void handler(OpsTarget target) throws OpsException {
if (OpsContext.isConfigure()) {
File pskFile = new File("/etc/racoon/psk.txt");
String psk = target.readTextFile(pskFile);
if (psk == null) {
psk = "# Managed by PlatformLayer\n";
}
boolean found = false;
// TODO: Extend MapSplitter / add some helper functions??
Splitter keyValueSpliter = Splitter.on(CharMatcher.WHITESPACE).limit(2).omitEmptyStrings().trimResults();
Map<String, String> psks = Maps.newHashMap();
for (String line : Splitter.on("\n").trimResults().omitEmptyStrings().split(psk)) {
if (line.startsWith("#")) {
continue;
}
List<String> tokens = Lists.newArrayList(keyValueSpliter.split(line));
if (tokens.size() != 2) {
throw new OpsException("Cannot parse PSK line: " + line);
}
String key = tokens.get(0);
String value = tokens.get(1);
if (psks.containsKey(key)) {
// (We could check to see if they're the same, but this is generally not good)
throw new OpsException("Found duplicate PSK");
}
psks.put(key, value);
if (!key.equals(id)) {
continue;
}
if (value.equals(secret.plaintext())) {
found = true;
}
}
if (!found) {
psk = psk + "\n";
psk += id + " " + secret.plaintext() + "\n";
FileUpload.upload(target, pskFile, psk);
target.executeCommand(Command.build("racoonctl reload-config"));
}
}
}
use of com.google.common.base.Splitter in project gerrit by GerritCodeReview.
the class ChangeField method getFileParts.
public static Set<String> getFileParts(ChangeData cd) {
List<String> paths = cd.currentFilePaths();
Splitter s = Splitter.on('/').omitEmptyStrings();
Set<String> r = new HashSet<>();
for (String path : paths) {
for (String part : s.split(path)) {
r.add(part);
}
}
return r;
}
use of com.google.common.base.Splitter in project xtext-core by eclipse.
the class PreferenceTaskTagProvider method parseTags.
public static List<TaskTag> parseTags(String names, String priorities) {
Splitter splitter = Splitter.on(",").omitEmptyStrings().trimResults();
List<String> tags = toList(splitter.split(names));
List<String> prios = toList(splitter.split(priorities));
List<TaskTag> elements = new ArrayList<>();
for (int i = 0; i < tags.size(); i++) {
TaskTag taskTag = new TaskTag();
taskTag.setName(tags.get(i));
Priority priority = Priority.NORMAL;
if (prios.size() >= i) {
try {
priority = Priority.valueOf(prios.get(i));
} catch (IllegalArgumentException ignore) {
}
}
taskTag.setPriority(priority);
elements.add(taskTag);
}
return elements;
}
use of com.google.common.base.Splitter in project cuba by cuba-platform.
the class AppComponents method load.
private void load(AppComponent component) {
Document doc = getDescriptorDoc(component);
String dependsOnAttr = doc.getRootElement().attributeValue("dependsOn");
if (!StringUtils.isEmpty(dependsOnAttr)) {
for (String depCompId : splitCommaSeparatedValue(dependsOnAttr)) {
AppComponent depComp = get(depCompId);
if (depComp == null) {
depComp = new AppComponent(depCompId);
load(depComp);
components.add(depComp);
}
component.addDependency(depComp);
}
}
for (Element moduleEl : doc.getRootElement().elements("module")) {
String blocksAttr = moduleEl.attributeValue("blocks");
if (StringUtils.isEmpty(blocksAttr)) {
continue;
}
List<String> blocks = splitCommaSeparatedValue(blocksAttr);
if (blocks.contains("*") || blocks.contains(block)) {
for (Element propertyEl : moduleEl.elements("property")) {
String name = propertyEl.attributeValue("name");
String value = propertyEl.attributeValue("value");
String existingValue = component.getProperty(name);
if (value.startsWith("\\+")) {
if (existingValue != null) {
log.debug("Overwrite value of property {} from {} to {}", name, existingValue, value);
}
component.setProperty(name, value.substring(1), false);
continue;
}
if (!value.startsWith("+")) {
if (existingValue != null) {
log.debug("Overwrite value of property {} from {} to {}", name, existingValue, value);
}
component.setProperty(name, value, false);
continue;
}
String cleanValue = value.substring(1);
if (existingValue != null) {
StringBuilder newValue = new StringBuilder(existingValue);
Splitter splitter = Splitter.on(AppProperties.SEPARATOR_PATTERN).omitEmptyStrings();
List<String> existingParts = splitter.splitToList(existingValue);
for (String part : splitter.split(cleanValue)) {
if (!existingParts.contains(part)) {
newValue.append(" ").append(part);
}
}
component.setProperty(name, newValue.toString(), true);
} else {
component.setProperty(name, cleanValue, true);
}
}
}
}
}
Aggregations