aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/cycling74/max/AtomString.java
blob: c4135afe991e88a6514b7428d34e538298ee1fc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.cycling74.max;

class AtomString extends Atom {
    private static final long serialVersionUID = 1738861344247036680L;
    private String value;
	
	AtomString(String value) {
		super(DataTypes.MESSAGE);
		this.value = value;
	}
	
	public int compareTo(Object obj) {
		if ( obj instanceof AtomString ) {
			AtomString s = (AtomString) obj;
			return s.getString().compareTo(getString());
		}
		if ( obj instanceof AtomFloat ) {
			return -1;
		}
		throw new ClassCastException();
	}
	
	public boolean isString() {
		return true;
	}
	
	public Object toObject() {
		return value;
	}
	
	public byte toByte() {
		return (byte) value.charAt(0);
	}
	
	public char toChar() {
		return value.charAt(0);
	}
	
	public String toString() {
		return value;
	}
	
	public boolean toBoolean() {
		return !value.equals("false");
	}
	
	public String getString() {
		return value;
	}
	
	public boolean equals(Object comp) {
	    if ( !(comp instanceof AtomString) ) {
	        return false;
	    }
	    AtomString test = (AtomString) comp;
	    
	    return test.value.equals(value);
	}
	
	public int hashCode() {
	    return value.hashCode();
	}
}