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

com.github.autermann.wps.commons.description.impl.AbstractComplexInputDescriptionBuilder Maven / Gradle / Ivy

/*
 * Copyright (C) 2013-2015 Christian Autermann
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package com.github.autermann.wps.commons.description.impl;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Objects;
import java.util.Set;

import com.github.autermann.wps.commons.Format;
import com.github.autermann.wps.commons.description.ComplexInputDescription;
import com.github.autermann.wps.commons.description.ComplexInputDescriptionBuilder;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;

/**
 * TODO JavaDoc
 *
 * @author Christian Autermann
 */
public abstract class AbstractComplexInputDescriptionBuilder>
        extends AbstractProcessInputDescriptionBuilder implements
        ComplexInputDescriptionBuilder {

    private final ImmutableSet.Builder supportedFormats = ImmutableSet
            .builder();
    private Format defaultFormat;
    private BigInteger maximumMegabytes;

    @SuppressWarnings(value = "unchecked")
    @Override
    public B withMaximumMegabytes(BigInteger maximumMegabytes) {
        Preconditions.checkArgument(maximumMegabytes == null ||
                                    maximumMegabytes.compareTo(BigInteger.ZERO) >
                                    0);
        this.maximumMegabytes = maximumMegabytes;
        return (B) this;
    }

    @Override
    public B withMaximumMegabytes(long maximumMegabytes) {
        return withMaximumMegabytes(BigInteger.valueOf(maximumMegabytes));
    }

    @SuppressWarnings(value = "unchecked")
    @Override
    public B withDefaultFormat(Format format) {
        this.defaultFormat = Objects.requireNonNull(format);
        this.supportedFormats.add(format);
        return (B) this;
    }

    @SuppressWarnings(value = "unchecked")
    @Override
    public B withSupportedFormat(Format format) {
        if (format != null) {
            this.supportedFormats.add(format);
        }
        return (B) this;
    }

    @SuppressWarnings(value = "unchecked")
    @Override
    public B withSupportedFormat(Iterable formats) {
        if (formats != null) {
            for (Format format : formats) {
                withSupportedFormat(format);
            }
        }
        return (B) this;
    }

    @Override
    public B withSupportedFormat(Format... formats) {
        return withSupportedFormat(Arrays.asList(formats));
    }

    Set getSupportedFormats() {
        return supportedFormats.build();
    }

    Format getDefaultFormat() {
        return defaultFormat;
    }

    BigInteger getMaximumMegabytes() {
        return maximumMegabytes;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy