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

sdmxdl.Query Maven / Gradle / Ivy

The newest version!
package sdmxdl;

import lombok.NonNull;

import java.util.stream.Stream;

@lombok.Value
@lombok.Builder(toBuilder = true)
public class Query {

    public static final Query ALL = Query.builder().build();

    @lombok.NonNull
    @lombok.Builder.Default
    Key key = Key.ALL;

    @lombok.NonNull
    @lombok.Builder.Default
    Detail detail = Detail.FULL;

    public @NonNull Stream execute(@NonNull Stream data) {
        return data
                .filter(key::containsKey)
                .map(this::map);
    }

    private Series map(Series series) {
        if (detail.isIgnoreData()) {
            if (detail.isIgnoreMeta()) {
                return series.toBuilder().clearObs().clearMeta().build();
            } else {
                return series.toBuilder().clearObs().build();
            }
        } else {
            if (detail.isIgnoreMeta()) {
                return series.toBuilder().clearMeta().build();
            } else {
                return series;
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy