use of com.google.common.base.Joiner in project jackrabbit-oak by apache.
the class MarkSweepGarbageCollector method iterateNodeTree.
/**
* Iterates the complete node tree and collect all blob references
* @param fs the garbage collector file state
* @param logPath whether to log path in the file or not
*/
protected void iterateNodeTree(GarbageCollectorFileState fs, final boolean logPath) throws IOException {
final BufferedWriter writer = Files.newWriter(fs.getMarkedRefs(), Charsets.UTF_8);
final AtomicInteger count = new AtomicInteger();
try {
marker.collectReferences(new ReferenceCollector() {
private final boolean debugMode = LOG.isTraceEnabled();
@Override
public void addReference(String blobId, final String nodeId) {
if (debugMode) {
LOG.trace("BlobId : {}, NodeId : {}", blobId, nodeId);
}
try {
Iterator<String> idIter = blobStore.resolveChunks(blobId);
final Joiner delimJoiner = Joiner.on(DELIM).skipNulls();
Iterator<List<String>> partitions = Iterators.partition(idIter, getBatchCount());
while (partitions.hasNext()) {
List<String> idBatch = Lists.transform(partitions.next(), new Function<String, String>() {
@Nullable
@Override
public String apply(@Nullable String id) {
if (logPath) {
return delimJoiner.join(id, nodeId);
}
return id;
}
});
if (debugMode) {
LOG.trace("chunkIds : {}", idBatch);
}
count.getAndAdd(idBatch.size());
saveBatchToFile(idBatch, writer);
}
if (count.get() % getBatchCount() == 0) {
LOG.info("Collected ({}) blob references", count.get());
}
} catch (Exception e) {
throw new RuntimeException("Error in retrieving references", e);
}
}
});
LOG.info("Number of valid blob references marked under mark phase of " + "Blob garbage collection [{}]", count.get());
// sort the marked references with the first part of the key
sort(fs.getMarkedRefs(), new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return s1.split(DELIM)[0].compareTo(s2.split(DELIM)[0]);
}
});
} finally {
closeQuietly(writer);
}
}
use of com.google.common.base.Joiner in project jackrabbit-oak by apache.
the class AbstractTest method statsFormatsJoined.
private String statsFormatsJoined(boolean commaSeparated) {
String comment = comment();
String[] formatPattern = statsFormats();
if (comment != null) {
String commentPattern = commaSeparated ? "#%s" : " #%s";
formatPattern = (String[]) ArrayUtils.add(formatPattern, commentPattern);
}
Joiner joiner = commaSeparated ? Joiner.on(',') : Joiner.on(" ");
return joiner.join(formatPattern);
}
use of com.google.common.base.Joiner in project jackrabbit-oak by apache.
the class AbstractTest method statsNamesJoined.
private String statsNamesJoined(boolean commaSeparated) {
Joiner joiner = commaSeparated ? Joiner.on(',') : Joiner.on(" ");
String names = joiner.join(statsNames());
if (!commaSeparated) {
names = " " + names;
}
return names;
}
use of com.google.common.base.Joiner in project jslint4java by happygiraffe.
the class MainTest method assertLintOutput.
/**
* Check that the exit value, stdout and stderr are as expected.
*/
private void assertLintOutput(int actualExit, int expectedExit, List<String> expectedStdout, List<String> expectedStderr) {
Joiner nl = Joiner.on(NEWLINE);
assertThat(stdio.getStdout(), is(nl.join(maybeAddTrailer(expectedStdout))));
assertThat(stdio.getStderr(), is(nl.join(maybeAddTrailer(expectedStderr))));
// Do this last so that we see stdout/stderr errors first.
assertThat(actualExit, is(expectedExit));
}
use of com.google.common.base.Joiner in project LearningGuava by JavaMilk.
the class TestSplitter method testSplitter.
@Test
public void testSplitter() {
Joiner joiner = Joiner.on(",");
Iterable<String> result;
// 按字符划分 Splitter.on(char)
result = Splitter.on(',').split("foo,bar,qux");
Assert.assertEquals(joiner.join(result), "foo,bar,qux");
// 按字 CharMatcher 划分 Splitter.on(CharMatcher)
result = Splitter.on(CharMatcher.anyOf(";,.")).split("foo;bar,qux");
Assert.assertEquals(joiner.join(result), "foo,bar,qux");
// 按字符串划分 Splitter.on(String)
result = Splitter.on(",").split("foo,bar,qux");
Assert.assertEquals(joiner.join(result), "foo,bar,qux");
// 按正则表达式划分 Splitter.onPattern(String) or Splitter.on(Pattern)
result = Splitter.onPattern("\\s+").split("foo bar qux");
Assert.assertEquals(joiner.join(result), "foo,bar,qux");
// 按固定长度划分 Splitter.fixedLength(int)
result = Splitter.fixedLength(3).split("foobarqux");
Assert.assertEquals(joiner.join(result), "foo,bar,qux");
// 去除结果中的空字符串
result = Splitter.on(",").omitEmptyStrings().split("foo,,,bar,qux");
Assert.assertEquals(joiner.join(result), "foo,bar,qux");
// 结果前后去除空格
result = Splitter.on(",").trimResults().split("foo ,bar,qux");
Assert.assertEquals(joiner.join(result), "foo,bar,qux");
// 只是去除前后的,内部不去除
result = Splitter.on(",").trimResults().split("foo ,b a r,qux");
Assert.assertEquals(joiner.join(result), "foo,b a r,qux");
// 结果前后去除 "_"
result = Splitter.on(',').trimResults(CharMatcher.is('_')).split("_a ,_b_ ,c__");
Assert.assertEquals(joiner.join(result), "a ,b_ ,c");
// 达到指定个数后不再划分
result = Splitter.on("_").limit(2).split("foo_bar_qux");
Assert.assertEquals(joiner.join(result), "foo,bar_qux");
}
Aggregations