2 * Sone - SimpleFieldSetBuilder.java - Copyright © 2011–2019 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.freenet;
20 import static com.google.common.base.Preconditions.checkNotNull;
22 import freenet.support.SimpleFieldSet;
25 * Helper class to construct {@link SimpleFieldSet} objects in a single call.
27 public class SimpleFieldSetBuilder {
29 /** The simple field set that is being constructed. */
30 private final SimpleFieldSet simpleFieldSet;
33 * Creates a new simple field set builder using a new, empty simple field
36 public SimpleFieldSetBuilder() {
37 this(new SimpleFieldSet(true));
41 * Creates a new simple field set builder that will return the given simple
42 * field set on {@link #get()}.
44 * @param simpleFieldSet
45 * The simple field set to build
47 public SimpleFieldSetBuilder(SimpleFieldSet simpleFieldSet) {
48 this.simpleFieldSet = checkNotNull(simpleFieldSet, "simpleFieldSet must not be null");
52 * Returns the constructed simple field set.
54 * @return The construct simple field set
56 public SimpleFieldSet get() {
57 return simpleFieldSet;
61 * Copies the given simple field set into the simple field set being built
62 * in this builder, overwriting all previously existing values.
64 * @param simpleFieldSet
65 * The simple field set to copy
66 * @return This simple field set builder
68 public SimpleFieldSetBuilder put(SimpleFieldSet simpleFieldSet) {
69 this.simpleFieldSet.putAllOverwrite(simpleFieldSet);
74 * Stores the given value under the given key, overwriting any previous
78 * The key of the value
81 * @return This simple field set builder
83 public SimpleFieldSetBuilder put(String key, String value) {
84 simpleFieldSet.putOverwrite(key, value);
89 * Stores the given value under the given key, overwriting any previous
93 * The key of the value
96 * @return This simple field set builder
98 public SimpleFieldSetBuilder put(String key, int value) {
99 simpleFieldSet.put(key, value);
104 * Stores the given value under the given key, overwriting any previous
108 * The key of the value
111 * @return This simple field set builder
113 public SimpleFieldSetBuilder put(String key, long value) {
114 simpleFieldSet.put(key, value);