summaryrefslogtreecommitdiffstats
path: root/EssentialsUpdate/src/com/earth2me/essentials/update/states/AbstractYesNoState.java
blob: 67baf6bb637ee42ac1464a9c602e4be5058e40cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.earth2me.essentials.update.states;


public abstract class AbstractYesNoState extends AbstractState
{
	private boolean answer = false;
	private final transient Class<? extends AbstractState> yesState;
	private final transient Class<? extends AbstractState> noState;

	public AbstractYesNoState(final StateMap states, final Class<? extends AbstractState> nextState)
	{
		this(states, nextState, nextState);
	}

	public AbstractYesNoState(final StateMap states, final Class<? extends AbstractState> yesState, final Class<? extends AbstractState> noState)
	{
		super(states);
		this.yesState = yesState;
		this.noState = noState;
	}

	@Override
	public AbstractState getNextState()
	{
		return answer
			   ? (yesState == null ? null : getState(yesState))
			   : (noState == null ? null : getState(noState));
	}

	@Override
	public boolean reactOnAnswer(final String answer)
	{
		if (answer.equalsIgnoreCase("yes")
			|| answer.equalsIgnoreCase("y"))
		{
			this.answer = true;
			return true;
		}
		if (answer.equalsIgnoreCase("no")
			|| answer.equalsIgnoreCase("n"))
		{
			this.answer = false;
			return true;
		}
		return false;
	}

	public boolean getAnswer()
	{
		return answer;
	}

	protected void setAnswer(final boolean answer)
	{
		this.answer = answer;
	}
}