From 8e54bf13b281d1299c3dc33f89940bd3a06d1a30 Mon Sep 17 00:00:00 2001 From: Iaccidentally Date: Mon, 14 Jan 2013 20:02:22 -0500 Subject: Remove Transient :: Formatting Cleanup --- .../org/anjocaido/groupmanager/data/DataUnit.java | 98 +++++++++---- .../src/org/anjocaido/groupmanager/data/Group.java | 108 ++++++++------ .../groupmanager/data/GroupVariables.java | 56 +++++--- .../src/org/anjocaido/groupmanager/data/User.java | 159 ++++++++++++++------- .../anjocaido/groupmanager/data/UserVariables.java | 24 ++-- .../org/anjocaido/groupmanager/data/Variables.java | 145 ++++++++++++------- 6 files changed, 379 insertions(+), 211 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 bb04fa3d7..280a882c4 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/DataUnit.java @@ -12,59 +12,74 @@ import org.anjocaido.groupmanager.GroupManager; import org.anjocaido.groupmanager.dataholder.WorldDataHolder; import org.anjocaido.groupmanager.utils.StringPermissionComparator; + /** - * + * * @author gabrielcouto */ -public abstract class DataUnit { - +public abstract class DataUnit +{ private WorldDataHolder dataSource; private String name; private boolean changed, sorted = false; private ArrayList permissions = new ArrayList(); - public DataUnit(WorldDataHolder dataSource, String name) { + public DataUnit(WorldDataHolder dataSource, String name) + { this.dataSource = dataSource; this.name = name; } - public DataUnit(String 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())) { + 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() { + public int hashCode() + { int hash = 5; hash = 71 * hash + (this.name != null ? this.name.toLowerCase().hashCode() : 0); @@ -73,20 +88,22 @@ public abstract class DataUnit { /** * Set the data source to point to a different worldDataHolder - * + * * @param source */ - public void setDataSource(WorldDataHolder source) { + public void setDataSource(WorldDataHolder source) + { this.dataSource = source; } /** * Get the current worldDataHolder this object is pointing to - * + * * @return the dataSource */ - public WorldDataHolder getDataSource() { + public WorldDataHolder getDataSource() + { return dataSource; } @@ -94,20 +111,26 @@ public abstract class DataUnit { /** * @return the name */ - public String getName() { + public String getName() + { return name; } - public void flagAsChanged() { + 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()){ @@ -117,63 +140,76 @@ public abstract class DataUnit { changed = true; } - public boolean isChanged() { + public boolean isChanged() + { return changed; } - public void flagAsSaved() { + 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) { + public boolean hasSamePermissionNode(String permission) + { return permissions.contains(permission); } - public void addPermission(String permission) { + public void addPermission(String permission) + { - if (!hasSamePermissionNode(permission)) { + if (!hasSamePermissionNode(permission)) + { permissions.add(permission); } flagAsChanged(); } - public boolean removePermission(String permission) { + 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 - * + * 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() { + public List getPermissionList() + { return Collections.unmodifiableList(permissions); } - public boolean isSorted() { + public boolean isSorted() + { return this.sorted; } - public void sortPermissions() { + public void sortPermissions() + { - if (!isSorted()) { + if (!isSorted()) + { Collections.sort(permissions, StringPermissionComparator.getInstance()); sorted = true; } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java index 751dc8fd6..5fe7365ce 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java @@ -14,97 +14,108 @@ import java.util.Collections; import java.util.List; import java.util.Map; + /** - * + * * @author gabrielcouto/ElgarL */ -public class Group extends DataUnit implements Cloneable { - +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 + * 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) { + public Group(WorldDataHolder source, String name) + { super(source, name); } /** * Constructor for Global Groups. - * + * * @param name */ - public Group(String name) { + public Group(String name) + { super(name); } /** * Is this a GlobalGroup - * + * * @return true if this is a global group */ - public boolean isGlobal() { + public boolean isGlobal() + { return (getDataSource() == null); } /** * Clone this group - * + * * @return a clone of this group */ @Override - public Group clone() { + public Group clone() + { Group clone; - if (isGlobal()) { + if (isGlobal()) + { clone = new Group(this.getName()); - } else { + } + else + { clone = new Group(getDataSource(), this.getName()); clone.inherits = new ArrayList(this.getInherits()); } - for (String perm : this.getPermissionList()) { + for (String perm : this.getPermissionList()) + { clone.addPermission(perm); } - clone.variables = ((GroupVariables) variables).clone(clone); + 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) { + public Group clone(WorldDataHolder dataSource) + { - if (dataSource.groupExists(this.getName())) { + if (dataSource.groupExists(this.getName())) + { return null; } Group clone = dataSource.createGroup(this.getName()); // Don't add inheritance for GlobalGroups - if (!isGlobal()) { + if (!isGlobal()) + { clone.inherits = new ArrayList(this.getInherits()); } - for (String perm : this.getPermissionList()) { + for (String perm : this.getPermissionList()) + { clone.addPermission(perm); } clone.variables = variables.clone(clone); @@ -113,13 +124,13 @@ public class Group extends DataUnit implements Cloneable { } /** - * an unmodifiable list of inherits list - * You can't manage the list by here - * Lol... version 0.6 had a problem because this. - * + * 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() { + public List getInherits() + { return Collections.unmodifiableList(inherits); } @@ -127,27 +138,35 @@ public class Group extends DataUnit implements Cloneable { /** * @param inherit the inherits to set */ - public void addInherits(Group inherit) { + public void addInherits(Group inherit) + { - if (!isGlobal()) { - if (!this.getDataSource().groupExists(inherit.getName())) { + if (!isGlobal()) + { + if (!this.getDataSource().groupExists(inherit.getName())) + { getDataSource().addGroup(inherit); } - if (!inherits.contains(inherit.getName().toLowerCase())) { + if (!inherits.contains(inherit.getName().toLowerCase())) + { inherits.add(inherit.getName().toLowerCase()); } flagAsChanged(); - if (GroupManager.isLoaded()) { + if (GroupManager.isLoaded()) + { GroupManager.BukkitPermissions.updateAllPlayers(); GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); } } } - public boolean removeInherits(String inherit) { + public boolean removeInherits(String inherit) + { - if (!isGlobal()) { - if (this.inherits.contains(inherit.toLowerCase())) { + if (!isGlobal()) + { + if (this.inherits.contains(inherit.toLowerCase())) + { this.inherits.remove(inherit.toLowerCase()); flagAsChanged(); GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); @@ -160,25 +179,30 @@ public class Group extends DataUnit implements Cloneable { /** * @return the variables */ - public GroupVariables getVariables() { + public GroupVariables getVariables() + { return variables; } /** - * + * * @param varList */ - public void setVariables(Map varList) { + public void setVariables(Map varList) + { - if (!isGlobal()) { + if (!isGlobal()) + { GroupVariables temp = new GroupVariables(this, varList); variables.clearVars(); - for (String key : temp.getVarKeyList()) { + for (String key : temp.getVarKeyList()) + { variables.addVar(key, temp.getVarObject(key)); } flagAsChanged(); - if (GroupManager.isLoaded()) { + 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 e08d1db7d..e77b3af2c 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/GroupVariables.java @@ -6,15 +6,17 @@ package org.anjocaido.groupmanager.data; import java.util.Map; + /** - * + * * @author gabrielcouto */ -public class GroupVariables extends Variables implements Cloneable { - +public class GroupVariables extends Variables implements Cloneable +{ private Group owner; - public GroupVariables(Group owner) { + public GroupVariables(Group owner) + { super(owner); this.owner = owner; @@ -23,23 +25,27 @@ public class GroupVariables extends Variables implements Cloneable { addVar("build", false); } - public GroupVariables(Group owner, Map varList) { + public GroupVariables(Group owner, Map varList) + { super(owner); variables = varList; - if (variables.get("prefix") == null) { + if (variables.get("prefix") == null) + { variables.put("prefix", ""); owner.flagAsChanged(); } //thisGrp.prefix = infoNode.get("prefix").toString(); - if (variables.get("suffix") == null) { + if (variables.get("suffix") == null) + { variables.put("suffix", ""); owner.flagAsChanged(); } //thisGrp.suffix = infoNode.get("suffix").toString(); - if (variables.get("build") == null) { + if (variables.get("build") == null) + { variables.put("build", false); owner.flagAsChanged(); } @@ -48,13 +54,15 @@ public class GroupVariables extends Variables implements Cloneable { /** * A clone of all vars here. - * + * * @return GroupVariables clone */ - protected GroupVariables clone(Group newOwner) { + protected GroupVariables clone(Group newOwner) + { GroupVariables clone = new GroupVariables(newOwner); - for (String key : variables.keySet()) { + for (String key : variables.keySet()) + { clone.variables.put(key, variables.get(key)); } newOwner.flagAsChanged(); @@ -63,21 +71,30 @@ public class GroupVariables extends Variables implements Cloneable { /** * Remove a var from the list - * + * * @param name */ @Override - public void removeVar(String name) { + public void removeVar(String name) + { - try { + try + { this.variables.remove(name); - } catch (Exception e) { } - if (name.equals("prefix")) { + catch (Exception e) + { + } + if (name.equals("prefix")) + { addVar("prefix", ""); - } else if (name.equals("suffix")) { + } + else if (name.equals("suffix")) + { addVar("suffix", ""); - } else if (name.equals("build")) { + } + else if (name.equals("build")) + { addVar("build", false); } owner.flagAsChanged(); @@ -87,7 +104,8 @@ public class GroupVariables extends Variables implements Cloneable { * @return the owner */ @Override - public Group getOwner() { + 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 6c74c2e50..128e5a7b1 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java @@ -16,44 +16,47 @@ import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.entity.Player; + /** - * + * * @author gabrielcouto/ElgarL */ -public class User extends DataUnit implements Cloneable { - +public class User extends DataUnit implements Cloneable +{ /** - * - */ + * + */ private String group = null; private ArrayList subGroups = new ArrayList(); /** - * This one holds the fields in INFO node. like prefix = 'c' or build = - * false + * This one holds the fields in INFO node. like prefix = 'c' or build = false */ private UserVariables variables = new UserVariables(this); - private transient Player bukkitPlayer = null; + private Player bukkitPlayer = null; /** - * + * * @param name */ - public User(WorldDataHolder source, String name) { + public User(WorldDataHolder source, String name) + { super(source, name); this.group = source.getDefaultGroup().getName(); } /** - * + * * @return User clone */ @Override - public User clone() { + public User clone() + { User clone = new User(getDataSource(), this.getName()); clone.group = this.group; - for (String perm : this.getPermissionList()) { + for (String perm : this.getPermissionList()) + { clone.addPermission(perm); } // clone.variables = this.variables.clone(); @@ -63,22 +66,28 @@ public class User extends DataUnit implements Cloneable { /** * Use this to deliver a user from one WorldDataHolder to another - * + * * @param dataSource * @return null if given dataSource already contains the same user */ - public User clone(WorldDataHolder dataSource) { + public User clone(WorldDataHolder dataSource) + { - if (dataSource.isUserDeclared(this.getName())) { + if (dataSource.isUserDeclared(this.getName())) + { return null; } User clone = dataSource.createUser(this.getName()); - if (dataSource.getGroup(group) == null) { + if (dataSource.getGroup(group) == null) + { clone.setGroup(dataSource.getDefaultGroup()); - } else { + } + else + { clone.setGroup(dataSource.getGroup(this.getGroupName())); } - for (String perm : this.getPermissionList()) { + for (String perm : this.getPermissionList()) + { clone.addPermission(perm); } clone.variables = this.variables.clone(this); @@ -86,10 +95,12 @@ public class User extends DataUnit implements Cloneable { return clone; } - public Group getGroup() { + public Group getGroup() + { Group result = getDataSource().getGroup(group); - if (result == null) { + if (result == null) + { this.setGroup(getDataSource().getDefaultGroup()); result = getDataSource().getDefaultGroup(); } @@ -99,21 +110,22 @@ public class User extends DataUnit implements Cloneable { /** * @return the group */ - public String getGroupName() { + public String getGroupName() + { Group result = getDataSource().getGroup(group); - if (result == null) { + if (result == null) + { group = getDataSource().getDefaultGroup().getName(); } return group; } - /** - * @param group - * the group to set + * @param group the group to set */ - public void setGroup(Group group) { + public void setGroup(Group group) + { setGroup(group, true); } @@ -121,20 +133,25 @@ public class User extends DataUnit implements Cloneable { /** * @param group the group to set * @param updatePerms if we are to trigger a superperms update. - * + * */ - public void setGroup(Group group, Boolean updatePerms) { + public void setGroup(Group group, Boolean updatePerms) + { - if (!this.getDataSource().groupExists(group.getName())) { + if (!this.getDataSource().groupExists(group.getName())) + { getDataSource().addGroup(group); } group = getDataSource().getGroup(group.getName()); String oldGroup = this.group; this.group = group.getName(); flagAsChanged(); - if (GroupManager.isLoaded()) { + if (GroupManager.isLoaded()) + { if (!GroupManager.BukkitPermissions.isPlayer_join() && (updatePerms)) + { GroupManager.BukkitPermissions.updatePlayer(getBukkitPlayer()); + } // Do we notify of the group change? String defaultGroupName = getDataSource().getDefaultGroup().getName(); @@ -144,32 +161,42 @@ public class User extends DataUnit implements Cloneable { boolean notify = (!oldGroup.equalsIgnoreCase(defaultGroupName)) || ((oldGroup.equalsIgnoreCase(defaultGroupName)) && (!this.group.equalsIgnoreCase(defaultGroupName))); 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) { + 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())) { + if (this.group.equalsIgnoreCase(subGroup.getName())) + { return false; } // User already has this subgroup if (containsSubGroup(subGroup)) + { return false; + } // If the group doesn't exists add it - if (!this.getDataSource().groupExists(subGroup.getName())) { + if (!this.getDataSource().groupExists(subGroup.getName())) + { getDataSource().addGroup(subGroup); } subGroups.add(subGroup.getName()); flagAsChanged(); - if (GroupManager.isLoaded()) { + if (GroupManager.isLoaded()) + { if (!GroupManager.BukkitPermissions.isPlayer_join()) + { GroupManager.BukkitPermissions.updatePlayer(getBukkitPlayer()); + } GroupManagerEventHandler.callEvent(this, Action.USER_SUBGROUP_CHANGED); } return true; @@ -179,43 +206,58 @@ public class User extends DataUnit implements Cloneable { //subGroups.add(subGroup.getName()); } - public int subGroupsSize() { + public int subGroupsSize() + { return subGroups.size(); } - public boolean isSubGroupsEmpty() { + public boolean isSubGroupsEmpty() + { return subGroups.isEmpty(); } - public boolean containsSubGroup(Group subGroup) { + public boolean containsSubGroup(Group subGroup) + { return subGroups.contains(subGroup.getName()); } - public boolean removeSubGroup(Group subGroup) { + public boolean removeSubGroup(Group subGroup) + { - try { - if (subGroups.remove(subGroup.getName())) { + try + { + if (subGroups.remove(subGroup.getName())) + { flagAsChanged(); if (GroupManager.isLoaded()) + { if (!GroupManager.BukkitPermissions.isPlayer_join()) + { GroupManager.BukkitPermissions.updatePlayer(getBukkitPlayer()); + } + } GroupManagerEventHandler.callEvent(this, Action.USER_SUBGROUP_CHANGED); return true; } - } catch (Exception e) { + } + catch (Exception e) + { } return false; } - public ArrayList subGroupListCopy() { + public ArrayList subGroupListCopy() + { ArrayList val = new ArrayList(); - for (String gstr : subGroups) { + for (String gstr : subGroups) + { Group g = getDataSource().getGroup(gstr); - if (g == null) { + if (g == null) + { removeSubGroup(g); continue; } @@ -224,7 +266,8 @@ public class User extends DataUnit implements Cloneable { return val; } - public ArrayList subGroupListStringCopy() { + public ArrayList subGroupListStringCopy() + { return new ArrayList(subGroups); } @@ -232,40 +275,46 @@ public class User extends DataUnit implements Cloneable { /** * @return the variables */ - public UserVariables getVariables() { + public UserVariables getVariables() + { return variables; } /** - * + * * @param varList */ - public void setVariables(Map varList) { + public void setVariables(Map varList) + { //UserVariables temp = new UserVariables(this, varList); variables.clearVars(); - for (String key : varList.keySet()) { + for (String key : varList.keySet()) + { variables.addVar(key, varList.get(key)); } flagAsChanged(); - if (GroupManager.isLoaded()) { + if (GroupManager.isLoaded()) + { //if (!GroupManager.BukkitPermissions.isPlayer_join()) // GroupManager.BukkitPermissions.updatePlayer(this.getName()); GroupManagerEventHandler.callEvent(this, Action.USER_INFO_CHANGED); } } - - public User updatePlayer(Player player) { + public User updatePlayer(Player player) + { bukkitPlayer = player; return this; } - public Player getBukkitPlayer() { + public Player getBukkitPlayer() + { - if (bukkitPlayer == null) { + if (bukkitPlayer == null) + { bukkitPlayer = Bukkit.getPlayer(this.getName()); } return bukkitPlayer; diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java index f994595c1..36c7e7e1a 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/UserVariables.java @@ -6,21 +6,24 @@ package org.anjocaido.groupmanager.data; import java.util.Map; + /** - * + * * @author gabrielcouto */ -public class UserVariables extends Variables { - +public class UserVariables extends Variables +{ private User owner; - public UserVariables(User owner) { + public UserVariables(User owner) + { super(owner); this.owner = owner; } - public UserVariables(User owner, Map varList) { + public UserVariables(User owner, Map varList) + { super(owner); this.variables = varList; @@ -29,13 +32,15 @@ public class UserVariables extends Variables { /** * A clone of all vars here. - * + * * @return UserVariables clone */ - protected UserVariables clone(User newOwner) { + protected UserVariables clone(User newOwner) + { UserVariables clone = new UserVariables(newOwner); - for (String key : variables.keySet()) { + for (String key : variables.keySet()) + { clone.variables.put(key, variables.get(key)); } newOwner.flagAsChanged(); @@ -46,7 +51,8 @@ public class UserVariables extends Variables { * @return the owner */ @Override - public User getOwner() { + 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 42ceba7e4..06e309008 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java @@ -8,41 +8,39 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; + /** - * A class that holds variables of a user/group. - * In groups, it holds the contents of INFO node. - * Like: - * prefix - * suffix + * 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 { - +public abstract class Variables implements Cloneable +{ private DataUnit owner; protected Map variables = new HashMap(); - public Variables(DataUnit owner) { + public Variables(DataUnit owner) + { this.owner = owner; } /** - * Add var to the the INFO node. - * examples: - * addVar("build",true); - * addVar("prefix","c"); - * + * 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) { + public void addVar(String name, Object o) + { - if (o == null) { + if (o == null) + { return; } - if (variables.containsKey(name)) { + if (variables.containsKey(name)) + { variables.remove(name); } variables.put(name, o); @@ -51,143 +49,178 @@ public abstract class Variables implements Cloneable { /** * Returns the object inside the var - * + * * @param name * @return a Object if exists. null if doesn't exists */ - public Object getVarObject(String name) { + 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) { + public String getVarString(String name) + { Object o = variables.get(name); - try { + try + { return o == null ? "" : o.toString(); - } catch (Exception e) { + } + catch (Exception e) + { return ""; } } /** - * + * * @param name * @return false if null. or a Boolean.parseBoolean of the string */ - public Boolean getVarBoolean(String name) { + public Boolean getVarBoolean(String name) + { Object o = variables.get(name); - try { + try + { return o == null ? false : Boolean.parseBoolean(o.toString()); - } catch (Exception e) { + } + catch (Exception e) + { return false; } } /** - * + * * @param name * @return -1 if null. or a parseInt of the string */ - public Integer getVarInteger(String name) { + public Integer getVarInteger(String name) + { Object o = variables.get(name); - try { + try + { return o == null ? -1 : Integer.parseInt(o.toString()); - } catch (Exception e) { + } + catch (Exception e) + { return -1; } } /** - * + * * @param name * @return -1 if null. or a parseDouble of the string */ - public Double getVarDouble(String name) { + public Double getVarDouble(String name) + { Object o = variables.get(name); - try { + try + { return o == null ? -1.0D : Double.parseDouble(o.toString()); - } catch (Exception e) { + } + catch (Exception e) + { return -1.0D; } } /** * All variable keys this is holding - * + * * @return Set of all variable names. */ - public Set getVarKeyList() { + 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) { + 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() { + public int getSize() + { return variables.size(); } /** * Remove a var from the list - * + * * @param name */ - public void removeVar(String name) { + public void removeVar(String name) + { - try { + try + { variables.remove(name); - } catch (Exception e) { + } + catch (Exception e) + { } owner.flagAsChanged(); } - public static Object parseVariableValue(String value) { + public static Object parseVariableValue(String value) + { - try { + try + { Integer i = Integer.parseInt(value); return i; - } catch (NumberFormatException e) { } - try { + catch (NumberFormatException e) + { + } + try + { Double d = Double.parseDouble(value); return d; - } catch (NumberFormatException e) { } - if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("on")) { + 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")) { + } + else if (value.equalsIgnoreCase("false") || value.equalsIgnoreCase("no") || value.equalsIgnoreCase("off")) + { return false; } return value; } - public void clearVars() { + public void clearVars() + { variables.clear(); owner.flagAsChanged(); @@ -196,12 +229,14 @@ public abstract class Variables implements Cloneable { /** * @return the owner */ - public DataUnit getOwner() { + public DataUnit getOwner() + { return owner; } - public boolean isEmpty() { + public boolean isEmpty() + { return variables.isEmpty(); } -- cgit v1.2.3