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

uk.gov.gchq.gaffer.data.element.function.TuplesToElements Maven / Gradle / Ivy

/*
 * Copyright 2019-2021 Crown Copyright
 *
 * 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 uk.gov.gchq.gaffer.data.element.function;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import uk.gov.gchq.gaffer.commonutil.iterable.TransformOneToManyIterable;
import uk.gov.gchq.gaffer.data.element.Element;
import uk.gov.gchq.koryphe.Since;
import uk.gov.gchq.koryphe.Summary;
import uk.gov.gchq.koryphe.function.KorypheFunction;
import uk.gov.gchq.koryphe.tuple.Tuple;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * A {@code TuplesToElements} is a Function which generates Elements from
 * an Iterable of Tuples.
 */
@Since("1.21.0")
@Summary("Generates elements from tuples")
@JsonPropertyOrder(alphabetic = true)
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class TuplesToElements extends KorypheFunction>, Iterable> implements Serializable {
    private static final long serialVersionUID = 8954092895764615233L;
    private final List elements = new ArrayList<>();

    @Override
    public Iterable apply(final Iterable> tuples) {
        final TupleToElements tupleToElements = new TupleToElements().elements(elements);
        return new TransformOneToManyIterable, Element>(tuples) {
            @Override
            protected Iterable transform(final Tuple tuple) {
                return tupleToElements.apply(tuple);
            }
        };
    }

    public List getElements() {
        return elements;
    }

    public void setElements(final List elements) {
        this.elements.clear();
        this.elements.addAll(elements);
    }

    public TuplesToElements element(final ElementTupleDefinition elementDef) {
        elements.add(elementDef);
        return this;
    }

    public TuplesToElements elements(final List elementDef) {
        elements.addAll(elementDef);
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy