📄 directionvalue.java
字号:
public class DirectionValue extends Value {
private String value;
DirectionValue() {
value = "North";
}
DirectionValue(String s) {
value = s;
}
boolean isDirection() {
return true;
}
String directionValue() {
return value;
}
boolean isOfType(String typeName) {
return typeName.equals("direction");
}
int numberValue() {
if (value.equals("North"))
return direction.NORTH_VALUE;
else if (value.equals("East"))
return direction.EAST_VALUE;
else if (value.equals("South"))
return direction.SOUTH_VALUE;
else
return direction.WEST_VALUE;
// could check for "West", too and throw an exception if it's not "West"
// either
// but it schould be redundant
}
direction primitiveDirectionValue() {
if (value.equals("North"))
return direction.NORTH;
else if (value.equals("East"))
return direction.EAST;
else if (value.equals("South"))
return direction.SOUTH;
else
return direction.WEST;
}
public String toString() {
return value;
}
Value isEqual(Value v) throws InterpreterException {
if (!v.isDirection())
throw new InterpreterException(
"This type does not support equation.");
return new BooleanValue(value.equals(((DirectionValue) v)
.directionValue()));
}
Value assign(Value v) throws InterpreterException {
if (!v.isDirection())
throw new InterpreterException("wrong type.");
this.value = ((DirectionValue) v).directionValue();
return this;
}
Value cloneValue() {
return new DirectionValue(value);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -