SimpleBindings.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Decompiled with CFR 0.152.
  3. */
  4. package com.script;
  5. import java.util.Collection;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8. import java.util.Set;
  9. public class SimpleBindings implements Bindings {
  10. private Map<String, Object> map;
  11. public SimpleBindings(Map<String, Object> m) {
  12. if (m == null) {
  13. throw new NullPointerException();
  14. }
  15. this.map = m;
  16. }
  17. public SimpleBindings() {
  18. this(new HashMap<String, Object>());
  19. }
  20. @Override
  21. public Object put(String name, Object value) {
  22. this.checkKey(name);
  23. return this.map.put(name, value);
  24. }
  25. @Override
  26. public void putAll(Map<? extends String, ? extends Object> toMerge) {
  27. if (toMerge == null) {
  28. throw new NullPointerException("toMerge map is null");
  29. }
  30. for (Map.Entry<? extends String, ? extends Object> entry : toMerge.entrySet()) {
  31. String key = entry.getKey();
  32. this.checkKey(key);
  33. this.put(key, entry.getValue());
  34. }
  35. }
  36. @Override
  37. public void clear() {
  38. this.map.clear();
  39. }
  40. @Override
  41. public boolean containsKey(Object key) {
  42. this.checkKey(key);
  43. return this.map.containsKey(key);
  44. }
  45. @Override
  46. public boolean containsValue(Object value) {
  47. return this.map.containsValue(value);
  48. }
  49. @Override
  50. public Set<Map.Entry<String, Object>> entrySet() {
  51. return this.map.entrySet();
  52. }
  53. @Override
  54. public Object get(Object key) {
  55. this.checkKey(key);
  56. return this.map.get(key);
  57. }
  58. @Override
  59. public boolean isEmpty() {
  60. return this.map.isEmpty();
  61. }
  62. @Override
  63. public Set<String> keySet() {
  64. return this.map.keySet();
  65. }
  66. @Override
  67. public Object remove(Object key) {
  68. this.checkKey(key);
  69. return this.map.remove(key);
  70. }
  71. @Override
  72. public int size() {
  73. return this.map.size();
  74. }
  75. @Override
  76. public Collection<Object> values() {
  77. return this.map.values();
  78. }
  79. private void checkKey(Object key) {
  80. if (key == null) {
  81. throw new NullPointerException("key can not be null");
  82. }
  83. if (!(key instanceof String)) {
  84. throw new ClassCastException("key should be a String");
  85. }
  86. if (key.equals("")) {
  87. throw new IllegalArgumentException("key can not be empty");
  88. }
  89. }
  90. }