summaryrefslogtreecommitdiffstats
path: root/EssentialsUpdate/src/f00f/net/irc/martyr/modes/GenericMode.java
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsUpdate/src/f00f/net/irc/martyr/modes/GenericMode.java')
-rw-r--r--EssentialsUpdate/src/f00f/net/irc/martyr/modes/GenericMode.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/EssentialsUpdate/src/f00f/net/irc/martyr/modes/GenericMode.java b/EssentialsUpdate/src/f00f/net/irc/martyr/modes/GenericMode.java
new file mode 100644
index 000000000..e1dad6045
--- /dev/null
+++ b/EssentialsUpdate/src/f00f/net/irc/martyr/modes/GenericMode.java
@@ -0,0 +1,77 @@
+package f00f.net.irc.martyr.modes;
+
+import f00f.net.irc.martyr.Mode;
+
+/**
+ * GenericNode uses the character to specify the hash code. Thus, two
+ * mode types are the same, in a hash table, even if they have
+ * different parameters or positive/negative values.
+ */
+public abstract class GenericMode implements Mode
+{
+ private String str;
+ private Mode.Sign sign = Mode.Sign.NOSIGN;
+
+ public void setParam( String str )
+ {
+ this.str = str;
+ }
+
+ public String getParam()
+ {
+ return str;
+ }
+
+ public void setSign( Mode.Sign sign )
+ {
+ this.sign = sign;
+ }
+
+ public Mode.Sign getSign()
+ {
+ return sign;
+ }
+
+ public String toString()
+ {
+ String pString = " ";
+ if( sign != Mode.Sign.NOSIGN )
+ pString += ( sign == Mode.Sign.POSITIVE ? "+" : "-" );
+ String className = this.getClass().getName();
+ className = className.substring( className.indexOf('$')+1 );
+
+ String result = className + pString + getChar();
+ if( requiresParam() )
+ {
+ result += " " + getParam();
+ }
+
+ return result;
+ }
+
+ public boolean equals( Object o )
+ {
+ if( o instanceof Mode )
+ {
+ Mode oMode = (Mode)o;
+
+ if( oMode.getParam() == null || this.getParam() == null )
+ return oMode.getChar() == this.getChar();
+
+ if( oMode.getParam() == null && this.getParam() != null )
+ return false;
+ if( oMode.getParam() == null && this.getParam() == null )
+ return oMode.getChar() == this.getChar();
+
+ return oMode.getChar() == this.getChar() &&
+ oMode.getParam().equals(this.getParam());
+ }
+ return false;
+ }
+
+ public int hashCode()
+ {
+ return (int)getChar();
+ }
+}
+