Search in sources :

Example 41 with Joiner

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);
    }
}
Also used : Joiner(com.google.common.base.Joiner) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) BufferedWriter(java.io.BufferedWriter) Function(com.google.common.base.Function) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LineIterator(org.apache.commons.io.LineIterator) FileLineDifferenceIterator(org.apache.jackrabbit.oak.commons.FileIOUtils.FileLineDifferenceIterator) Iterator(java.util.Iterator) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Nullable(javax.annotation.Nullable)

Example 42 with Joiner

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);
}
Also used : Joiner(com.google.common.base.Joiner)

Example 43 with Joiner

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;
}
Also used : Joiner(com.google.common.base.Joiner)

Example 44 with Joiner

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));
}
Also used : Joiner(com.google.common.base.Joiner)

Example 45 with Joiner

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");
}
Also used : Joiner(com.google.common.base.Joiner) Test(org.junit.Test)

Aggregations

Joiner (com.google.common.base.Joiner)47 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)6 IOException (java.io.IOException)5 Map (java.util.Map)4 BufferedWriter (java.io.BufferedWriter)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 ResultSet (com.google.cloud.spanner.ResultSet)2 Statement (com.google.cloud.spanner.Statement)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 DBException (com.yahoo.ycsb.DBException)2 File (java.io.File)2 URI (java.net.URI)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)2 FileLineDifferenceIterator (org.apache.jackrabbit.oak.commons.FileIOUtils.FileLineDifferenceIterator)2 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1