PropertyKey.java 839 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package gnu.mapping;
  2. /** PropertySet keys that provide statically-typeable values. */
  3. public class PropertyKey<T>
  4. {
  5. String name;
  6. public PropertyKey(String name)
  7. {
  8. this.name = name;
  9. }
  10. /** Get the value associated with this key in a given {@code PropertySet}.
  11. * Return {@code defaultValue} if there is no association for this key.
  12. */
  13. @SuppressWarnings("unchecked")
  14. public T get(PropertySet container, T defaultValue)
  15. {
  16. return (T) container.getProperty(this, defaultValue);
  17. }
  18. /** Get the value associated with this key in a given {@code PropertySet}.
  19. * Return null if there is no association for this key.
  20. */
  21. public final T get(PropertySet container)
  22. {
  23. return get(container, null);
  24. }
  25. public void set (PropertySet container, T value)
  26. {
  27. container.setProperty(this, value);
  28. }
  29. }