Skip to content

Method: fixedBoolean(String, Boolean)

1: package de.fhdw.gaming.core.ui.util;
2:
3: import java.util.Map;
4: import java.util.Optional;
5: import java.util.Set;
6: import java.util.function.Function;
7:
8: import de.fhdw.gaming.core.ui.InputProvider;
9: import de.fhdw.gaming.core.ui.InputProviderException;
10: import de.fhdw.gaming.core.ui.type.validator.Validator;
11:
12: /**
13: * An {@link InputProvider} that links two {@link InputProvider}s together.
14: */
15: public final class ChainedInputProvider implements InputProvider {
16:
17: /**
18: * The current {@link InputProvider} in the chain.
19: */
20: private final InputProvider current;
21: /**
22: * A function returning the next {@link InputProvider} in the chain, given the data requested by the current one.
23: */
24: private final Function<Map<String, Object>, InputProvider> next;
25:
26: /**
27: * Creates a {@link ChainedInputProvider}.
28: *
29: * @param current The current {@link InputProvider} in the chain to delegate requests to.
30: * @param next A function returning the next {@link InputProvider} in the chain, given the data requested by the
31: * current one.
32: */
33: public ChainedInputProvider(final InputProvider current, final Function<Map<String, Object>, InputProvider> next) {
34: this.current = current;
35: this.next = next;
36: }
37:
38: @Override
39: @SafeVarargs
40: public final InputProvider needString(final String id, final String prompt, final Optional<String> defaultValue,
41: final Validator<String>... validators) throws InputProviderException {
42:
43: this.current.needString(id, prompt, defaultValue, validators);
44: return this;
45: }
46:
47: @Override
48: public InputProvider fixedString(final String id, final String fixedValue) throws InputProviderException {
49: this.current.fixedString(id, fixedValue);
50: return this;
51: }
52:
53: @Override
54: @SafeVarargs
55: public final InputProvider needInteger(final String id, final String prompt, final Optional<Integer> defaultValue,
56: final Validator<Integer>... validators) throws InputProviderException {
57:
58: this.current.needInteger(id, prompt, defaultValue, validators);
59: return this;
60: }
61:
62: @Override
63: public InputProvider fixedInteger(final String id, final Integer fixedValue) throws InputProviderException {
64: this.current.fixedInteger(id, fixedValue);
65: return this;
66: }
67:
68: @Override
69: @SafeVarargs
70: public final InputProvider needBoolean(final String id, final String prompt, final Optional<Boolean> defaultValue,
71: final Validator<Boolean>... validators) throws InputProviderException {
72:
73: this.current.needBoolean(id, prompt, defaultValue, validators);
74: return this;
75: }
76:
77: @Override
78: public InputProvider fixedBoolean(final String id, final Boolean fixedValue) throws InputProviderException {
79: this.current.fixedBoolean(id, fixedValue);
80: return this;
81: }
82:
83: @Override
84: public InputProvider needObject(final String id, final String prompt, final Optional<Object> defaultValue,
85: final Set<? extends Object> objectSet) throws InputProviderException {
86:
87: this.current.needObject(id, prompt, defaultValue, objectSet);
88: return this;
89: }
90:
91: @Override
92: public InputProvider fixedObject(final String id, final Object fixedValue) throws InputProviderException {
93: this.current.fixedObject(id, fixedValue);
94: return this;
95: }
96:
97: @Override
98: public Map<String, Object> requestData(final String title) throws InputProviderException {
99: return this.current.requestData(title);
100: }
101:
102: @Override
103: public InputProvider getNext(final Map<String, Object> lastDataSet) {
104: return this.next.apply(lastDataSet);
105: }
106: }