Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.65 KB | None | 0 0
  1. package matt.engine.rts;
  2.  
  3. public class Property
  4. {
  5.     public Property(String name) {
  6.         this.name = name;
  7.     }
  8.    
  9.     public Property(String name, Object value) {
  10.         this(name);
  11.         type = type_obj;
  12.         valueObj = value;
  13.     }
  14.    
  15.     public Property(String name, int value) {
  16.         this(name);
  17.         type = type_int;
  18.         valueInt = value;
  19.     }
  20.    
  21.     public Property(String name, float value) {
  22.         this(name);
  23.         type = type_float;
  24.         valueFloat = value;
  25.     }
  26.    
  27.     public Property(String name, boolean value) {
  28.         this(name);
  29.         type = type_bool;
  30.         valueBool = value;
  31.     }
  32.    
  33.     public String getName() {
  34.         return name;
  35.     }
  36.    
  37.     public void set(Object value) {
  38.         checkType(type_obj);
  39.         this.valueObj = value;
  40.     }
  41.    
  42.     public void set(int value) {
  43.         checkType(type_int);
  44.         this.valueInt = value;
  45.     }
  46.    
  47.     public void set(float value) {
  48.         checkType(type_float);
  49.         this.valueFloat = value;
  50.     }
  51.    
  52.     public void set(boolean value) {
  53.         checkType(type_bool);
  54.         this.valueBool = value;
  55.     }
  56.    
  57.     public Object getObj() {
  58.         checkType(type_obj);
  59.         return valueObj;
  60.     }
  61.    
  62.     public int getInt() {
  63.         checkType(type_int);
  64.         return valueInt;
  65.     }
  66.    
  67.     public float getFloat() {
  68.         checkType(type_float);
  69.         return valueFloat;
  70.     }
  71.    
  72.     public boolean getBool() {
  73.         checkType(type_bool);
  74.         return valueBool;
  75.     }
  76.    
  77.     private final void checkType(int type) {
  78.         if (this.type != type)
  79.             throw new IllegalStateException();
  80.     }
  81.    
  82.     private final String name;
  83.    
  84.     private Object  valueObj;
  85.     private int     valueInt;
  86.     private float   valueFloat;
  87.     private boolean valueBool;
  88.    
  89.     private int     type;
  90.    
  91.     private static final int type_obj = 0,
  92.                              type_int = 1,
  93.                              type_float = 2,
  94.                              type_bool = 3;
  95.    
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement