All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arangodb.internal.cursor.AbstractArangoIterable Maven / Gradle / Ivy

There is a newer version: 7.15.0
Show newest version
/*
 * DISCLAIMER
 *
 * Copyright 2018 ArangoDB GmbH, Cologne, Germany
 *
 * 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.
 *
 * Copyright holder is ArangoDB GmbH, Cologne, Germany
 */

package com.arangodb.internal.cursor;

import com.arangodb.ArangoIterable;
import com.arangodb.ArangoIterator;
import com.arangodb.Function;
import com.arangodb.Predicate;

import java.util.Collection;
import java.util.Iterator;

/**
 * @author Mark Vollmary
 */
public abstract class AbstractArangoIterable implements ArangoIterable {

    @Override
    public  ArangoIterable map(final Function mapper) {
        return new ArangoMappingIterable<>(this, mapper);
    }

    @Override
    public ArangoIterable filter(final Predicate predicate) {
        return new ArangoFilterIterable<>(this, predicate);
    }

    @Override
    public T first() {
        final ArangoIterator iterator = iterator();
        return iterator.hasNext() ? iterator.next() : null;
    }

    @Override
    public long count() {
        long count = 0L;
        for (final Iterator iterator = iterator(); iterator.hasNext(); iterator.next()) {
            count++;
        }
        return count;
    }

    @Override
    public boolean anyMatch(final Predicate predicate) {
        boolean match = false;
        for (final T t : this) {
            if (predicate.test(t)) {
                match = true;
                break;
            }
        }
        return match;
    }

    @Override
    public boolean allMatch(final Predicate predicate) {
        boolean match = false;
        for (final T t : this) {
            match = predicate.test(t);
            if (!match) {
                break;
            }
        }
        return match;
    }

    @Override
    public boolean noneMatch(final Predicate predicate) {
        boolean match = false;
        for (final T t : this) {
            match = !predicate.test(t);
            if (!match) {
                break;
            }
        }
        return match;
    }

    @Override
    public > R collectInto(final R target) {
        for (final T t : this) {
            target.add(t);
        }
        return target;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy