1 | // Copyright 2004-2007 Jean-Francois Poilpret |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | package net.sourceforge.hiveboard.util; |
16 | |
17 | import org.apache.hivemind.util.ToStringBuilder; |
18 | |
19 | import net.sourceforge.hiveboard.Account; |
20 | import net.sourceforge.hiveboard.Board; |
21 | |
22 | public class Participant |
23 | { |
24 | public Participant(Account account, Board board) |
25 | { |
26 | _account = account; |
27 | _board = board; |
28 | _id = _account.getId(); |
29 | } |
30 | |
31 | public Account getAccount() |
32 | { |
33 | return _account; |
34 | } |
35 | |
36 | public Board getBoard() |
37 | { |
38 | return _board; |
39 | } |
40 | |
41 | public void setRequester() |
42 | { |
43 | _requester = true; |
44 | } |
45 | public boolean isRequester() |
46 | { |
47 | return _requester; |
48 | } |
49 | |
50 | public boolean isInitiator() |
51 | { |
52 | return (_id == _board.getInitiator()); |
53 | } |
54 | |
55 | public boolean isWriter() |
56 | { |
57 | boolean writer = (_id == _board.getWriter()); |
58 | if (writer) |
59 | { |
60 | _requester = false; |
61 | } |
62 | return writer; |
63 | } |
64 | |
65 | public boolean isPresent() |
66 | { |
67 | return (_board.getPresents().contains(_id)); |
68 | } |
69 | |
70 | @Override public String toString() |
71 | { |
72 | ToStringBuilder builder = new ToStringBuilder(this); |
73 | builder.append("account", _account.getId()); |
74 | builder.append("board", _board.getId()); |
75 | return builder.toString(); |
76 | } |
77 | |
78 | final private Account _account; |
79 | final private Board _board; |
80 | final private int _id; |
81 | private boolean _requester; |
82 | } |