android.gov.nist.core.MultiValueMapImpl Maven / Gradle / Ivy
/*
* Conditions Of Use
*
* This software was developed by employees of the National Institute of
* Standards and Technology (NIST), an agency of the Federal Government.
* Pursuant to title 15 Untied States Code Section 105, works of NIST
* employees are not subject to copyright protection in the United States
* and are considered to be in the public domain. As a result, a formal
* license is not needed to use the software.
*
* This software is provided by NIST as a service and is expressly
* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
* AND DATA ACCURACY. NIST does not warrant or make any representations
* regarding the use of the software or the results thereof, including but
* not limited to the correctness, accuracy, reliability or usefulness of
* the software.
*
* Permission to use this software is contingent upon your acceptance
* of the terms of this agreement.
*
*/
package android.gov.nist.core;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class MultiValueMapImpl implements MultiValueMap, Cloneable {
// jeand : lazy init of the map to reduce mem consumption
private HashMap> map = null;
private static final long serialVersionUID = 4275505380960964605L;
public MultiValueMapImpl() {
super();
}
public List put(String key, V value) {
ArrayList keyList = null;
if(map != null) {
keyList = map.get(key);
}
if (keyList == null) {
keyList = new ArrayList();
getMap().put(key, keyList);
}
keyList.add(value);
return keyList;
}
public boolean containsValue(Object value) {
Set pairs = null;
if(map != null) {
pairs = map.entrySet();
}
if (pairs == null)
return false;
Iterator pairsIterator = pairs.iterator();
while (pairsIterator.hasNext()) {
Map.Entry keyValuePair = (Map.Entry) (pairsIterator.next());
ArrayList list = (ArrayList) (keyValuePair.getValue());
if (list.contains(value))
return true;
}
return false;
}
public void clear() {
if(map != null) {
Set pairs = map.entrySet();
Iterator pairsIterator = pairs.iterator();
while (pairsIterator.hasNext()) {
Map.Entry keyValuePair = (Map.Entry) (pairsIterator.next());
ArrayList list = (ArrayList) (keyValuePair.getValue());
list.clear();
}
map.clear();
}
}
public Collection values() {
if(map == null) {
return new ArrayList();
}
ArrayList returnList = new ArrayList(map.size());
Set pairs = map.entrySet();
Iterator pairsIterator = pairs.iterator();
while (pairsIterator.hasNext()) {
Map.Entry keyValuePair = (Map.Entry) (pairsIterator.next());
ArrayList list = (ArrayList) (keyValuePair.getValue());
Object[] values = list.toArray();
for (int ii = 0; ii < values.length; ii++) {
returnList.add(values[ii]);
}
}
return returnList;
}
public Object clone() {
MultiValueMapImpl obj = new MultiValueMapImpl();
if(map != null) {
obj.map = (HashMap