| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AddableParameterMap |
|
| 1.3333333333333333;1.333 | ||||
| AddableParameterMap$1 |
|
| 1.3333333333333333;1.333 | ||||
| AddableParameterMap$AddableParameterEntrySet |
|
| 1.3333333333333333;1.333 |
| 1 | /* | |
| 2 | * $Id: AddableParameterMap.java 1064782 2011-01-28 17:08:52Z apetrelli $ | |
| 3 | * | |
| 4 | * Licensed to the Apache Software Foundation (ASF) under one | |
| 5 | * or more contributor license agreements. See the NOTICE file | |
| 6 | * distributed with this work for additional information | |
| 7 | * regarding copyright ownership. The ASF licenses this file | |
| 8 | * to you under the Apache License, Version 2.0 (the | |
| 9 | * "License"); you may not use this file except in compliance | |
| 10 | * with the License. You may obtain a copy of the License at | |
| 11 | * | |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 13 | * | |
| 14 | * Unless required by applicable law or agreed to in writing, | |
| 15 | * software distributed under the License is distributed on an | |
| 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 17 | * KIND, either express or implied. See the License for the | |
| 18 | * specific language governing permissions and limitations | |
| 19 | * under the License. | |
| 20 | */ | |
| 21 | package org.apache.tiles.request.collection; | |
| 22 | ||
| 23 | import java.util.Collection; | |
| 24 | import java.util.Map; | |
| 25 | import java.util.Set; | |
| 26 | ||
| 27 | import org.apache.tiles.request.attribute.HasAddableKeys; | |
| 28 | ||
| 29 | /** | |
| 30 | * Exposes an {@link HasAddableKeys} object as a put/get (no remove) map. | |
| 31 | * | |
| 32 | * @version $Rev: 1064782 $ $Date: 2011-01-29 04:08:52 +1100 (Sat, 29 Jan 2011) $ | |
| 33 | */ | |
| 34 | 3 | public class AddableParameterMap extends ReadOnlyEnumerationMap<String> { |
| 35 | ||
| 36 | /** | |
| 37 | * The request. | |
| 38 | */ | |
| 39 | private HasAddableKeys<String> request; | |
| 40 | ||
| 41 | /** | |
| 42 | * Constructor. | |
| 43 | * | |
| 44 | * @param request The request object to use. | |
| 45 | */ | |
| 46 | public AddableParameterMap(HasAddableKeys<String> request) { | |
| 47 | 3 | super(request); |
| 48 | 3 | this.request = request; |
| 49 | 3 | } |
| 50 | ||
| 51 | /** {@inheritDoc} */ | |
| 52 | public Set<Map.Entry<String, String>> entrySet() { | |
| 53 | 1 | return new AddableParameterEntrySet(); |
| 54 | } | |
| 55 | ||
| 56 | /** {@inheritDoc} */ | |
| 57 | public String put(String key, String value) { | |
| 58 | 1 | String oldValue = request.getValue(key); |
| 59 | 1 | request.setValue(key, value); |
| 60 | 1 | return oldValue; |
| 61 | } | |
| 62 | ||
| 63 | ||
| 64 | /** {@inheritDoc} */ | |
| 65 | public void putAll(Map<? extends String, ? extends String> map) { | |
| 66 | 1 | for (Map.Entry<? extends String, ? extends String> entry : map |
| 67 | .entrySet()) { | |
| 68 | 2 | request.setValue(entry.getKey(), entry.getValue()); |
| 69 | 2 | } |
| 70 | 1 | } |
| 71 | ||
| 72 | ||
| 73 | /** | |
| 74 | * Entry set implementation for {@link AddableParameterMap}. | |
| 75 | */ | |
| 76 | 3 | private class AddableParameterEntrySet extends ReadOnlyEnumerationMap<String>.ReadOnlyEnumerationMapEntrySet { |
| 77 | ||
| 78 | @Override | |
| 79 | public boolean add(java.util.Map.Entry<String, String> e) { | |
| 80 | 1 | request.setValue(e.getKey(), e.getValue()); |
| 81 | 1 | return true; |
| 82 | } | |
| 83 | ||
| 84 | @Override | |
| 85 | public boolean addAll( | |
| 86 | Collection<? extends java.util.Map.Entry<String, String>> c) { | |
| 87 | 1 | for (Map.Entry<String, String> entry : c) { |
| 88 | 2 | request.setValue(entry.getKey(), entry.getValue()); |
| 89 | 2 | } |
| 90 | 1 | return true; |
| 91 | } | |
| 92 | } | |
| 93 | } |