Skip to content

Method: fixedObject(String, Object)

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:
7: import de.fhdw.gaming.core.domain.util.FunctionE;
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 FunctionE<Map<String, Object>, InputProvider, InputProviderException> 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,
34: final FunctionE<Map<String, Object>, InputProvider, InputProviderException> next) {
35: this.current = current;
36: this.next = next;
37: }
38:
39: @Override
40: @SafeVarargs
41: public final ChainedInputProvider needString(final String id, final String prompt,
42: final Optional<String> defaultValue,
43: final Validator<String>... validators) throws InputProviderException {
44:
45: this.current.needString(id, prompt, defaultValue, validators);
46: return this;
47: }
48:
49: @Override
50: public ChainedInputProvider fixedString(final String id, final String fixedValue) throws InputProviderException {
51: this.current.fixedString(id, fixedValue);
52: return this;
53: }
54:
55: @Override
56: @SafeVarargs
57: public final ChainedInputProvider needInteger(final String id, final String prompt,
58: final Optional<Integer> defaultValue,
59: final Validator<Integer>... validators) throws InputProviderException {
60:
61: this.current.needInteger(id, prompt, defaultValue, validators);
62: return this;
63: }
64:
65: @Override
66: public ChainedInputProvider fixedInteger(final String id, final Integer fixedValue) throws InputProviderException {
67: this.current.fixedInteger(id, fixedValue);
68: return this;
69: }
70:
71: @Override
72: @SafeVarargs
73: public final ChainedInputProvider needBoolean(final String id, final String prompt,
74: final Optional<Boolean> defaultValue,
75: final Validator<Boolean>... validators) throws InputProviderException {
76:
77: this.current.needBoolean(id, prompt, defaultValue, validators);
78: return this;
79: }
80:
81: @Override
82: public ChainedInputProvider fixedBoolean(final String id, final Boolean fixedValue) throws InputProviderException {
83: this.current.fixedBoolean(id, fixedValue);
84: return this;
85: }
86:
87: @Override
88: public ChainedInputProvider needObject(final String id, final String prompt, final Optional<Object> defaultValue,
89: final Set<?> objectSet) throws InputProviderException {
90:
91: this.current.needObject(id, prompt, defaultValue, objectSet);
92: return this;
93: }
94:
95: @Override
96: public ChainedInputProvider fixedObject(final String id, final Object fixedValue) throws InputProviderException {
97: this.current.fixedObject(id, fixedValue);
98: return this;
99: }
100:
101: @Override
102: public Map<String, Object> requestData(final String title) throws InputProviderException {
103: return this.current.requestData(title);
104: }
105:
106: @Override
107: public InputProvider getNext(final Map<String, Object> lastDataSet) throws InputProviderException {
108: return this.next.apply(lastDataSet);
109: }
110: }