From a028abe03630c1990105f5dbfef5ba44bf11602d Mon Sep 17 00:00:00 2001 From: ElgarL Date: Fri, 13 Apr 2012 14:40:26 +0100 Subject: Update all code formatting to use tabs for indentation. --- .../org/anjocaido/groupmanager/data/DataUnit.java | 294 +++++++++-------- .../src/org/anjocaido/groupmanager/data/Group.java | 317 ++++++++++--------- .../groupmanager/data/GroupVariables.java | 139 ++++---- .../src/org/anjocaido/groupmanager/data/User.java | 32 +- .../anjocaido/groupmanager/data/UserVariables.java | 73 +++-- .../org/anjocaido/groupmanager/data/Variables.java | 352 +++++++++++---------- 6 files changed, 645 insertions(+), 562 deletions(-) (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager/data') diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java index e3250a1c1..bb04fa3d7 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java @@ -13,151 +13,169 @@ import org.anjocaido.groupmanager.dataholder.WorldDataHolder; import org.anjocaido.groupmanager.utils.StringPermissionComparator; /** - * + * * @author gabrielcouto */ public abstract class DataUnit { - private WorldDataHolder dataSource; - private String name; - private boolean changed, sorted = false; - private ArrayList permissions = new ArrayList(); + private WorldDataHolder dataSource; + private String name; + private boolean changed, sorted = false; + private ArrayList permissions = new ArrayList(); - public DataUnit(WorldDataHolder dataSource, String name) { - this.dataSource = dataSource; - this.name = name; - } + public DataUnit(WorldDataHolder dataSource, String name) { - public DataUnit(String name) { - this.name = name; + this.dataSource = dataSource; + this.name = name; + } + + public DataUnit(String name) { + + this.name = name; + } + + /** + * Every group is matched only by their names and DataSources names. + * + * @param o + * @return true if they are equal. false if not. + */ + @Override + public boolean equals(Object o) { + + if (o instanceof DataUnit) { + DataUnit go = (DataUnit) o; + if (this.getName().equalsIgnoreCase(go.getName())) { + // Global Group match. + if (this.dataSource == null && go.getDataSource() == null) + return true; + // This is a global group, the object to test isn't. + if (this.dataSource == null && go.getDataSource() != null) + return false; + // This is not a global group, but the object to test is. + if (this.dataSource != null && go.getDataSource() == null) + return false; + // Match on group name and world name. + if (this.dataSource.getName().equalsIgnoreCase(go.getDataSource().getName())) + return true; + } + } + return false; + } + + @Override + public int hashCode() { + + int hash = 5; + hash = 71 * hash + (this.name != null ? this.name.toLowerCase().hashCode() : 0); + return hash; + } + + /** + * Set the data source to point to a different worldDataHolder + * + * @param source + */ + public void setDataSource(WorldDataHolder source) { + + this.dataSource = source; + } + + /** + * Get the current worldDataHolder this object is pointing to + * + * @return the dataSource + */ + public WorldDataHolder getDataSource() { + + return dataSource; + } + + /** + * @return the name + */ + public String getName() { + + return name; + } + + public void flagAsChanged() { + + WorldDataHolder testSource = getDataSource(); + String source = ""; + + if (testSource == null) + source = "GlobalGroups"; + else + source = testSource.getName(); + + GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as changed!"); + // for(StackTraceElement st: Thread.currentThread().getStackTrace()){ + // GroupManager.logger.finest(st.toString()); + // } + sorted = false; + changed = true; + } + + public boolean isChanged() { + + return changed; + } + + public void flagAsSaved() { + + WorldDataHolder testSource = getDataSource(); + String source = ""; + + if (testSource == null) + source = "GlobalGroups"; + else + source = testSource.getName(); + + GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as saved!"); + changed = false; + } + + public boolean hasSamePermissionNode(String permission) { + + return permissions.contains(permission); + } + + public void addPermission(String permission) { + + if (!hasSamePermissionNode(permission)) { + permissions.add(permission); + } + flagAsChanged(); + } + + public boolean removePermission(String permission) { + + flagAsChanged(); + return permissions.remove(permission); } /** - * Every group is matched only by their names and DataSources names. - * @param o - * @return true if they are equal. false if not. - */ - @Override - public boolean equals(Object o) { - if (o instanceof DataUnit) { - DataUnit go = (DataUnit) o; - if (this.getName().equalsIgnoreCase(go.getName())) { - // Global Group match. - if (this.dataSource == null && go.getDataSource() == null) - return true; - // This is a global group, the object to test isn't. - if (this.dataSource == null && go.getDataSource() != null) - return false; - // This is not a global group, but the object to test is. - if (this.dataSource != null && go.getDataSource() == null) - return false; - // Match on group name and world name. - if (this.dataSource.getName().equalsIgnoreCase(go.getDataSource().getName())) - return true; - } - } - return false; - } - - @Override - public int hashCode() { - int hash = 5; - hash = 71 * hash + (this.name != null ? this.name.toLowerCase().hashCode() : 0); - return hash; - } - - /** - * Set the data source to point to a different worldDataHolder - * - * @param source - */ - public void setDataSource(WorldDataHolder source) { - this.dataSource = source; - } - - /** - * Get the current worldDataHolder this object is pointing to - * - * @return the dataSource - */ - public WorldDataHolder getDataSource() { - return dataSource; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - public void flagAsChanged() { - WorldDataHolder testSource = getDataSource(); - String source = ""; - - if (testSource == null) - source = "GlobalGroups"; - else - source = testSource.getName(); - - GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as changed!"); -// for(StackTraceElement st: Thread.currentThread().getStackTrace()){ -// GroupManager.logger.finest(st.toString()); -// } - sorted = false; - changed = true; - } - - public boolean isChanged() { - return changed; - } - - public void flagAsSaved() { - WorldDataHolder testSource = getDataSource(); - String source = ""; - - if (testSource == null) - source = "GlobalGroups"; - else - source = testSource.getName(); - - GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as saved!"); - changed = false; - } - - public boolean hasSamePermissionNode(String permission) { - return permissions.contains(permission); - } - - public void addPermission(String permission) { - if (!hasSamePermissionNode(permission)) { - permissions.add(permission); - } - flagAsChanged(); - } - - public boolean removePermission(String permission) { - flagAsChanged(); - return permissions.remove(permission); - } - - /** - * Use this only to list permissions. - * You can't edit the permissions using the returned ArrayList instance - * @return a copy of the permission list - */ - public List getPermissionList() { - return Collections.unmodifiableList(permissions); - } - - public boolean isSorted() { - return this.sorted; - } - - public void sortPermissions() { - if (!isSorted()) { - Collections.sort(permissions, StringPermissionComparator.getInstance()); - sorted = true; - } - } + * Use this only to list permissions. + * You can't edit the permissions using the returned ArrayList instance + * + * @return a copy of the permission list + */ + public List getPermissionList() { + + return Collections.unmodifiableList(permissions); + } + + public boolean isSorted() { + + return this.sorted; + } + + public void sortPermissions() { + + if (!isSorted()) { + Collections.sort(permissions, StringPermissionComparator.getInstance()); + sorted = true; + } + } } \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java index 56ef7e870..751dc8fd6 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java @@ -15,160 +15,173 @@ import java.util.List; import java.util.Map; /** - * + * * @author gabrielcouto/ElgarL */ public class Group extends DataUnit implements Cloneable { - /** - * The group it inherits DIRECTLY! - */ - private ArrayList inherits = new ArrayList(); - /** - *This one holds the fields in INFO node. - * like prefix = 'c' - * or build = false - */ - private GroupVariables variables = new GroupVariables(this); - - /** - * Constructor for individual World Groups. - * - * @param name - */ - public Group(WorldDataHolder source, String name) { - super(source, name); - } - - /** - * Constructor for Global Groups. - * - * @param name - */ - public Group(String name) { - super(name); - } - - /** - * Is this a GlobalGroup - * - * @return true if this is a global group - */ - public boolean isGlobal() { - return (getDataSource() == null); - } - - /** - * Clone this group - * @return a clone of this group - */ - @Override - public Group clone() { - Group clone; - - if (isGlobal()) { - clone = new Group(this.getName()); - } else { - clone = new Group(getDataSource(), this.getName()); - clone.inherits = new ArrayList(this.getInherits()); - } - - for (String perm : this.getPermissionList()) { - clone.addPermission(perm); - } - clone.variables = ((GroupVariables) variables).clone(clone); - //clone.flagAsChanged(); - return clone; - } - - /** - * Use this to deliver a group from a different dataSource to another - * @param dataSource - * @return Null or Clone - */ - public Group clone(WorldDataHolder dataSource) { - if (dataSource.groupExists(this.getName())) { - return null; - } - - Group clone = dataSource.createGroup(this.getName()); - - // Don't add inheritance for GlobalGroups - if (!isGlobal()) { - clone.inherits = new ArrayList(this.getInherits()); - } - for (String perm : this.getPermissionList()) { - clone.addPermission(perm); - } - clone.variables = variables.clone(clone); - clone.flagAsChanged(); //use this to make the new dataSource save the new group - return clone; - } - - /** - * an unmodifiable list of inherits list - * You can't manage the list by here - * Lol... version 0.6 had a problem because this. - * @return the inherits - */ - public List getInherits() { - return Collections.unmodifiableList(inherits); - } - - /** - * @param inherit the inherits to set - */ - public void addInherits(Group inherit) { - if (!isGlobal()) { - if (!this.getDataSource().groupExists(inherit.getName())) { - getDataSource().addGroup(inherit); - } - if (!inherits.contains(inherit.getName().toLowerCase())) { - inherits.add(inherit.getName().toLowerCase()); - } - flagAsChanged(); - if (GroupManager.isLoaded()) { - GroupManager.BukkitPermissions.updateAllPlayers(); - GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); - } - } - } - - public boolean removeInherits(String inherit) { - if (!isGlobal()) { - if (this.inherits.contains(inherit.toLowerCase())) { - this.inherits.remove(inherit.toLowerCase()); - flagAsChanged(); - GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); - return true; - } - } - return false; - } - - /** - * @return the variables - */ - public GroupVariables getVariables() { - return variables; - } - - /** - * - * @param varList - */ - public void setVariables(Map varList) { - if (!isGlobal()) { - GroupVariables temp = new GroupVariables(this, varList); - variables.clearVars(); - for (String key : temp.getVarKeyList()) { - variables.addVar(key, temp.getVarObject(key)); - } - flagAsChanged(); - if (GroupManager.isLoaded()) { - GroupManager.BukkitPermissions.updateAllPlayers(); - GroupManagerEventHandler.callEvent(this, Action.GROUP_INFO_CHANGED); - } - } - } + /** + * The group it inherits DIRECTLY! + */ + private ArrayList inherits = new ArrayList(); + /** + * This one holds the fields in INFO node. + * like prefix = 'c' + * or build = false + */ + private GroupVariables variables = new GroupVariables(this); + + /** + * Constructor for individual World Groups. + * + * @param name + */ + public Group(WorldDataHolder source, String name) { + + super(source, name); + } + + /** + * Constructor for Global Groups. + * + * @param name + */ + public Group(String name) { + + super(name); + } + + /** + * Is this a GlobalGroup + * + * @return true if this is a global group + */ + public boolean isGlobal() { + + return (getDataSource() == null); + } + + /** + * Clone this group + * + * @return a clone of this group + */ + @Override + public Group clone() { + + Group clone; + + if (isGlobal()) { + clone = new Group(this.getName()); + } else { + clone = new Group(getDataSource(), this.getName()); + clone.inherits = new ArrayList(this.getInherits()); + } + + for (String perm : this.getPermissionList()) { + clone.addPermission(perm); + } + clone.variables = ((GroupVariables) variables).clone(clone); + //clone.flagAsChanged(); + return clone; + } + + /** + * Use this to deliver a group from a different dataSource to another + * + * @param dataSource + * @return Null or Clone + */ + public Group clone(WorldDataHolder dataSource) { + + if (dataSource.groupExists(this.getName())) { + return null; + } + + Group clone = dataSource.createGroup(this.getName()); + + // Don't add inheritance for GlobalGroups + if (!isGlobal()) { + clone.inherits = new ArrayList(this.getInherits()); + } + for (String perm : this.getPermissionList()) { + clone.addPermission(perm); + } + clone.variables = variables.clone(clone); + clone.flagAsChanged(); //use this to make the new dataSource save the new group + return clone; + } + + /** + * an unmodifiable list of inherits list + * You can't manage the list by here + * Lol... version 0.6 had a problem because this. + * + * @return the inherits + */ + public List getInherits() { + + return Collections.unmodifiableList(inherits); + } + + /** + * @param inherit the inherits to set + */ + public void addInherits(Group inherit) { + + if (!isGlobal()) { + if (!this.getDataSource().groupExists(inherit.getName())) { + getDataSource().addGroup(inherit); + } + if (!inherits.contains(inherit.getName().toLowerCase())) { + inherits.add(inherit.getName().toLowerCase()); + } + flagAsChanged(); + if (GroupManager.isLoaded()) { + GroupManager.BukkitPermissions.updateAllPlayers(); + GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); + } + } + } + + public boolean removeInherits(String inherit) { + + if (!isGlobal()) { + if (this.inherits.contains(inherit.toLowerCase())) { + this.inherits.remove(inherit.toLowerCase()); + flagAsChanged(); + GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); + return true; + } + } + return false; + } + + /** + * @return the variables + */ + public GroupVariables getVariables() { + + return variables; + } + + /** + * + * @param varList + */ + public void setVariables(Map varList) { + + if (!isGlobal()) { + GroupVariables temp = new GroupVariables(this, varList); + variables.clearVars(); + for (String key : temp.getVarKeyList()) { + variables.addVar(key, temp.getVarObject(key)); + } + flagAsChanged(); + if (GroupManager.isLoaded()) { + GroupManager.BukkitPermissions.updateAllPlayers(); + GroupManagerEventHandler.callEvent(this, Action.GROUP_INFO_CHANGED); + } + } + } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java index 19db58851..e08d1db7d 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java @@ -7,81 +7,88 @@ package org.anjocaido.groupmanager.data; import java.util.Map; /** - * + * * @author gabrielcouto */ public class GroupVariables extends Variables implements Cloneable { - private Group owner; + private Group owner; - public GroupVariables(Group owner) { - super(owner); - this.owner = owner; - addVar("prefix", ""); - addVar("suffix", ""); - addVar("build", false); - } + public GroupVariables(Group owner) { - public GroupVariables(Group owner, Map varList) { - super(owner); - variables = varList; - if (variables.get("prefix") == null) { - variables.put("prefix", ""); - owner.flagAsChanged(); - } - //thisGrp.prefix = infoNode.get("prefix").toString(); + super(owner); + this.owner = owner; + addVar("prefix", ""); + addVar("suffix", ""); + addVar("build", false); + } - if (variables.get("suffix") == null) { - variables.put("suffix", ""); - owner.flagAsChanged(); - } - //thisGrp.suffix = infoNode.get("suffix").toString(); + public GroupVariables(Group owner, Map varList) { - if (variables.get("build") == null) { - variables.put("build", false); - owner.flagAsChanged(); - } - this.owner = owner; - } + super(owner); + variables = varList; + if (variables.get("prefix") == null) { + variables.put("prefix", ""); + owner.flagAsChanged(); + } + //thisGrp.prefix = infoNode.get("prefix").toString(); - /** - * A clone of all vars here. - * @return GroupVariables clone - */ - protected GroupVariables clone(Group newOwner) { - GroupVariables clone = new GroupVariables(newOwner); - for (String key : variables.keySet()) { - clone.variables.put(key, variables.get(key)); - } - newOwner.flagAsChanged(); - return clone; - } + if (variables.get("suffix") == null) { + variables.put("suffix", ""); + owner.flagAsChanged(); + } + //thisGrp.suffix = infoNode.get("suffix").toString(); - /** - * Remove a var from the list - * @param name - */ - @Override - public void removeVar(String name) { - try { - this.variables.remove(name); - } catch (Exception e) { - } - if (name.equals("prefix")) { - addVar("prefix", ""); - } else if (name.equals("suffix")) { - addVar("suffix", ""); - } else if (name.equals("build")) { - addVar("build", false); - } - owner.flagAsChanged(); - } + if (variables.get("build") == null) { + variables.put("build", false); + owner.flagAsChanged(); + } + this.owner = owner; + } - /** - * @return the owner - */ - @Override - public Group getOwner() { - return owner; - } + /** + * A clone of all vars here. + * + * @return GroupVariables clone + */ + protected GroupVariables clone(Group newOwner) { + + GroupVariables clone = new GroupVariables(newOwner); + for (String key : variables.keySet()) { + clone.variables.put(key, variables.get(key)); + } + newOwner.flagAsChanged(); + return clone; + } + + /** + * Remove a var from the list + * + * @param name + */ + @Override + public void removeVar(String name) { + + try { + this.variables.remove(name); + } catch (Exception e) { + } + if (name.equals("prefix")) { + addVar("prefix", ""); + } else if (name.equals("suffix")) { + addVar("suffix", ""); + } else if (name.equals("build")) { + addVar("build", false); + } + owner.flagAsChanged(); + } + + /** + * @return the owner + */ + @Override + public Group getOwner() { + + return owner; + } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java index 217ab904e..25b3cb3fe 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java @@ -16,7 +16,6 @@ import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.entity.Player; - /** * * @author gabrielcouto/ElgarL @@ -40,6 +39,7 @@ public class User extends DataUnit implements Cloneable { * @param name */ public User(WorldDataHolder source, String name) { + super(source, name); this.group = source.getDefaultGroup().getName(); } @@ -50,6 +50,7 @@ public class User extends DataUnit implements Cloneable { */ @Override public User clone() { + User clone = new User(getDataSource(), this.getName()); clone.group = this.group; for (String perm : this.getPermissionList()) { @@ -67,6 +68,7 @@ public class User extends DataUnit implements Cloneable { * @return null if given dataSource already contains the same user */ public User clone(WorldDataHolder dataSource) { + if (dataSource.isUserDeclared(this.getName())) { return null; } @@ -85,6 +87,7 @@ public class User extends DataUnit implements Cloneable { } public Group getGroup() { + Group result = getDataSource().getGroup(group); if (result == null) { this.setGroup(getDataSource().getDefaultGroup()); @@ -97,6 +100,7 @@ public class User extends DataUnit implements Cloneable { * @return the group */ public String getGroupName() { + Group result = getDataSource().getGroup(group); if (result == null) { group = getDataSource().getDefaultGroup().getName(); @@ -110,6 +114,7 @@ public class User extends DataUnit implements Cloneable { */ @Deprecated public void setGroup(String group) { + this.group = group; flagAsChanged(); if (GroupManager.isLoaded()) @@ -122,15 +127,17 @@ public class User extends DataUnit implements Cloneable { * the group to set */ public void setGroup(Group group) { + setGroup(group, true); } - + /** * @param group the group to set * @param updatePerms if we are to trigger a superperms update. - * + * */ public void setGroup(Group group, Boolean updatePerms) { + if (!this.getDataSource().groupExists(group.getName())) { getDataSource().addGroup(group); } @@ -151,12 +158,13 @@ public class User extends DataUnit implements Cloneable { if (notify) GroupManager.notify(this.getName(), String.format(" moved to the group %s.", group.getName())); - + GroupManagerEventHandler.callEvent(this, Action.USER_GROUP_CHANGED); } } public boolean addSubGroup(Group subGroup) { + // Don't allow adding a subgroup if it's already set as the primary. if (this.group.equalsIgnoreCase(subGroup.getName())) { return false; @@ -164,12 +172,12 @@ public class User extends DataUnit implements Cloneable { // User already has this subgroup if (containsSubGroup(subGroup)) return false; - + // If the group doesn't exists add it if (!this.getDataSource().groupExists(subGroup.getName())) { getDataSource().addGroup(subGroup); } - + subGroups.add(subGroup.getName()); flagAsChanged(); if (GroupManager.isLoaded()) { @@ -178,25 +186,29 @@ public class User extends DataUnit implements Cloneable { GroupManagerEventHandler.callEvent(this, Action.USER_SUBGROUP_CHANGED); } return true; - + //subGroup = getDataSource().getGroup(subGroup.getName()); //removeSubGroup(subGroup); //subGroups.add(subGroup.getName()); } public int subGroupsSize() { + return subGroups.size(); } public boolean isSubGroupsEmpty() { + return subGroups.isEmpty(); } public boolean containsSubGroup(Group subGroup) { + return subGroups.contains(subGroup.getName()); } public boolean removeSubGroup(Group subGroup) { + try { if (subGroups.remove(subGroup.getName())) { flagAsChanged(); @@ -212,6 +224,7 @@ public class User extends DataUnit implements Cloneable { } public ArrayList subGroupListCopy() { + ArrayList val = new ArrayList(); for (String gstr : subGroups) { Group g = getDataSource().getGroup(gstr); @@ -225,6 +238,7 @@ public class User extends DataUnit implements Cloneable { } public ArrayList subGroupListStringCopy() { + return new ArrayList(subGroups); } @@ -232,6 +246,7 @@ public class User extends DataUnit implements Cloneable { * @return the variables */ public UserVariables getVariables() { + return variables; } @@ -240,6 +255,7 @@ public class User extends DataUnit implements Cloneable { * @param varList */ public void setVariables(Map varList) { + //UserVariables temp = new UserVariables(this, varList); variables.clearVars(); for (String key : varList.keySet()) { @@ -254,6 +270,7 @@ public class User extends DataUnit implements Cloneable { } public User updatePlayer(Player player) { + if (player != null) { bukkitPlayer = player; } @@ -261,6 +278,7 @@ public class User extends DataUnit implements Cloneable { } public Player getBukkitPlayer() { + if (bukkitPlayer == null) { bukkitPlayer = Bukkit.getPlayer(this.getName()); } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java index 0b3948cab..f994595c1 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java @@ -7,42 +7,47 @@ package org.anjocaido.groupmanager.data; import java.util.Map; /** - * + * * @author gabrielcouto */ public class UserVariables extends Variables { - private User owner; - - public UserVariables(User owner) { - super(owner); - this.owner = owner; - } - - public UserVariables(User owner, Map varList) { - super(owner); - this.variables = varList; - this.owner = owner; - } - - /** - * A clone of all vars here. - * @return UserVariables clone - */ - protected UserVariables clone(User newOwner) { - UserVariables clone = new UserVariables(newOwner); - for (String key : variables.keySet()) { - clone.variables.put(key, variables.get(key)); - } - newOwner.flagAsChanged(); - return clone; - } - - /** - * @return the owner - */ - @Override - public User getOwner() { - return owner; - } + private User owner; + + public UserVariables(User owner) { + + super(owner); + this.owner = owner; + } + + public UserVariables(User owner, Map varList) { + + super(owner); + this.variables = varList; + this.owner = owner; + } + + /** + * A clone of all vars here. + * + * @return UserVariables clone + */ + protected UserVariables clone(User newOwner) { + + UserVariables clone = new UserVariables(newOwner); + for (String key : variables.keySet()) { + clone.variables.put(key, variables.get(key)); + } + newOwner.flagAsChanged(); + return clone; + } + + /** + * @return the owner + */ + @Override + public User getOwner() { + + return owner; + } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java index 140d6626a..42ceba7e4 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java @@ -9,178 +9,200 @@ import java.util.Map; import java.util.Set; /** - *A class that holds variables of a user/group. + * A class that holds variables of a user/group. * In groups, it holds the contents of INFO node. * Like: * prefix * suffix * build - * + * * @author gabrielcouto */ public abstract class Variables implements Cloneable { - private DataUnit owner; - protected Map variables = new HashMap(); - - public Variables(DataUnit owner) { - this.owner = owner; - } - - /** - * Add var to the the INFO node. - * examples: - * addVar("build",true); - * addVar("prefix","c"); - * @param name key name of the var - * @param o the object value of the var - */ - public void addVar(String name, Object o) { - if (o == null) { - return; - } - if (variables.containsKey(name)) { - variables.remove(name); - } - variables.put(name, o); - owner.flagAsChanged(); - } - - /** - * Returns the object inside the var - * @param name - * @return a Object if exists. null if doesn't exists - */ - public Object getVarObject(String name) { - return variables.get(name); - } - - /** - * Get the String value for the given var name - * @param name the var key name - * @return "" if null. or the toString() value of object - */ - public String getVarString(String name) { - Object o = variables.get(name); - try { - return o == null ? "" : o.toString(); - } catch (Exception e) { - return ""; - } - } - - /** - * - * @param name - * @return false if null. or a Boolean.parseBoolean of the string - */ - public Boolean getVarBoolean(String name) { - Object o = variables.get(name); - try { - return o == null ? false : Boolean.parseBoolean(o.toString()); - } catch (Exception e) { - return false; - } - } - - /** - * - * @param name - * @return -1 if null. or a parseInt of the string - */ - public Integer getVarInteger(String name) { - Object o = variables.get(name); - try { - return o == null ? -1 : Integer.parseInt(o.toString()); - } catch (Exception e) { - return -1; - } - } - - /** - * - * @param name - * @return -1 if null. or a parseDouble of the string - */ - public Double getVarDouble(String name) { - Object o = variables.get(name); - try { - return o == null ? -1.0D : Double.parseDouble(o.toString()); - } catch (Exception e) { - return -1.0D; - } - } - - /** - * All variable keys this is holding - * @return Set of all variable names. - */ - public Set getVarKeyList() { - return variables.keySet(); - } - - /** - * verify is a var exists - * @param name the key name of the var - * @return true if that var exists - */ - public boolean hasVar(String name) { - return variables.containsKey(name); - } - - /** - * Returns the quantity of vars this is holding - * @return the number of vars - */ - public int getSize() { - return variables.size(); - } - - /** - * Remove a var from the list - * @param name - */ - public void removeVar(String name) { - try { - variables.remove(name); - } catch (Exception e) { - } - owner.flagAsChanged(); - } - - public static Object parseVariableValue(String value) { - try { - Integer i = Integer.parseInt(value); - return i; - } catch (NumberFormatException e) { - } - try { - Double d = Double.parseDouble(value); - return d; - } catch (NumberFormatException e) { - } - if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("on")) { - return true; - } else if (value.equalsIgnoreCase("false") || value.equalsIgnoreCase("no") || value.equalsIgnoreCase("off")) { - return false; - } - return value; - - } - - public void clearVars() { - variables.clear(); - owner.flagAsChanged(); - } - - /** - * @return the owner - */ - public DataUnit getOwner() { - return owner; - } - - public boolean isEmpty() { - return variables.isEmpty(); - } + private DataUnit owner; + protected Map variables = new HashMap(); + + public Variables(DataUnit owner) { + + this.owner = owner; + } + + /** + * Add var to the the INFO node. + * examples: + * addVar("build",true); + * addVar("prefix","c"); + * + * @param name key name of the var + * @param o the object value of the var + */ + public void addVar(String name, Object o) { + + if (o == null) { + return; + } + if (variables.containsKey(name)) { + variables.remove(name); + } + variables.put(name, o); + owner.flagAsChanged(); + } + + /** + * Returns the object inside the var + * + * @param name + * @return a Object if exists. null if doesn't exists + */ + public Object getVarObject(String name) { + + return variables.get(name); + } + + /** + * Get the String value for the given var name + * + * @param name the var key name + * @return "" if null. or the toString() value of object + */ + public String getVarString(String name) { + + Object o = variables.get(name); + try { + return o == null ? "" : o.toString(); + } catch (Exception e) { + return ""; + } + } + + /** + * + * @param name + * @return false if null. or a Boolean.parseBoolean of the string + */ + public Boolean getVarBoolean(String name) { + + Object o = variables.get(name); + try { + return o == null ? false : Boolean.parseBoolean(o.toString()); + } catch (Exception e) { + return false; + } + } + + /** + * + * @param name + * @return -1 if null. or a parseInt of the string + */ + public Integer getVarInteger(String name) { + + Object o = variables.get(name); + try { + return o == null ? -1 : Integer.parseInt(o.toString()); + } catch (Exception e) { + return -1; + } + } + + /** + * + * @param name + * @return -1 if null. or a parseDouble of the string + */ + public Double getVarDouble(String name) { + + Object o = variables.get(name); + try { + return o == null ? -1.0D : Double.parseDouble(o.toString()); + } catch (Exception e) { + return -1.0D; + } + } + + /** + * All variable keys this is holding + * + * @return Set of all variable names. + */ + public Set getVarKeyList() { + + return variables.keySet(); + } + + /** + * verify is a var exists + * + * @param name the key name of the var + * @return true if that var exists + */ + public boolean hasVar(String name) { + + return variables.containsKey(name); + } + + /** + * Returns the quantity of vars this is holding + * + * @return the number of vars + */ + public int getSize() { + + return variables.size(); + } + + /** + * Remove a var from the list + * + * @param name + */ + public void removeVar(String name) { + + try { + variables.remove(name); + } catch (Exception e) { + } + owner.flagAsChanged(); + } + + public static Object parseVariableValue(String value) { + + try { + Integer i = Integer.parseInt(value); + return i; + } catch (NumberFormatException e) { + } + try { + Double d = Double.parseDouble(value); + return d; + } catch (NumberFormatException e) { + } + if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("on")) { + return true; + } else if (value.equalsIgnoreCase("false") || value.equalsIgnoreCase("no") || value.equalsIgnoreCase("off")) { + return false; + } + return value; + + } + + public void clearVars() { + + variables.clear(); + owner.flagAsChanged(); + } + + /** + * @return the owner + */ + public DataUnit getOwner() { + + return owner; + } + + public boolean isEmpty() { + + return variables.isEmpty(); + } } -- cgit v1.2.3