AMHashMap.java revision ba3a3712480c928969c1051ed875c776faaecd93
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: AMHashMap.java,v 1.7 2009/11/03 00:06:31 hengming Exp $
*
*/
/*
* Portions Copyrighted 2014 ForgeRock, AS.
*/
/**
* This class will lower the case of the key that is used to access the HashMap.
* Primarily this implementation of HashMap is customized for storing and
* returning attributes.
*
* In the case of String values, the values are stored in a Set, whereas in case
* of byte values the values are stored as byte array. The special byte methods
* in this class should be used to do specific byte operations.
*
* This HashMap stores information about the type of values, (String or byte).
* All the operations are performed on this basis. The default case is that it
* stores String values.
*
* Note: For byte values there is no negative caching done.
*
*/
public class AMHashMap extends CaseInsensitiveHashMap {
private static final long serialVersionUID = 6468554078141700418L;
private boolean byteValues = false;
// Use a Collections.EMPTY_SET, as you want to avoid instantiating a Set
// for every AMHashMap created.
public AMHashMap() {
super();
}
/**
* Creates a new AMHashMap
*
* @param forByteValues
* if true then, this map is used for storing byte values. if
* false, then used for storing String values
*/
public AMHashMap(boolean forByteValues) {
super();
}
public AMHashMap(int initialCapacity) {
super(initialCapacity);
}
super(initialCapacity);
}
super();
}
}
}
/*
* Override the default isEmpty(). This map is not empty, if the type is
* byteValues and if either the map is not empty or the negative set is not
*/
public boolean isEmpty() {
if (!byteValues) {
return super.isEmpty();
} else {
}
}
/*
* Override the default clear(). This method will clear the negative
* attributes set too, if the type is byteValues
*/
public void clear() {
super.clear();
if (byteValues) {
}
}
byteNegativeAttrs = new CaseInsensitiveHashSet();
}
}
}
}
protected void clearNegativeByteAttrs() {
}
}
// Collections.EMPTY_SET implements contains and returns false. So, we
// are okay here.
}
/*
* Methods to get and get negative set of AMHashMap
*/
protected void setNegativeByteAttr(Set n) {
byteNegativeAttrs = n;
}
public Set getNegativeByteAttrClone() {
return Collections.EMPTY_SET;
}
}
return res;
}
/**
* This compares all the elements of the specified and returns a Set which
* contains all the keys missing in the map. If a key is missing, this
* method adds puts a new element in this map with the missing key and empty
* Set.
*
* @param keys
* the Set of keys that will be compared against the keys in this
* map.
* @return a set of keys which are missing
*/
if (byteValues) {
if (!isNegativeByteAttr(name)) {
// need to mark it as negative
}
} else { // String values
}
}
}
return missAttrNames;
}
/**
* This compares all the elements of the specified and returns a Set which
* contains all the keys missing in the map and also those keys whose values
* are empty. If a key is missing, this method adds puts a new element in
* this map with the missing key and empty Set.
*
* @param keys
* the Set of keys that will be compared against the keys in this
* map.
* @return a set of keys which are missing and keys whose values are empty
* Sets.
*/
if (!byteValues) { // String values
}
}
} else { // byte values
} else if (isNegativeByteAttr(name)) {
}
}
}
return missAttrNames;
}
remove(t);
}
}
}
/**
* Copies the contents of the specified map to this map. This operation
* overwrites the values in this map.
*
* @param map
* the map that needs to be copied
*/
return;
}
// Replicating to avoid comparison inside loop
if (!byteValues) { // String values
}
} else { // byte values
this.removeNegativeByteAttr(name);
}
}
}
}
/**
* Copies the contents of the specified map to this map. This operation
* overwrites the values in this map with new contents. This method copies
* only Sets with values and not empty sets. NOTE: This method will not
* worry about any negative attributes. Hence will be used in CacheBlock
* when the entries are being stored.
*
* @param map
* the map that needs to be copied
*
* @return a set of attributes which have empty sets stored with them
*/
return null;
}
// Replicating to avoid comparison inside loop
if (!byteValues) { // String values
} else {
}
}
} else { // byte values
}
}
return attrsWithValues;
}
/**
* Merges all the values from the specified map to the current map. Adds new
* values into the current map if not already present. The method assumes
* that the values in the map are of Set type.
*
* @param map
* the map whose values need to merge and added to the current
* map.
* @throws NullPointerException
* if the map is null.
*/
throw new NullPointerException();
}
if (!byteValues) { // For String values merge
} else {
}
}
} else { // For byte values replace ??
}
}
/**
* Method which adds new entries to the map with empty set as values
*
* @param names
* new entries to be added to the map
*/
if (!byteValues) {
} else {
}
}
}
/**
* Removes all the empty values (empty sets) from the map.
*/
public void removeEmptyValues() {
// We are removing negative attributes here
if (!byteValues) {
}
}
}
// Remove the negative byte attrs
}
/**
* This method is to some what clone() behaviour. However, this AMHashMap is
* designed to mostly store attribute names as keys and Set of values
* corresponding to each key, a new protected method has been created for
* this purpose.
*
* @return a new AMHashMap that has a copy of all the elements in this map
*/
if (!byteValues) { // String values
if (!isEmpty()) {
}
}
return map;
} else { // byte values
if (!isEmpty()) {
}
}
return map;
}
}
/**
* This method is to some what clone() behaviour. However, this AMHashMap is
* designed to mostly store attribute names as keys and Set of values
* corresponding to each key, a new protected method has been created for
* this purpose.
*
* @param names
* the names of the attributes that need to be obtained from Map
*
* @return a new AMHashMap that has a copy of all the elements in this map
*/
if (!byteValues) { // String values
}
}
}
return map;
} else { // byte values
}
}
}
return map;
}
}
return null;
}
}
}
return copyValues;
}
private byte[][] getByteArrayCopy(byte[][] values) {
byte[][] copyValues = new byte[count1][];
for (int i = 0; i < count1; i++) {
copyValues[i] = new byte[count2];
for (int j = 0; j < count2; j++) {
copyValues[i][j] = values[i][j];
}
}
return copyValues;
}
/**
* Checks whether this map contains byte array or string values.
*
* @return true if the type of values is {@code byte[][]} otherwise false.
*/
public boolean isByteValues() {
return byteValues;
}
}