<commit_before>/*
 * Copyright 2011 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.hamnaberg.json;

import com.google.common.collect.ImmutableList;

import java.net.URI;

public class DefaultJsonCollection extends AbstractJsonCollection {
    private final ImmutableList<Link> links;
    private final ImmutableList<Item> items;
    private final ImmutableList<Query> queries;
    private final Template template;

    public DefaultJsonCollection(URI href) {
        this(href, Version.ONE);
    }

    public DefaultJsonCollection(URI href, Version version) {
        this(href, version, ImmutableList.<Link>of(), ImmutableList.<Item>of(), ImmutableList.<Query>of(), null);
    }

    public DefaultJsonCollection(URI href, Version version, ImmutableList<Link> links, ImmutableList<Item> items, ImmutableList<Query> queries, Template template) {
        super(href, version);
        this.links = links;
        this.items = items;
        this.queries = queries;
        this.template = template;
    }

    @Override
    public ImmutableList<Link> getLinks() {
        return links;
    }

    @Override
    public ImmutableList<Item> getItems() {
        return items;
    }

    @Override
    public ImmutableList<Query> getQueries() {
        return queries;
    }

    public Item getFirst() {
        if (items.isEmpty()) {
            return null;
        }
        return items.get(0);
    }<commit_msg>- Add some methods for searching<commit_after>/*
 * Copyright 2011 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.hamnaberg.json;

import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import java.net.URI;
import java.util.Collection;

public class DefaultJsonCollection extends AbstractJsonCollection {
    private final ImmutableList<Link> links;
    private final ImmutableList<Item> items;
    private final ImmutableList<Query> queries;
    private final Template template;

    public DefaultJsonCollection(URI href) {
        this(href, Version.ONE);
    }

    public DefaultJsonCollection(URI href, Version version) {
        this(href, version, ImmutableList.<Link>of(), ImmutableList.<Item>of(), ImmutableList.<Query>of(), null);
    }

    public DefaultJsonCollection(URI href, Version version, ImmutableList<Link> links, ImmutableList<Item> items, ImmutableList<Query> queries, Template template) {
        super(href, version);
        this.links = links;
        this.items = items;
        this.queries = queries;
        this.template = template;
    }

    @Override
    public ImmutableList<Link> getLinks() {
        return links;
    }

    @Override
    public ImmutableList<Item> getItems() {
        return items;
    }

    @Override
    public ImmutableList<Query> getQueries() {
        return queries;
    }

    public Link findLink(Predicate<Link> predicate) {
        return find(links, predicate);
    }

    public Collection<Link> findLinks(Predicate<Link> predicate) {
        return Collections2.filter(links, predicate);
    }

    public Item findItem(Predicate<Item> predicate) {
        return find(items, predicate);
    }

    public Collection<Item> findItems(Predicate<Item> predicate) {
        return Collections2.filter(items, predicate);
    }

    public Query findQuery(Predicate<Query> predicate) {
        return find(queries, predicate);
    }

    public Collection<Query> findQueries(Predicate<Query> predicate) {
        return Collections2.filter(queries, predicate);
    }

    private <T> T find(Collection<T> collection, Predicate<T> predicate) {
        Collection<T> filter = Collections2.filter(collection, predicate);
        if (filter.isEmpty()) {
            return null;
        }
        return filter.iterator().next();
    }

    public Item getFirst() {
        if (items.isEmpty()) {
            return null;
        }
        return items.get(0);
    }
{'fraction_non_alphanumeric': 0.09419713831478538, 'fraction_numerical': 0.0045707472178060414, 'mean_word_length': 3.1767634854771782, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2889993', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1327, 'n_words': 422}