| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /*
- * Decompiled with CFR 0.152.
- */
- package com.script;
- import java.util.Collection;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Set;
- public class SimpleBindings implements Bindings {
- private Map<String, Object> map;
- public SimpleBindings(Map<String, Object> m) {
- if (m == null) {
- throw new NullPointerException();
- }
- this.map = m;
- }
- public SimpleBindings() {
- this(new HashMap<String, Object>());
- }
- @Override
- public Object put(String name, Object value) {
- this.checkKey(name);
- return this.map.put(name, value);
- }
- @Override
- public void putAll(Map<? extends String, ? extends Object> toMerge) {
- if (toMerge == null) {
- throw new NullPointerException("toMerge map is null");
- }
- for (Map.Entry<? extends String, ? extends Object> entry : toMerge.entrySet()) {
- String key = entry.getKey();
- this.checkKey(key);
- this.put(key, entry.getValue());
- }
- }
- @Override
- public void clear() {
- this.map.clear();
- }
- @Override
- public boolean containsKey(Object key) {
- this.checkKey(key);
- return this.map.containsKey(key);
- }
- @Override
- public boolean containsValue(Object value) {
- return this.map.containsValue(value);
- }
- @Override
- public Set<Map.Entry<String, Object>> entrySet() {
- return this.map.entrySet();
- }
- @Override
- public Object get(Object key) {
- this.checkKey(key);
- return this.map.get(key);
- }
- @Override
- public boolean isEmpty() {
- return this.map.isEmpty();
- }
- @Override
- public Set<String> keySet() {
- return this.map.keySet();
- }
- @Override
- public Object remove(Object key) {
- this.checkKey(key);
- return this.map.remove(key);
- }
- @Override
- public int size() {
- return this.map.size();
- }
- @Override
- public Collection<Object> values() {
- return this.map.values();
- }
- private void checkKey(Object key) {
- if (key == null) {
- throw new NullPointerException("key can not be null");
- }
- if (!(key instanceof String)) {
- throw new ClassCastException("key should be a String");
- }
- if (key.equals("")) {
- throw new IllegalArgumentException("key can not be empty");
- }
- }
- }
|