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 wicketstuff-jing Show documentation
Show all versions of wicketstuff-jing Show documentation
Jing is a validator for RELAX NG and other schema languages. This
project was taken from http://code.google.com/p/jing-trang and
mavenized for inclusion in the Wicket Stuff HTML Validator.
The code was taken from the 20091111 release.
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);
}
}