All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.thaiopensource.util.SinglePropertyMap Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 1.11
Show newest version
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);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy