I am porting over some L-system classes from ActionScript to Processing (91) and am having some strange problems with string comparison.
Please forgive the slopiness of some of this code. It has all been written today.
So, I have an L-system class:
Code:
class Lsystem {
String axiom;
int rc, rm, renderindex, rint;
String[] sa;
RuleSet ruleset;
Engine eng;
Lsystem(String axiom) {
this.axiom = axiom;
this.rc = 0;
};
void registerRuleSet(RuleSet rs) {
this.ruleset = rs;
};
void registerEngine(Engine e) {
this.eng = e;
};
void recurse(int maxi) {
this.rm = maxi;
this.rc ++;
this.sa = this.axiom.split("");
String[] ta = new String[1000];
for (int n=1; n<this.sa.length; n++) {
String replace = this.ruleset.runRule(this.sa[n]);
ta[n] = replace;
};
//print(ta);
if (this.rc < this.rm) {
this.recurse(this.rm);
}
else {
this.rc = 0;
};
};
};
Which uses a RuleSet class to store sets of rules:
Code:
class RuleSet {
Rule[] rules;
int rulecount, test;
RuleSet() {
rulecount = 0;
Rule[] temp = new Rule[100];
rules = temp;
};
void init() {
};
void addRule(Rule r) {
rulecount ++;
rules[rulecount] = r;
};
String runRule(String rid) {
for (int i=1; i<rulecount; i++){
if (rules[i].id == rid) {
println ("*******RUN RULE" + rid);
};
};
return ("X");
};
};
Code:
class Rule {
String id;
String[] rules;
Rule(String name, String[] ruleset) {
id = name;
rules = ruleset;
};
};
The problem is here:
Code:
String runRule(String rid) {
for (int i=1; i<rulecount; i++){
if (rules[i].id == rid) {
println ("*******RUN RULE" + rid);
};
};
return ("X");
};
I am passing in an id value (ie. "X") and am looking through the array of rules for find a rule with the matching id property.
If I trace the two values out, I get this:
X:X
But, they are not satisfying the equality condition. If I convert them to char values first, I get this:
[C@c92535 : [C@a9c09e
Clearly these two values aren't equal... but for the life of me I can't figure out why.
Anyone have any idea why this might be?