KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > util > SinglePropertyMap


1 package com.thaiopensource.util;
2
3 public class SinglePropertyMap implements PropertyMap {
4   private final PropertyId pid;
5   private final Object JavaDoc value;
6
7   public SinglePropertyMap(PropertyId pid, Object JavaDoc value) {
8     if (!(pid.getValueClass().isInstance(value))) {
9       if (value == null)
10         throw new NullPointerException JavaDoc();
11       throw new ClassCastException JavaDoc();
12     }
13     this.pid = pid;
14     this.value = value;
15   }
16
17   public Object JavaDoc 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 JavaDoc();
34     return pid;
35   }
36 }
37
Popular Tags