|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.AbstractMap | +--org.web3d.vrtp.dabp.OrderedMap
Really simple class that handles attribute-value pairs, in the order they were addded. For example,
Attribute Value
--------- -----
"Fred" PersonObjectInstance
"Joe" managerObjectInstace
"Suzy" modelObjectInstance
"Employees" OrderedMapInstance
"Joe Bloggs" employeeObjectInstance
"Joe Sixpack" employeeObjectInstance
The OrderedMap keeps instances in the order in which they were added; put("Fred", personObjectInstance) and put("Joe", personObjectIntance) means that fred will always be listed before joe. You can also nest OrderedMaps; in the above example, the ordered map includes in turn another ordered map, referenced by the attribute "employees".
One of the major design issues here was whether to use the JDK 1.2 collection classes, the pre-1.2 collections, or a third party collections framework.
The major third-party collections framework is from objectspace (http://www.objectspace.com/developers/jgl/). It is closely modeled on the C++ STL.
The pre-1.2 collections are basically Hashtable and Vector.
JDK 1.2 introduced a new collections framework that imposes a bit more order and capability.
A good review of the JDK1.2 vs. JGL issue is at http://www.javaworld.com/javaworld/jw-01-1999/jw-01-jglvscoll.html Basically, JGL is more capable, but with a steeper learning curve, and, while free, is not a standard part of the JDK distribution. The resemblence to the STL library would be good for porting to C++.
The clinching argument for me was that other elements of the JDK core classes will probably be congealing around the 1.2 collections framework. Using JGL would probably mean doing a lot of conversions between the JGL classes and java collection classes to pass things into other core JDK release objects (say, GUI elements.)
OrderedMap is an implementation of the Map interface, which represents object-pair values, not unlike a hash table. The difference is that OrderedMap preserves the order; if something is added, it can stay in a specific place in the collection. This is required for handling fields, in which order is very, very important.
This subclasses AbstractMap, a convienice class provided by Sun to take care of most of the details of implementing the Map interface.
Note that this uses internally the _new_ Vector class. You should use the List interface to interact with the new Vector class, so that you don't get tied to the old way of doing things.
This makes use of a couple inner classes and one anonymous class, which are moderately obscure portions of the Java language. Basically, inner classes are "helper classes" that are closely coupled to a particular class. They could, in theory, be stand-alone classes, but since they make sense only when used with another class, they are syntactically "enclosed" by that class. They're refered to via OuterClass.InnerClass notation. I'm of two minds about this; while they're probably a good idea, they're also difficult for newbies to grasp. The clincher is that they're also basically required by the Map interface in the collections framework, eg Map.Entry.
Anonymous classes are like inner classes, but have no name. They just conform to an interface.
For a discussion of inner classes, see http://www.performancecomputing.com/columns/java/9806.shtml
This class includes references to XML, which is a highly questionable decision. OrderedMap is general purpose enough to get along without the XML references. But it makes it easier to create nested attribute-value lists if this is in a constructor.
this is almost, but not quite, a generally useful and reusable class, which annoys me to no end.
Author: Don McGregor
Inner Class Summary
(package private) class
OrderedMap.Entry
Another inner class, this one for Map.Entry.
Inner classes inherited from class java.util.Map
java.util.Map.Entry
Field Summary
protected java.util.Vector
entries
protected java.lang.String
name
Constructor Summary
OrderedMap(org.w3c.dom.Element directoryEntry)
A constructor that takes a DOM node in a specified format
and creates key-value pairs from the result.
OrderedMap(java.lang.String pName)
Constructor; takes a name for this directory, default, empty stuff
for the rest.
Method Summary
java.lang.Object
clone()
clone operation; given an ordered map, returns another ordered map
that shares no internal data structures.
int
compareTo(java.lang.Object obj)
Implementation of the Comparable interface.
java.util.Set
entrySet()
Returns a set view of the mappings contained in this map.
java.lang.Object
get(int pIdx)
Get an object at a specific index.
java.lang.Object
get(java.lang.Object pKey)
Get a value back out for the key passed in.
int
getLength()
like the above, but a different name, because I can never remember.
java.lang.String
getName()
Returns the name of this ordered map.
int
getSize()
Number of bytes this takes up when serialized.
int
hashcode()
Generate a hashcode for an ordered map.
void
initializeWithBinary(byte[] pData,
int pOffset)
this is unexercised right now.
void
initializeWithString(java.lang.String pString)
This is not implemented right now.
static void
main(java.lang.String[] args)
Used for debugging and testing purposes
java.lang.Object
put(java.lang.Object pObject,
int pIdx)
Puts an element at a specific place in the map.
java.lang.Object
put(java.lang.Object pKey,
java.lang.Object pValue)
Put a string and a value into the database.
java.lang.Object
put(OrderedMap.Entry pEntry)
Add a new Map.Entry object (key, value) to the OrderedMap.
void
serialize(java.io.DataOutputStream pOutputStream)
Serialize data, using our own internal scheme, completely
separate from that of the JDK serialization/externalizable
scheme.
void
setName(java.lang.String pName)
int
size()
returns the size of the OrderedMap, which is just the number
of entries.
java.lang.String
toString()
toString is a method used lots of places in the JDK; it's what is called
by System.out.println() on objects that appear in println statements.
protected boolean
valEquals(java.lang.Object o1,
java.lang.Object o2)
Test two values for equality.
Methods inherited from class java.util.AbstractMap
clear, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, remove, values
Methods inherited from class java.lang.Object
Methods inherited from interface org.web3d.vrtp.datatypes.Primitive
equals, hashCode
Field Detail
name
protected java.lang.String name
entries
protected java.util.Vector entries
Constructor Detail
OrderedMap
public OrderedMap(java.lang.String pName)
OrderedMap
public OrderedMap(org.w3c.dom.Element directoryEntry)
Method Detail
entrySet
public java.util.Set entrySet()
entrySet
in class java.util.AbstractMap
valEquals
protected boolean valEquals(java.lang.Object o1,
java.lang.Object o2)
initializeWithBinary
public void initializeWithBinary(byte[] pData,
int pOffset)
initializeWithBinary
in interface Primitive
initializeWithString
public void initializeWithString(java.lang.String pString)
initializeWithString
in interface Primitive
clone
public java.lang.Object clone()
put
public java.lang.Object put(OrderedMap.Entry pEntry)
put
public java.lang.Object put(java.lang.Object pKey,
java.lang.Object pValue)
put
in class java.util.AbstractMap
getName
public java.lang.String getName()
setName
public void setName(java.lang.String pName)
get
public java.lang.Object get(int pIdx)
put
public java.lang.Object put(java.lang.Object pObject,
int pIdx)
get
public java.lang.Object get(java.lang.Object pKey)
get
in class java.util.AbstractMap
toString
public java.lang.String toString()
size
public int size()
size
in class java.util.AbstractMap
getLength
public int getLength()
getSize
public int getSize()
serialize
public void serialize(java.io.DataOutputStream pOutputStream)
hashcode
public int hashcode()
compareTo
public int compareTo(java.lang.Object obj)
main
public static void main(java.lang.String[] args)
Overview
Package
Class
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD