1 package com.thaiopensource.util; 2 3 public class SinglePropertyMap implements PropertyMap { 4 private final PropertyId pid; 5 private final Object value; 6 7 public SinglePropertyMap(PropertyId pid, Object value) { 8 if (!(pid.getValueClass().isInstance(value))) { 9 if (value == null) 10 throw new NullPointerException (); 11 throw new ClassCastException (); 12 } 13 this.pid = pid; 14 this.value = value; 15 } 16 17 public Object get(PropertyId pid) { 18 if (pid != this.pid) 19 return null; 20 return value; 21 } 22 23 public boolean contains(PropertyId pid) { 24 return pid == this.pid; 25 } 26 27 public int size() { 28 return 1; 29 } 30 31 public PropertyId getKey(int i) { 32 if (i != 0) 33 throw new IndexOutOfBoundsException (); 34 return pid; 35 } 36 } 37 | Popular Tags |