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

org.n52.javaps.io.AbstractInputOutputHandlerRepository Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2016-2023 52°North Spatial Information Research GmbH
 *
 * 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 org.n52.javaps.io;

import static java.util.stream.Collectors.toSet;

import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

import javax.inject.Provider;

import org.n52.shetland.ogc.wps.Format;

/**
 * TODO JavaDoc
 *
 * @author Christian Autermann
 * @param 
 *            the input output handler type
 */
public abstract class AbstractInputOutputHandlerRepository implements FormatRepository {

    @Override
    public Set getSupportedFormats() {
        return stream().map(T::getSupportedFormats).flatMap(Set::stream).collect(toSet());
    }

    @Override
    public Set getSupportedFormats(Class> binding) {
        return stream().filter(g -> g.isSupportedBinding(binding)).map(InputOutputHandler::getSupportedFormats).flatMap(
                Set::stream).collect(toSet());
    }

    protected Optional getHandler(Class> binding,
            Format format) {
        // TODO: try a chaining approach, by calculation all permutations and
        // look for matches.
        return stream().filter(g -> g.isSupportedBinding(binding)).filter(g -> g.isSupportedFormat(format)).findFirst();
    }

    protected Set getHandlers() {
        return Collections.unmodifiableSet(stream().collect(toSet()));
    }

    protected abstract Set> getHandlerProviders();

    protected Stream stream() {
        return getHandlerProviders().stream().map(Provider::get);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy