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

sdmxdl.DataSet Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2020 National Bank of Belgium
 *
 * Licensed under the EUPL, Version 1.1 or - as soon they will be approved
 * by the European Commission - subsequent versions of the EUPL (the "Licence");
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at:
 *
 * http://ec.europa.eu/idabc/eupl
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the Licence is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and
 * limitations under the Licence.
 */
package sdmxdl;

import lombok.NonNull;

import java.util.Collection;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Stream;

import static java.util.Collections.unmodifiableList;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toList;

/**
 * @author Philippe Charles
 */
@lombok.Value
@lombok.Builder(toBuilder = true)
@lombok.EqualsAndHashCode(callSuper = false)
public class DataSet extends Resource {

    @lombok.NonNull
    FlowRef ref;

    @lombok.NonNull
    @lombok.Builder.Default
    Query query = Query.ALL;

    @lombok.NonNull
    @lombok.Singular("series")
    Collection data;

    public @NonNull DataSet getData(@NonNull Query query) {
        return query.equals(Query.ALL) ? this : query.execute(data.stream()).collect(toDataSet(ref, query));
    }

    public @NonNull Stream getDataStream(@NonNull Query query) {
        return query.equals(Query.ALL) ? data.stream() : query.execute(data.stream());
    }

    public static @NonNull Collector toDataSet(@NonNull FlowRef flowRef, @NonNull Query query) {
        return collectingAndThen(toList(), newDataSet(flowRef, query));
    }

    private static Function, DataSet> newDataSet(FlowRef flowRef, Query query) {
        return list -> new DataSet(flowRef, query, unmodifiableList(list));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy