-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnector.java
More file actions
45 lines (36 loc) · 1.18 KB
/
Connector.java
File metadata and controls
45 lines (36 loc) · 1.18 KB
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
import java.util.HashMap;
import java.util.Map;
public class Connector extends AbstractListSymbol implements ListSymbol {
private final Type type;
private static Map<Type, String> connectorTypesAndSymbols = new HashMap<Type, String>() {{
put(Type.OR,"\u2228");
put(Type.AND,"\u2227");
put(Type.NOT,"\u00AC");
put(Type.OPEN,"(");
put(Type.CLOSE,")");
}};
private Connector(Type type) {
this.type = type;
}
//Only creates a new Connector object if it has a non-null and allowed value
public static final Connector build(Type type){
if(type == null)
throw new NullPointerException("Cannot build a Connector object with null String value");
if (! connectorTypesAndSymbols.containsKey(type))
throw new IllegalArgumentException("Connector must have Type value of OR, AND, NOT, OPEN, or CLOSE");
return new Connector(type);
}
//returns the Unicode representation of the object's type
@Override
public String toString(){
return connectorTypesAndSymbols.get(type);
}
@Override
public Type getType() {
return type;
}
@Override
public long complexity() {
return (type == Type.OR || type == Type.AND) ? 1 : 0;
}
}