com.thaiopensource.util.SinglePropertyMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trang Show documentation
Show all versions of trang Show documentation
Trang, a multi-format schema converter based on RELAX NG.
package com.thaiopensource.util;
public class SinglePropertyMap implements PropertyMap {
private final PropertyId pid;
private final T value;
private SinglePropertyMap(PropertyId pid, T value) {
if (!(pid.getValueClass().isInstance(value))) {
if (value == null)
throw new NullPointerException();
throw new ClassCastException();
}
this.pid = pid;
this.value = value;
}
public V get(PropertyId pid) {
if (pid != this.pid)
return null;
// it would be nice to avoid the cast,
// but I can't figure out how to do it
return pid.getValueClass().cast(value);
}
public boolean contains(PropertyId> pid) {
return pid == this.pid;
}
public int size() {
return 1;
}
public PropertyId> getKey(int i) {
if (i != 0)
throw new IndexOutOfBoundsException();
return pid;
}
public static SinglePropertyMap newInstance(PropertyId pid, T value) {
return new SinglePropertyMap(pid, value);
}
}