Example usage for com.google.common.collect Iterators toString

List of usage examples for com.google.common.collect Iterators toString

Introduction

In this page you can find the example usage for com.google.common.collect Iterators toString.

Prototype

public static String toString(Iterator<?> iterator) 

Source Link

Document

Returns a string representation of iterator , with the format [e1, e2, ..., en] .

Usage

From source file:com.linkedin.pinot.common.utils.JsonAssert.java

/**
 * Compare two JSON objects, ignoring field order. For example, objects {a:1, b:2} and {b:2, a:1} are equals, even
 * though they are not using string comparison.
 *
 * @param actual The actual JSON object/*from   ww w. ja v  a 2  s.com*/
 * @param expected The expected JSON object
 */
public static void assertEqualsIgnoreOrder(String actual, String expected) {
    try {
        JSONObject actualObject = new JSONObject(actual);
        JSONObject expectedObject = new JSONObject(expected);

        // Check that both objects have the same keys
        Assert.assertTrue(Iterators.elementsEqual(actualObject.sortedKeys(), expectedObject.sortedKeys()),
                "JSON objects don't have the same keys, expected:<"
                        + Iterators.toString(expectedObject.sortedKeys()) + "> but was:<"
                        + Iterators.toString(actualObject.sortedKeys()) + ">");

        // Iterate over all the keys of one element and compare their contents
        Iterator<String> objectKeys = actualObject.keys();
        while (objectKeys.hasNext()) {
            String key = objectKeys.next();
            Object actualValue = actualObject.get(key);
            Object expectedValue = expectedObject.get(key);

            Assert.assertTrue(actualValue.getClass().equals(expectedValue.getClass()),
                    "Objects with key " + key + " don't have the same class, expected:<" + expectedValue
                            + "> but was:<" + actualValue + ">");
            if (actualValue instanceof JSONObject) {
                assertEqualsIgnoreOrder(actualValue.toString(), expectedValue.toString());
            } else {
                Assert.assertEquals(actualValue.toString(), expectedValue.toString(),
                        "Objects with key " + key + " don't have the same value");
            }
        }
    } catch (JSONException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.ambraproject.wombat.util.HttpDebug.java

private static String enumerationToString(Enumeration enumeration) {
    if (enumeration == null) {
        return null;
    }/*from ww w.  jav  a 2  s.com*/
    return Iterators.toString(Iterators.forEnumeration(enumeration));
}

From source file:org.apache.arrow.vector.VectorLoader.java

/**
 * Loads the record batch in the vectors
 * will not close the record batch//from  ww  w  . j  a v a  2  s .  c om
 * @param recordBatch
 */
public void load(ArrowRecordBatch recordBatch) {
    Iterator<ArrowBuf> buffers = recordBatch.getBuffers().iterator();
    Iterator<ArrowFieldNode> nodes = recordBatch.getNodes().iterator();
    List<Field> fields = root.getSchema().getFields();
    for (int i = 0; i < fields.size(); ++i) {
        Field field = fields.get(i);
        FieldVector fieldVector = root.getVector(field.getName());
        loadBuffers(fieldVector, field, buffers, nodes);
    }
    root.setRowCount(recordBatch.getLength());
    if (nodes.hasNext() || buffers.hasNext()) {
        throw new IllegalArgumentException("not all nodes and buffers where consumed. nodes: "
                + Iterators.toString(nodes) + " buffers: " + Iterators.toString(buffers));
    }
}

From source file:org.apache.fluo.core.log.TracingTransaction.java

private String encB(Collection<Bytes> columns) {
    return Iterators.toString(Iterators.transform(columns.iterator(), new Function<Bytes, String>() {
        @Override/* ww w  .  j  a  v  a2s.  c  o  m*/
        public String apply(Bytes b) {
            return Hex.encNonAscii(b);
        }
    }));
}

From source file:org.apache.fluo.core.log.TracingTransaction.java

private String encRC(Collection<RowColumn> ret) {
    return Iterators.toString(Iterators.transform(ret.iterator(), new Function<RowColumn, String>() {
        @Override/*from  ww w  .  j ava  2 s  . com*/
        public String apply(RowColumn rc) {
            return Hex.encNonAscii(rc);
        }
    }));
}

From source file:com.github.rinde.datgen.pdptw.Dataset.java

@Override
public String toString() {
    return Iterators.toString(iterator());
}

From source file:org.apache.fluo.core.log.TracingTransaction.java

private String encRC(Map<Bytes, Map<Column, Bytes>> ret) {
    return Iterators.toString(Iterators.transform(ret.entrySet().iterator(),
            new Function<Entry<Bytes, Map<Column, Bytes>>, String>() {
                @Override/*from   w ww. j  a v  a  2 s  .  c om*/
                public String apply(Entry<Bytes, Map<Column, Bytes>> e) {
                    return enc(e.getKey()) + "=" + encC(e.getValue());
                }
            }));
}

From source file:com.geniusgithub.contact.contact.model.account.dataitem.DataKind.java

public static String toString(Iterable<?> list) {
    if (list == null) {
        return "(null)";
    } else {//w w w.  ja v a2 s  . c o  m
        return Iterators.toString(list.iterator());
    }
}

From source file:org.apache.fluo.core.log.TracingTransaction.java

private String encC(Collection<Column> columns) {
    return Iterators.toString(Iterators.transform(columns.iterator(), new Function<Column, String>() {
        @Override//from ww  w  .  ja  va  2  s . c  o m
        public String apply(Column col) {
            return Hex.encNonAscii(col);
        }
    }));
}

From source file:org.apache.fluo.core.log.TracingTransaction.java

private String encC(Map<Column, Bytes> ret) {
    return Iterators.toString(
            Iterators.transform(ret.entrySet().iterator(), new Function<Entry<Column, Bytes>, String>() {
                @Override//from  w  w w. j  a v a2  s.co  m
                public String apply(Entry<Column, Bytes> e) {
                    return enc(e.getKey()) + "=" + enc(e.getValue());
                }
            }));
}