001    package com.thaiopensource.util;
002    
003    public class SinglePropertyMap implements PropertyMap {
004      private final PropertyId pid;
005      private final Object value;
006    
007      public SinglePropertyMap(PropertyId pid, Object value) {
008        if (!(pid.getValueClass().isInstance(value))) {
009          if (value == null)
010            throw new NullPointerException();
011          throw new ClassCastException();
012        }
013        this.pid = pid;
014        this.value = value;
015      }
016    
017      public Object get(PropertyId pid) {
018        if (pid != this.pid)
019          return null;
020        return value;
021      }
022    
023      public boolean contains(PropertyId pid) {
024        return pid == this.pid;
025      }
026    
027      public int size() {
028        return 1;
029      }
030    
031      public PropertyId getKey(int i) {
032        if (i != 0)
033          throw new IndexOutOfBoundsException();
034        return pid;
035      }
036    }