Posts tagged ‘FIRE/J’

Hacking and slashing in FIRE/J’s code. Before:

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
public enum ParserPlugin {
    FIRE("org.firej.dfa.fire.ParserFire"),
    AUTOMATON("org.firej.dfa.automaton.ParserAutomaton");
 
    private static Parser current;
 
    static {
	current = new ParserAutomaton();
    }
 
    private String classpath;
 
    private ParserPlugin(String cl) {
	this.classpath = cl;
    }
 
    public boolean load() {
	try {
	    ClassLoader classloader = ClassLoader.getSystemClassLoader();
	    Class clazz = classloader.loadClass(classpath);
	    current = (Parser) clazz.newInstance();
	    return true;
	} catch (Exception e) {	    
	    return false;
	}
    }
}

and after …

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public enum ParserPlugin {
    FIRE,
    AUTOMATON;
 
    private static Parser current;
 
    static {
	current = new ParserAutomaton();
    }
 
    public boolean load() {
        switch(this) {
            case FIRE:
                current = new ParserFire();
                return true;
            case AUTOMATON:
                current = new ParserAutomaton();
                return true;
            default:
                return false;
        }
    }
}
VN:F [1.9.17_1161]
Rating: 9.0/10 (1 vote cast)
VN:F [1.9.17_1161]
Rating: 0 (from 0 votes)