From 1cf0ebbd7f120c0b8d421cc459f2d5a1386d82dc Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 10 Sep 2012 20:49:07 +0200 Subject: Thread safety for GM --- .../src/org/anjocaido/groupmanager/data/DataUnit.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java') diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java index bb04fa3d7..5cd07048f 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java @@ -21,7 +21,7 @@ public abstract class DataUnit { private WorldDataHolder dataSource; private String name; private boolean changed, sorted = false; - private ArrayList permissions = new ArrayList(); + private List permissions = Collections.unmodifiableList(Collections.emptyList()); public DataUnit(WorldDataHolder dataSource, String name) { @@ -144,7 +144,9 @@ public abstract class DataUnit { public void addPermission(String permission) { if (!hasSamePermissionNode(permission)) { - permissions.add(permission); + List clone = new ArrayList(permissions); + clone.add(permission); + permissions = Collections.unmodifiableList(clone); } flagAsChanged(); } @@ -152,7 +154,10 @@ public abstract class DataUnit { public boolean removePermission(String permission) { flagAsChanged(); - return permissions.remove(permission); + List clone = new ArrayList(permissions); + boolean ret = clone.remove(permission); + permissions = Collections.unmodifiableList(clone); + return ret; } /** @@ -162,8 +167,7 @@ public abstract class DataUnit { * @return a copy of the permission list */ public List getPermissionList() { - - return Collections.unmodifiableList(permissions); + return permissions; } public boolean isSorted() { @@ -174,7 +178,9 @@ public abstract class DataUnit { public void sortPermissions() { if (!isSorted()) { - Collections.sort(permissions, StringPermissionComparator.getInstance()); + List clone = new ArrayList(permissions); + Collections.sort(clone, StringPermissionComparator.getInstance()); + permissions = Collections.unmodifiableList(clone); sorted = true; } } -- cgit v1.2.3