Java tutorial
/* * Copyright (C) 2013 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.input; import java.util.Arrays; import com.github.autermann.wps.commons.description.BoundingBoxDescription; import com.github.autermann.wps.commons.description.ows.OwsCRS; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; /** * TODO JavaDoc * * @author Christian Autermann */ public class BoundingBoxInputDescription extends ProcessInputDescription implements BoundingBoxDescription { private final ImmutableSet<OwsCRS> supportedCRS; private final Optional<OwsCRS> defaultCRS; protected BoundingBoxInputDescription(Builder<?, ?> builder) { super(builder); this.supportedCRS = builder.getSupportedCRS().build(); this.defaultCRS = Optional.fromNullable(builder.getDefaultCRS()); } @Override public ImmutableSet<OwsCRS> getSupportedCRS() { return this.supportedCRS; } @Override public Optional<OwsCRS> getDefaultCRS() { return this.defaultCRS; } @Override public boolean isBoundingBox() { return true; } @Override public BoundingBoxInputDescription asBoundingBox() { return this; } @Override public <T> T visit(ReturningVisitor<T> visitor) { return visitor.visit(this); } public static Builder<?, ?> builder() { return new BuilderImpl(); } private static class BuilderImpl extends Builder<BoundingBoxInputDescription, BuilderImpl> { @Override public BoundingBoxInputDescription build() { return new BoundingBoxInputDescription(this); } } public static abstract class Builder<T extends BoundingBoxInputDescription, B extends Builder<T, B>> extends ProcessInputDescription.Builder<T, B> { private OwsCRS defaultCRS; private final ImmutableSet.Builder<OwsCRS> supportedCRS = ImmutableSet.builder(); @SuppressWarnings("unchecked") public B withDefaultCRS(OwsCRS defaultCRS) { this.defaultCRS = defaultCRS; return (B) this; } public B withDefaultCRS(String defaultCRS) { return withDefaultCRS(defaultCRS == null ? null : new OwsCRS(defaultCRS)); } @SuppressWarnings("unchecked") public B withSupportedCRS(Iterable<OwsCRS> crss) { for (OwsCRS crs : crss) { withSupportedCRS(crs); } return (B) this; } public B withSupportedCRS(OwsCRS... crss) { return withSupportedCRS(Arrays.asList(crss)); } @SuppressWarnings("unchecked") public B withSupportedCRS(OwsCRS uom) { if (uom != null) { this.supportedCRS.add(uom); } return (B) this; } public B withSupportedCRS(String uom) { return withSupportedCRS(uom == null ? null : new OwsCRS(uom)); } private OwsCRS getDefaultCRS() { return defaultCRS; } private ImmutableSet.Builder<OwsCRS> getSupportedCRS() { return supportedCRS; } } }