map) {
delegatedMap = new LinkedHashMap<>(map);
unmodifiableDelegatedMap = Collections.unmodifiableMap(delegatedMap);
}
/**
* The current lock state of this parameter map.
*/
private boolean locked = false;
/**
* @return the locked state of this parameter map.
*/
public boolean isLocked() {
return locked;
}
/**
* Set the locked state of this parameter map.
*
* @param locked The new locked state
*/
public void setLocked(boolean locked) {
this.locked = locked;
}
/**
* The string manager for this package.
*/
private static final StringManager sm = StringManager.getManager("org.apache.catalina.util");
/**
* {@inheritDoc}
*
* @exception IllegalStateException if this map is currently locked
*/
@Override
public void clear() {
checkLocked();
delegatedMap.clear();
}
/**
* {@inheritDoc}
*
* @exception IllegalStateException if this map is currently locked
*/
@Override
public V put(K key, V value) {
checkLocked();
return delegatedMap.put(key, value);
}
/**
* {@inheritDoc}
*
* @exception IllegalStateException if this map is currently locked
*/
@Override
public void putAll(Map extends K,? extends V> map) {
checkLocked();
delegatedMap.putAll(map);
}
/**
* {@inheritDoc}
*
* @exception IllegalStateException if this map is currently locked
*/
@Override
public V remove(Object key) {
checkLocked();
return delegatedMap.remove(key);
}
private void checkLocked() {
if (locked) {
throw new IllegalStateException(sm.getString("parameterMap.locked"));
}
}
@Override
public int size() {
return delegatedMap.size();
}
@Override
public boolean isEmpty() {
return delegatedMap.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return delegatedMap.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
return delegatedMap.containsValue(value);
}
@Override
public V get(Object key) {
return delegatedMap.get(key);
}
/**
* {@inheritDoc}
*
* Returns an unmodifiable {@link Set} view of the keys
* contained in this map if it is locked.
*/
@Override
public Set keySet() {
if (locked) {
return unmodifiableDelegatedMap.keySet();
}
return delegatedMap.keySet();
}
/**
* {@inheritDoc}
*
* Returns an unmodifiable {@link Collection} view of the
* values contained in this map if it is locked.
*/
@Override
public Collection values() {
if (locked) {
return unmodifiableDelegatedMap.values();
}
return delegatedMap.values();
}
/**
* {@inheritDoc}
*
* Returns an unmodifiable {@link Set} view of the mappings
* contained in this map if it is locked.
*/
@Override
public Set> entrySet() {
if (locked) {
return unmodifiableDelegatedMap.entrySet();
}
return delegatedMap.entrySet();
}
}