Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package matt.engine.rts;
- public class Property
- {
- public Property(String name) {
- this.name = name;
- }
- public Property(String name, Object value) {
- this(name);
- type = type_obj;
- valueObj = value;
- }
- public Property(String name, int value) {
- this(name);
- type = type_int;
- valueInt = value;
- }
- public Property(String name, float value) {
- this(name);
- type = type_float;
- valueFloat = value;
- }
- public Property(String name, boolean value) {
- this(name);
- type = type_bool;
- valueBool = value;
- }
- public String getName() {
- return name;
- }
- public void set(Object value) {
- checkType(type_obj);
- this.valueObj = value;
- }
- public void set(int value) {
- checkType(type_int);
- this.valueInt = value;
- }
- public void set(float value) {
- checkType(type_float);
- this.valueFloat = value;
- }
- public void set(boolean value) {
- checkType(type_bool);
- this.valueBool = value;
- }
- public Object getObj() {
- checkType(type_obj);
- return valueObj;
- }
- public int getInt() {
- checkType(type_int);
- return valueInt;
- }
- public float getFloat() {
- checkType(type_float);
- return valueFloat;
- }
- public boolean getBool() {
- checkType(type_bool);
- return valueBool;
- }
- private final void checkType(int type) {
- if (this.type != type)
- throw new IllegalStateException();
- }
- private final String name;
- private Object valueObj;
- private int valueInt;
- private float valueFloat;
- private boolean valueBool;
- private int type;
- private static final int type_obj = 0,
- type_int = 1,
- type_float = 2,
- type_bool = 3;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement