src/java.scripting/share/classes/javax/script/SimpleBindings.java
author mbaesken
Thu, 17 May 2018 18:09:19 +0200
changeset 50231 10b14c9ee78d
parent 47216 71c04702a3d5
permissions -rw-r--r--
8203355: MITSHM define guarding missing Reviewed-by: prr, stuefe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.script;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * A simple implementation of Bindings backed by
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    35
 * a {@code HashMap} or some other specified {@code Map}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author Mike Grogan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class SimpleBindings implements Bindings {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /**
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    43
     * The {@code Map} field stores the attributes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private Map<String,Object> map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    48
     * Constructor uses an existing {@code Map} to store the values.
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    49
     * @param m The {@code Map} backing this {@code SimpleBindings}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * @throws NullPointerException if m is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public SimpleBindings(Map<String,Object> m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        if (m == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        this.map = m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    60
     * Default constructor uses a {@code HashMap}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public SimpleBindings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        this(new HashMap<String,Object>());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    67
     * Sets the specified key/value in the underlying {@code map} field.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @param name Name of value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param value Value to set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @return Previous value for the specified key.  Returns null if key was previously
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * unset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @throws NullPointerException if the name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @throws IllegalArgumentException if the name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public Object put(String name, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        checkKey(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return map.put(name,value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    84
     * {@code putAll} is implemented using {@code Map.putAll}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    86
     * @param toMerge The {@code Map} of values to add.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @throws NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *         if toMerge map is null or if some key in the map is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *         if some key in the map is an empty String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public void putAll(Map<? extends String, ? extends Object> toMerge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (toMerge == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            throw new NullPointerException("toMerge map is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        for (Map.Entry<? extends String, ? extends Object> entry : toMerge.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            String key = entry.getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            checkKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            put(key, entry.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /** {@inheritDoc} */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        map.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   110
     * Returns {@code true} if this map contains a mapping for the specified
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   111
     * key.  More formally, returns {@code true} if and only if
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   112
     * this map contains a mapping for a key {@code k} such that
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   113
     * {@code (key==null ? k==null : key.equals(k))}.  (There can be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * at most one such mapping.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param key key whose presence in this map is to be tested.
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   117
     * @return {@code true} if this map contains a mapping for the specified
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *         key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @throws NullPointerException if key is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @throws ClassCastException if key is not String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @throws IllegalArgumentException if key is empty String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public boolean containsKey(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        checkKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return map.containsKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /** {@inheritDoc} */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public boolean containsValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return map.containsValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /** {@inheritDoc} */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public Set<Map.Entry<String, Object>> entrySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return map.entrySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Returns the value to which this map maps the specified key.  Returns
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   141
     * {@code null} if the map contains no mapping for this key.  A return
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   142
     * value of {@code null} does not <i>necessarily</i> indicate that the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * map contains no mapping for the key; it's also possible that the map
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   144
     * explicitly maps the key to {@code null}.  The {@code containsKey}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * operation may be used to distinguish these two cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * <p>More formally, if this map contains a mapping from a key
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   148
     * {@code k} to a value {@code v} such that
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   149
     * {@code (key==null ? k==null : key.equals(k))},
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   150
     * then this method returns {@code v}; otherwise
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   151
     * it returns {@code null}.  (There can be at most one such mapping.)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @param key key whose associated value is to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @return the value to which this map maps the specified key, or
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   155
     *         {@code null} if the map contains no mapping for this key.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @throws NullPointerException if key is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @throws ClassCastException if key is not String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @throws IllegalArgumentException if key is empty String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public Object get(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        checkKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return map.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /** {@inheritDoc} */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return map.isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /** {@inheritDoc} */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public Set<String> keySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return map.keySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Removes the mapping for this key from this map if it is present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * (optional operation).   More formally, if this map contains a mapping
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   179
     * from key {@code k} to value {@code v} such that
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   180
     * {@code (key==null ?  k==null : key.equals(k))}, that mapping
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * is removed.  (The map can contain at most one such mapping.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * <p>Returns the value to which the map previously associated the key, or
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   184
     * {@code null} if the map contained no mapping for this key.  (A
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   185
     * {@code null} return can also indicate that the map previously
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   186
     * associated {@code null} with the specified key if the implementation
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   187
     * supports {@code null} values.)  The map will not contain a mapping for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * the specified  key once the call returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param key key whose mapping is to be removed from the map.
32769
c9520bbd6754 8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   191
     * @return previous value associated with specified key, or {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *         if there was no mapping for key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @throws NullPointerException if key is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @throws ClassCastException if key is not String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @throws IllegalArgumentException if key is empty String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public Object remove(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        checkKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return map.remove(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /** {@inheritDoc} */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return map.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /** {@inheritDoc} */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public Collection<Object> values() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return map.values();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    private void checkKey(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (key == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            throw new NullPointerException("key can not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (!(key instanceof String)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            throw new ClassCastException("key should be a String");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if (key.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            throw new IllegalArgumentException("key can not be empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
}