2 * Quoridor server and related libraries
3 * Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License.
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. Look for COPYING file in the top folder.
16 * If not, see http://www.gnu.org/licenses/.
18 package cz.xelfi.quoridor.webidor;
20 import java.util.ArrayList;
21 import java.util.List;
23 import java.util.TreeSet;
24 import javax.xml.bind.annotation.XmlAccessType;
25 import javax.xml.bind.annotation.XmlAccessorType;
26 import javax.xml.bind.annotation.XmlAttribute;
27 import javax.xml.bind.annotation.XmlElement;
28 import javax.xml.bind.annotation.XmlRootElement;
29 import javax.xml.bind.annotation.XmlValue;
33 * @author Jaroslav Tulach <jtulach@netbeans.org>
36 @XmlAccessorType(XmlAccessType.NONE)
37 public final class User extends Object {
40 @XmlElement(name="property")
41 private List<Property> properties;
42 private transient Set<String> permissions;
47 public User(String id) {
51 public void addProperty(String name, String value) {
52 if (properties == null) {
53 properties = new ArrayList<Property>();
55 properties.add(new Property(name, value));
58 public void addPermission(String permission) {
59 if (permissions == null) {
60 permissions = new TreeSet<String>();
62 permissions.add(permission);
65 public String getProperty(String name) {
66 if (properties == null) {
69 for (Property p : properties) {
70 if (p.name.equals(name)) {
77 public boolean hasPermission(String permission) {
78 if (permissions == null) {
81 return permissions.contains(permission);
84 public static boolean canSee(GameId gId, String userId) {
85 if (!gId.isFinished()) {
88 if (userId.equals(gId.getWhite())) {
91 if (userId.equals(gId.getBlack())) {
97 public boolean canSee(GameId gId){
98 return canSee(gId, id);
101 public String getId() {
105 public static final class Property {
109 private String value;
114 Property(String name, String value) {