
de.otto.jsonhome.model.HintsBuilder Maven / Gradle / Ivy
/*
* Copyright 2012 Guido Steinacker
*
* 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 de.otto.jsonhome.model;
import java.util.*;
import static de.otto.jsonhome.model.Documentation.emptyDocs;
import static de.otto.jsonhome.model.Hints.hints;
import static java.util.Arrays.asList;
/**
* A builder used to build Hints instances.
*
* @author Guido Steinacker
* @since 30.09.12
*/
public class HintsBuilder {
private final Set allows = EnumSet.noneOf(Allow.class);
private final Set representations = new LinkedHashSet();
private final Set acceptPost = new LinkedHashSet();
private final Set acceptPut = new LinkedHashSet();
private final Set acceptPatch = new LinkedHashSet();
private final Set acceptRanges = new LinkedHashSet();
private final Set preferences = new LinkedHashSet();
private final List preconditionReq = new ArrayList();
private final List authReq = new ArrayList();
private Documentation docs = emptyDocs();
private Status status = Status.OK;
private HintsBuilder() {
}
public static HintsBuilder hintsBuilder() {
return new HintsBuilder();
}
public HintsBuilder allowing(final Allow... allows) {
this.allows.addAll(asList(allows));
return this;
}
public HintsBuilder allowing(final Set allows) {
this.allows.addAll(allows);
return this;
}
public HintsBuilder representedAs(final String... representations) {
this.representations.addAll(asList(representations));
return this;
}
public HintsBuilder representedAs(final List representations) {
this.representations.addAll(representations);
return this;
}
public HintsBuilder acceptingForPut(final String... representations) {
this.acceptPut.addAll(asList(representations));
return this;
}
public HintsBuilder acceptingForPut(final List representations) {
this.acceptPut.addAll(representations);
return this;
}
public HintsBuilder acceptingForPost(final String... representations) {
acceptPost.addAll(asList(representations));
return this;
}
public HintsBuilder acceptingForPost(final List representations) {
acceptPost.addAll(representations);
return this;
}
public HintsBuilder acceptingForPatch(final String... representations) {
acceptPatch.addAll(asList(representations));
return this;
}
public HintsBuilder acceptingForPatch(final List representations) {
acceptPatch.addAll(representations);
return this;
}
public HintsBuilder acceptingRanges(final String... ranges) {
this.acceptRanges.addAll(asList(ranges));
return this;
}
public HintsBuilder acceptingRanges(final List ranges) {
this.acceptRanges.addAll(ranges);
return this;
}
public HintsBuilder preferring(final String... preferences) {
this.preferences.addAll(asList(preferences));
return this;
}
public HintsBuilder preferring(final List preferences) {
this.preferences.addAll(preferences);
return this;
}
public HintsBuilder with(Documentation docs) {
this.docs = docs;
return this;
}
public HintsBuilder requiring(final Precondition... preconditions) {
this.preconditionReq.addAll(asList(preconditions));
return this;
}
public HintsBuilder requiring(final List preconditions) {
this.preconditionReq.addAll(preconditions);
return this;
}
public HintsBuilder withAuthRequired(final List authReq) {
this.authReq.addAll(authReq);
return this;
}
public HintsBuilder withStatus(final Status status) {
this.status = status;
return this;
}
public Hints build() {
return hints(
allows,
new ArrayList(representations),
new ArrayList(acceptPut),
new ArrayList(acceptPost),
new ArrayList(acceptPatch),
new ArrayList(acceptRanges),
new ArrayList(preferences),
preconditionReq,
authReq,
status,
docs
);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy