org.frameworkset.util.LinkedMultiValueMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bboss-util Show documentation
Show all versions of bboss-util Show documentation
bboss is a j2ee framework include aop/ioc,mvc,persistent,taglib,rpc,event ,bean-xml serializable and so on.http://www.bbossgroups.com
/*
* Copyright 2008 biaoping.yin
*
* Licensed 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.frameworkset.util;
import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Title: LinkedMultiValueMap.java
* Description:
* bboss workgroup
* Copyright (c) 2008
* @Date 2010-11-22
* @author biaoping.yin
* @version 1.0
*/
public class LinkedMultiValueMap implements MultiValueMap, Serializable {
private static final long serialVersionUID = 3801124242820219131L;
private final Map> targetMap;
/**
* Create a new LinkedMultiValueMap that wraps a {@link LinkedHashMap}.
*/
public LinkedMultiValueMap() {
this.targetMap = new LinkedHashMap>();
}
/**
* Create a new LinkedMultiValueMap that wraps a {@link LinkedHashMap}
* with the given initial capacity.
* @param initialCapacity the initial capacity
*/
public LinkedMultiValueMap(int initialCapacity) {
this.targetMap = new LinkedHashMap>(initialCapacity);
}
/**
* Copy constructor: Create a new LinkedMultiValueMap with the same mappings
* as the specified Map.
* @param otherMap the Map whose mappings are to be placed in this Map
*/
public LinkedMultiValueMap(Map> otherMap) {
this.targetMap = new LinkedHashMap>(otherMap);
}
// MultiValueMap implementation
public void add(K key, V value) {
List values = this.targetMap.get(key);
if (values == null) {
values = new LinkedList();
this.targetMap.put(key, values);
}
values.add(value);
}
public V getFirst(K key) {
List values = this.targetMap.get(key);
return (values != null ? values.get(0) : null);
}
public void set(K key, V value) {
List values = new LinkedList();
values.add(value);
this.targetMap.put(key, values);
}
public void setAll(Map values) {
for (Entry entry : values.entrySet()) {
set(entry.getKey(), entry.getValue());
}
}
public Map toSingleValueMap() {
LinkedHashMap singleValueMap = new LinkedHashMap(this.targetMap.size());
for (Entry> entry : targetMap.entrySet()) {
singleValueMap.put(entry.getKey(), entry.getValue().get(0));
}
return singleValueMap;
}
// Map implementation
public int size() {
return this.targetMap.size();
}
public boolean isEmpty() {
return this.targetMap.isEmpty();
}
public boolean containsKey(Object key) {
return this.targetMap.containsKey(key);
}
public boolean containsValue(Object value) {
return this.targetMap.containsValue(value);
}
public List get(Object key) {
return this.targetMap.get(key);
}
public List put(K key, List value) {
return this.targetMap.put(key, value);
}
public List remove(Object key) {
return this.targetMap.remove(key);
}
public void putAll(Map extends K, ? extends List> m) {
this.targetMap.putAll(m);
}
public void clear() {
this.targetMap.clear();
}
public Set keySet() {
return this.targetMap.keySet();
}
public Collection> values() {
return this.targetMap.values();
}
public Set>> entrySet() {
return this.targetMap.entrySet();
}
@Override
public boolean equals(Object obj) {
return this.targetMap.equals(obj);
}
@Override
public int hashCode() {
return this.targetMap.hashCode();
}
@Override
public String toString() {
return this.targetMap.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy