diff options
author | snowleo <schneeleo@gmail.com> | 2012-09-10 20:49:07 +0200 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2012-09-10 20:49:07 +0200 |
commit | 1cf0ebbd7f120c0b8d421cc459f2d5a1386d82dc (patch) | |
tree | 5c494cf4d05d847fd7811dfa06bada20f4d75719 /EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java | |
parent | 736a6d273abb000c81b17d0142ce358d2225f873 (diff) | |
download | Essentials-1cf0ebbd7f120c0b8d421cc459f2d5a1386d82dc.tar Essentials-1cf0ebbd7f120c0b8d421cc459f2d5a1386d82dc.tar.gz Essentials-1cf0ebbd7f120c0b8d421cc459f2d5a1386d82dc.tar.lz Essentials-1cf0ebbd7f120c0b8d421cc459f2d5a1386d82dc.tar.xz Essentials-1cf0ebbd7f120c0b8d421cc459f2d5a1386d82dc.zip |
Thread safety for GM
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java')
-rw-r--r-- | EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java | 18 |
1 files changed, 12 insertions, 6 deletions
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<String> permissions = new ArrayList<String>(); + private List<String> permissions = Collections.unmodifiableList(Collections.<String>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<String> clone = new ArrayList<String>(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<String> clone = new ArrayList<String>(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<String> 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<String> clone = new ArrayList<String>(permissions); + Collections.sort(clone, StringPermissionComparator.getInstance()); + permissions = Collections.unmodifiableList(clone); sorted = true; } } |