Example usage for com.fasterxml.jackson.databind JsonNode size

List of usage examples for com.fasterxml.jackson.databind JsonNode size

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode size.

Prototype

public int size() 

Source Link

Usage

From source file:com.github.fge.jackson.JsonNumEquals.java

@Override
protected int doHash(final JsonNode t) {
    /*/*from www . ja v a 2 s.  co  m*/
     * If this is a numeric node, we want the same hashcode for the same
     * mathematical values. Go with double, its range is good enough for
     * 99+% of use cases.
     */
    if (t.isNumber())
        return Double.valueOf(t.doubleValue()).hashCode();

    /*
     * If this is a primitive type (other than numbers, handled above),
     * delegate to JsonNode.
     */
    if (!t.isContainerNode())
        return t.hashCode();

    /*
     * The following hash calculations work, yes, but they are poor at best.
     * And probably slow, too.
     *
     * TODO: try and figure out those hash classes from Guava
     */
    int ret = 0;

    /*
     * If the container is empty, just return
     */
    if (t.size() == 0)
        return ret;

    /*
     * Array
     */
    if (t.isArray()) {
        for (final JsonNode element : t)
            ret = 31 * ret + doHash(element);
        return ret;
    }

    /*
     * Not an array? An object.
     */
    final Iterator<Map.Entry<String, JsonNode>> iterator = t.fields();

    Map.Entry<String, JsonNode> entry;

    while (iterator.hasNext()) {
        entry = iterator.next();
        ret = 31 * ret + (entry.getKey().hashCode() ^ doHash(entry.getValue()));
    }

    return ret;
}

From source file:tests.SearchTests.java

public void returnFieldHitParam(final String query, final int hits) {
    running(TEST_SERVER, new Runnable() {
        @Override//w w  w .ja va2s. c  om
        public void run() {
            final String response = call(query + "format=short.fulltextOnline");
            assertThat(response).isNotNull();
            final JsonNode jsonObject = Json.parse(response);
            assertThat(jsonObject.isArray()).isTrue();
            assertThat(jsonObject.size()).isEqualTo(hits + META);
        }
    });
}

From source file:tests.SearchTests.java

public void findItem(final String call) {
    running(TEST_SERVER, new Runnable() {
        @Override/*from w w  w.  j  a  va 2 s.  c o  m*/
        public void run() {
            final JsonNode jsonObject = Json.parse(call(call));
            assertThat(jsonObject.isArray()).isTrue();
            assertThat(jsonObject.size()).isEqualTo(1 + META);
        }
    });
}

From source file:tests.SearchTests.java

public void returnFieldHitPath(final String query, final int hits) {
    running(TEST_SERVER, new Runnable() {
        @Override/*  ww w . j  a  va2 s.  c  om*/
        public void run() {
            final String response = call(query + "format=short.fulltextOnline");
            assertThat(response).isNotNull();
            final JsonNode jsonObject = Json.parse(response);
            assertThat(jsonObject.isArray()).isTrue();
            assertThat(jsonObject.size()).isEqualTo(hits);
            if (hits > 0)
                assertThat(jsonObject.get(0).asText()).isEqualTo("http://dx.doi.org/10.1007/978-1-4020-8389-1");
        }
    });
}

From source file:tests.SearchTests.java

public void gndPerson(final String gndId, final int results) {
    running(TEST_SERVER, new Runnable() {
        @Override//from  w  w w.j  a  v  a2s . c  om
        public void run() {
            final JsonNode jsonObject = Json.parse(call("person?id=" + gndId));
            assertThat(jsonObject.isArray()).isTrue();
            assertThat(jsonObject.size()).isEqualTo(results + META);
            final String gndPrefix = "http://d-nb.info/gnd/";
            assertThat(jsonObject.get(0 + META).toString()).contains(gndPrefix + gndId.replace(gndPrefix, ""));
        }
    });
}

From source file:tests.SearchTests.java

public void gndSubjectId(final String gndId, final int results) {
    running(TEST_SERVER, new Runnable() {
        @Override/*from  ww w  .  j av  a 2  s . c o  m*/
        public void run() {
            final JsonNode jsonObject = Json.parse(call("subject?id=" + gndId));
            assertThat(jsonObject.isArray()).isTrue();
            assertThat(jsonObject.size()).isEqualTo(results + META);
            final String gndPrefix = "http://d-nb.info/gnd/";
            assertThat(jsonObject.get(0 + META).toString()).contains(gndPrefix + gndId.replace(gndPrefix, ""));
        }
    });
}

From source file:tests.SearchTests.java

@Test
public void searchViaApiResourcesAuthorId() {
    running(TEST_SERVER, new Runnable() {
        @Override//  w  w w .  ja v a 2s. co m
        public void run() {
            String gndId = "118554808";
            final JsonNode jsonObject = Json.parse(call("resource?author=" + gndId));
            assertThat(jsonObject.isArray()).isTrue();
            assertThat(jsonObject.size()).isEqualTo(1 + META);
            assertThat(jsonObject.get(0 + META).toString()).contains("http://d-nb.info/gnd/" + gndId);
        }
    });
}

From source file:tests.SearchTests.java

public void resByGndSubject(final String gndId, final int results) {
    running(TEST_SERVER, new Runnable() {
        @Override//from  w ww . ja v  a 2 s  . c o  m
        public void run() {
            final JsonNode jsonObject = Json.parse(call("resource?subject=" + gndId));
            assertThat(jsonObject.isArray()).isTrue();
            assertThat(jsonObject.size()).isEqualTo(results + META);
            String prefix = "http://d-nb.info/gnd/";
            assertThat(jsonObject.get(0 + META).toString()).contains(prefix + gndId.replace(prefix, ""));
        }
    });
}

From source file:tests.SearchTests.java

public void gndSubject(final String subjectName, final int results) {
    running(TEST_SERVER, new Runnable() {
        @Override/*from  ww  w  .j  a v a 2  s . c  o m*/
        public void run() {
            final JsonNode jsonObject = Json.parse(call("subject?name=" + subjectName));
            assertThat(jsonObject.isArray()).isTrue();
            assertThat(jsonObject.size()).isEqualTo(results + META);
            assertThat(jsonObject.get(0 + META).toString()).contains(subjectName);
        }
    });
}