summaryrefslogtreecommitdiffstats
path: root/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java')
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Variables.java145
1 files changed, 90 insertions, 55 deletions
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<String, Object> variables = new HashMap<String, Object>();
- 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<String> getVarKeyList() {
+ public Set<String> 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();
}