2 * Sone - SimpleFieldSetBuilder.java - Copyright © 2011–2012 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 net.pterodactylus.util.validation.Validation;
21 import freenet.support.SimpleFieldSet;
24 * Helper class to construct {@link SimpleFieldSet} objects in a single call.
26 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
28 public class SimpleFieldSetBuilder {
30 /** The simple field set that is being constructed. */
31 private final SimpleFieldSet simpleFieldSet;
34 * Creates a new simple field set builder using a new, empty simple field
37 public SimpleFieldSetBuilder() {
38 this(new SimpleFieldSet(true));
42 * Creates a new simple field set builder that will return the given simple
43 * field set on {@link #get()}.
45 * @param simpleFieldSet
46 * The simple field set to build
48 public SimpleFieldSetBuilder(SimpleFieldSet simpleFieldSet) {
49 Validation.begin().isNotNull("Simple Field Set", simpleFieldSet).check();
50 this.simpleFieldSet = simpleFieldSet;
54 * Returns the constructed simple field set.
56 * @return The construct simple field set
58 public SimpleFieldSet get() {
59 return simpleFieldSet;
63 * Copies the given simple field set into the simple field set being built
64 * in this builder, overwriting all previously existing values.
66 * @param simpleFieldSet
67 * The simple field set to copy
68 * @return This simple field set builder
70 public SimpleFieldSetBuilder put(SimpleFieldSet simpleFieldSet) {
71 this.simpleFieldSet.putAllOverwrite(simpleFieldSet);
76 * Stores the given value under the given key, overwriting any previous
80 * The key of the value
83 * @return This simple field set builder
85 public SimpleFieldSetBuilder put(String key, String value) {
86 simpleFieldSet.putOverwrite(key, value);
91 * Stores the given value under the given key, overwriting any previous
95 * The key of the value
98 * @return This simple field set builder
100 public SimpleFieldSetBuilder put(String key, int value) {
101 simpleFieldSet.put(key, value);
106 * Stores the given value under the given key, overwriting any previous
110 * The key of the value
113 * @return This simple field set builder
115 public SimpleFieldSetBuilder put(String key, long value) {
116 simpleFieldSet.put(key, value);