org.apache.tiles.request.collection.AddableParameterMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tiles-request-api Show documentation
Show all versions of tiles-request-api Show documentation
API for the Tiles Request framework.
The newest version!
/*
* $Id: AddableParameterMap.java 1064782 2011-01-28 17:08:52Z apetrelli $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tiles.request.collection;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import org.apache.tiles.request.attribute.HasAddableKeys;
/**
* Exposes an {@link HasAddableKeys} object as a put/get (no remove) map.
*
* @version $Rev: 1064782 $ $Date: 2011-01-29 04:08:52 +1100 (Sat, 29 Jan 2011) $
*/
public class AddableParameterMap extends ReadOnlyEnumerationMap {
/**
* The request.
*/
private HasAddableKeys request;
/**
* Constructor.
*
* @param request The request object to use.
*/
public AddableParameterMap(HasAddableKeys request) {
super(request);
this.request = request;
}
/** {@inheritDoc} */
public Set> entrySet() {
return new AddableParameterEntrySet();
}
/** {@inheritDoc} */
public String put(String key, String value) {
String oldValue = request.getValue(key);
request.setValue(key, value);
return oldValue;
}
/** {@inheritDoc} */
public void putAll(Map extends String, ? extends String> map) {
for (Map.Entry extends String, ? extends String> entry : map
.entrySet()) {
request.setValue(entry.getKey(), entry.getValue());
}
}
/**
* Entry set implementation for {@link AddableParameterMap}.
*/
private class AddableParameterEntrySet extends ReadOnlyEnumerationMap.ReadOnlyEnumerationMapEntrySet {
@Override
public boolean add(java.util.Map.Entry e) {
request.setValue(e.getKey(), e.getValue());
return true;
}
@Override
public boolean addAll(
Collection extends java.util.Map.Entry> c) {
for (Map.Entry entry : c) {
request.setValue(entry.getKey(), entry.getValue());
}
return true;
}
}
}