HHH-2748 : remove SequencedHashMap usage;

HHH-2749  : direct use of LinkedHashSet/LinkedHashMap

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@12832 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2007-07-27 03:20:24 +00:00
parent 61133f9530
commit 4499b6ac14
14 changed files with 101 additions and 148 deletions

View File

@ -9,7 +9,6 @@ import java.util.Iterator;
import java.util.Properties;
import java.util.StringTokenizer;
import org.apache.commons.collections.SequencedHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Attribute;
@ -2610,14 +2609,11 @@ public final class HbmBinder {
}
public static java.util.Map getParameterTypes(Element queryElem) {
java.util.Map result = new SequencedHashMap();
java.util.Map result = new java.util.LinkedHashMap();
Iterator iter = queryElem.elementIterator("query-param");
while ( iter.hasNext() ) {
Element element = (Element) iter.next();
result.put(
element.attributeValue("name"),
element.attributeValue("type")
);
result.put( element.attributeValue("name"), element.attributeValue("type") );
}
return result;
}

View File

@ -4,9 +4,9 @@ package org.hibernate.engine;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.commons.collections.SequencedHashMap;
import org.hibernate.EntityMode;
import org.hibernate.cache.CacheKey;
import org.hibernate.collection.PersistentCollection;
@ -30,12 +30,12 @@ public class BatchFetchQueue {
* elegible for batch-fetching.
* <p/>
* Even though this is a map, we only use the keys. A map was chosen in
* order to utilize a {@link SequencedHashMap} to maintain sequencing
* order to utilize a {@link LinkedHashMap} to maintain sequencing
* as well as uniqueness.
* <p/>
* TODO : this would be better as a SequencedReferenceSet, but no such beast exists!
*/
private final Map batchLoadableEntityKeys = new SequencedHashMap(8);
private final Map batchLoadableEntityKeys = new LinkedHashMap(8);
/**
* A map of {@link SubselectFetch subselect-fetch descriptors} keyed by the

View File

@ -10,11 +10,11 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.collections.SequencedHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -63,8 +63,8 @@ public class QueryTranslatorImpl extends BasicLoader implements FilterTranslator
private final String queryIdentifier;
private final String queryString;
private final Map typeMap = new SequencedHashMap();
private final Map collections = new SequencedHashMap();
private final Map typeMap = new LinkedHashMap();
private final Map collections = new LinkedHashMap();
private List returnedTypes = new ArrayList();
private final List fromTypes = new ArrayList();
private final List scalarTypes = new ArrayList();
@ -77,7 +77,7 @@ public class QueryTranslatorImpl extends BasicLoader implements FilterTranslator
private final List scalarSelectTokens = new ArrayList();
private final List whereTokens = new ArrayList();
private final List havingTokens = new ArrayList();
private final Map joins = new SequencedHashMap();
private final Map joins = new LinkedHashMap();
private final List orderByTokens = new ArrayList();
private final List groupByTokens = new ArrayList();
private final Set querySpaces = new HashSet();

View File

@ -10,8 +10,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.LinkedHashMap;
import org.apache.commons.collections.SequencedHashMap;
import org.hibernate.Criteria;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
@ -49,11 +49,11 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
private final String rootSQLAlias;
private int aliasCount = 0;
private final Map criteriaEntityNames = new SequencedHashMap();
private final Map criteriaEntityNames = new LinkedHashMap();
private final Map criteriaSQLAliasMap = new HashMap();
private final Map aliasCriteriaMap = new HashMap();
private final Map associationPathCriteriaMap = new SequencedHashMap();
private final Map associationPathJoinTypesMap = new SequencedHashMap();
private final Map associationPathCriteriaMap = new LinkedHashMap();
private final Map associationPathJoinTypesMap = new LinkedHashMap();
private final SessionFactoryImplementor sessionFactory;

View File

@ -7,8 +7,8 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.LinkedHashMap;
import org.apache.commons.collections.SequencedHashMap;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect;
@ -30,7 +30,7 @@ public class Table implements RelationalModel, Serializable {
/**
* contains all columns, including the primary key
*/
private Map columns = new SequencedHashMap();
private Map columns = new LinkedHashMap();
private KeyValue idValue;
private PrimaryKey primaryKey;
private Map indexes = new HashMap();

View File

@ -2,11 +2,10 @@
package org.hibernate.sql;
import java.util.Map;
import java.util.LinkedHashMap;
import org.hibernate.util.StringHelper;
import org.apache.commons.collections.SequencedHashMap;
/**
* Abstract SQL case fragment renderer
*
@ -17,7 +16,7 @@ public abstract class CaseFragment {
protected String returnColumnName;
protected Map cases = new SequencedHashMap();
protected Map cases = new LinkedHashMap();
public CaseFragment setReturnColumnName(String returnColumnName) {
this.returnColumnName = returnColumnName;

View File

@ -3,8 +3,8 @@ package org.hibernate.sql;
import java.util.Iterator;
import java.util.Map;
import java.util.LinkedHashMap;
import org.apache.commons.collections.SequencedHashMap;
import org.hibernate.dialect.Dialect;
import org.hibernate.type.LiteralType;
@ -17,7 +17,7 @@ public class Insert {
private Dialect dialect;
private String tableName;
private String comment;
private Map columns = new SequencedHashMap();
private Map columns = new LinkedHashMap();
public Insert(Dialect dialect) {
this.dialect = dialect;

View File

@ -3,13 +3,12 @@ package org.hibernate.sql;
import java.util.Iterator;
import java.util.Map;
import java.util.LinkedHashMap;
import org.hibernate.dialect.Dialect;
import org.hibernate.type.LiteralType;
import org.hibernate.util.StringHelper;
import org.apache.commons.collections.SequencedHashMap;
/**
* An SQL <tt>UPDATE</tt> statement
*
@ -24,8 +23,8 @@ public class Update {
private String assignments;
private String comment;
private Map columns = new SequencedHashMap();
private Map whereColumns = new SequencedHashMap();
private Map columns = new LinkedHashMap();
private Map whereColumns = new LinkedHashMap();
private Dialect dialect;

View File

@ -1,13 +1,12 @@
package org.hibernate.tuple;
import org.apache.commons.collections.SequencedHashMap;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import java.util.Map;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.io.Serializable;
/**
@ -18,7 +17,7 @@ import java.io.Serializable;
public abstract class EntityModeToTuplizerMapping implements Serializable {
// map of EntityMode -> Tuplizer
private final Map tuplizers = Collections.synchronizedMap( new SequencedHashMap() );
private final Map tuplizers = Collections.synchronizedMap( new LinkedHashMap() );
protected void addTuplizer(EntityMode entityMode, Tuplizer tuplizer) {
tuplizers.put( entityMode, tuplizer );

View File

@ -1,16 +1,30 @@
//$Id: OrderedMapType.java 10100 2006-07-10 16:31:09Z steve.ebersole@jboss.com $
package org.hibernate.type;
import org.hibernate.util.LinkedHashCollectionHelper;
import java.util.LinkedHashMap;
/**
* A specialization of the map type, with (resultset-based) ordering.
*/
public class OrderedMapType extends MapType {
/**
* Constructs a map type capable of creating ordered maps of the given
* role.
*
* @param role The collection role name.
* @param propertyRef The property ref name.
* @param isEmbeddedInXML Is this collection to embed itself in xml
*/
public OrderedMapType(String role, String propertyRef, boolean isEmbeddedInXML) {
super( role, propertyRef, isEmbeddedInXML );
}
/**
* {@inheritDoc}
*/
public Object instantiate(int anticipatedSize) {
return LinkedHashCollectionHelper.createLinkedHashMap( anticipatedSize );
return new LinkedHashMap( anticipatedSize );
}
}

View File

@ -1,16 +1,30 @@
//$Id: OrderedSetType.java 10100 2006-07-10 16:31:09Z steve.ebersole@jboss.com $
package org.hibernate.type;
import org.hibernate.util.LinkedHashCollectionHelper;
import java.util.LinkedHashSet;
/**
* A specialization of the set type, with (resultset-based) ordering.
*/
public class OrderedSetType extends SetType {
/**
* Constructs a set type capable of creating ordered sets of the given
* role.
*
* @param role The collection role name.
* @param propertyRef The property ref name.
* @param isEmbeddedInXML Is this collection to embed itself in xml
*/
public OrderedSetType(String role, String propertyRef, boolean isEmbeddedInXML) {
super( role, propertyRef, isEmbeddedInXML );
}
/**
* {@inheritDoc}
*/
public Object instantiate(int anticipatedSize) {
return LinkedHashCollectionHelper.createLinkedHashSet( anticipatedSize );
return new LinkedHashSet( anticipatedSize );
}
}

View File

@ -7,12 +7,11 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.collections.SequencedHashMap;
/**
* A <tt>Map</tt> where keys are compared by object identity,
* rather than <tt>equals()</tt>.
@ -26,22 +25,31 @@ public final class IdentityMap implements Map {
/**
* Return a new instance of this class, with an undefined
* iteration order
* iteration order.
*
* @param size The size of the map
* @return Map
*/
public static Map instantiate(int size) {
return new IdentityMap( new HashMap(size) );
return new IdentityMap( new HashMap( size ) );
}
/**
* Return a new instance of this class, with iteration
* order defined by the order that entries were added
* order defined as the order in which entries were added
*
* @param size The size of the map to create
* @return
*/
public static Map instantiateSequenced(int size) {
return new IdentityMap( new SequencedHashMap(size) );
return new IdentityMap( new LinkedHashMap( size ) );
}
/**
* Private ctor used in serialization.
*
* @param underlyingMap The delegate map.
*/
private IdentityMap(Map underlyingMap) {
map = underlyingMap;
dirty = true;

View File

@ -1,23 +1,36 @@
//$Id: IdentitySet.java 8807 2005-12-09 15:27:05Z epbernard $
package org.hibernate.util;
import java.util.Set;
import java.util.Collection;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* Set implementation that use == instead of equals() as its comparison mechanism
* that base its implementation of IdentityMap
*
* Set implementation that use == instead of equals() as its comparison
* mechanism. This is achieved by internally using an IdentityHashMap.
*
* @author Emmanuel Bernard
*/
public class IdentitySet implements Set {
private Map map;
private static final Object DUMP_VALUE = new Object();
private final IdentityHashMap map;
/**
* Create an IdentitySet with default sizing.
*/
public IdentitySet() {
this.map = IdentityMap.instantiate( 10 );
this.map = new IdentityHashMap();
}
/**
* Create an IdentitySet with the given sizing.
*
* @param sizing The sizing of the set to create.
*/
public IdentitySet(int sizing) {
this.map = new IdentityHashMap( sizing );
}
public int size() {
@ -41,11 +54,11 @@ public class IdentitySet implements Set {
}
public Object[] toArray(Object[] a) {
return map.entrySet().toArray(a);
return map.entrySet().toArray( a );
}
public boolean add(Object o) {
return map.put( o, DUMP_VALUE) == null;
return map.put( o, DUMP_VALUE ) == null;
}
public boolean remove(Object o) {
@ -55,7 +68,9 @@ public class IdentitySet implements Set {
public boolean containsAll(Collection c) {
Iterator it = c.iterator();
while ( it.hasNext() ) {
if ( ! map.containsKey( it.next() ) ) return false;
if ( !map.containsKey( it.next() ) ) {
return false;
}
}
return true;
}
@ -64,7 +79,9 @@ public class IdentitySet implements Set {
Iterator it = c.iterator();
boolean changed = false;
while ( it.hasNext() ) {
if ( this.add( it.next() ) ) changed = true;
if ( this.add( it.next() ) ) {
changed = true;
}
}
return changed;
}
@ -78,7 +95,9 @@ public class IdentitySet implements Set {
Iterator it = c.iterator();
boolean changed = false;
while ( it.hasNext() ) {
if ( this.remove( it.next() ) ) changed = true;
if ( this.remove( it.next() ) ) {
changed = true;
}
}
return changed;
}

View File

@ -1,95 +0,0 @@
//$Id: LinkedHashCollectionHelper.java 10100 2006-07-10 16:31:09Z steve.ebersole@jboss.com $
package org.hibernate.util;
import java.util.Map;
import java.util.Set;
import java.lang.reflect.Constructor;
import org.hibernate.AssertionFailure;
public final class LinkedHashCollectionHelper {
private static final Class SET_CLASS;
private static final Class MAP_CLASS;
private static final Class[] CAPACITY_CTOR_SIG = new Class[] { int.class, float.class };
private static final Constructor SET_CAPACITY_CTOR;
private static final Constructor MAP_CAPACITY_CTOR;
private static final float LOAD_FACTOR_V = .75f;
private static final Float LOAD_FACTOR = new Float( LOAD_FACTOR_V );
static {
Class setClass;
Class mapClass;
Constructor setCtor;
Constructor mapCtor;
try {
setClass = Class.forName( "java.util.LinkedHashSet" );
mapClass = Class.forName( "java.util.LinkedHashMap" );
setCtor = setClass.getConstructor( CAPACITY_CTOR_SIG );
mapCtor = mapClass.getConstructor( CAPACITY_CTOR_SIG );
}
catch ( Throwable t ) {
setClass = null;
mapClass = null;
setCtor = null;
mapCtor = null;
}
SET_CLASS = setClass;
MAP_CLASS = mapClass;
SET_CAPACITY_CTOR = setCtor;
MAP_CAPACITY_CTOR = mapCtor;
}
public static Set createLinkedHashSet() {
try {
return (Set) SET_CLASS.newInstance();
}
catch (Exception e) {
throw new AssertionFailure("Could not instantiate LinkedHashSet", e);
}
}
public static Set createLinkedHashSet(int anticipatedSize) {
if ( anticipatedSize <= 0 ) {
return createLinkedHashSet();
}
int initialCapacity = anticipatedSize + (int)( anticipatedSize * LOAD_FACTOR_V );
try {
return ( Set ) SET_CAPACITY_CTOR.newInstance( new Object[] { new Integer( initialCapacity ), LOAD_FACTOR } );
}
catch (Exception e) {
throw new AssertionFailure("Could not instantiate LinkedHashSet", e);
}
}
public static Map createLinkedHashMap() {
try {
return (Map) MAP_CLASS.newInstance();
}
catch (Exception e) {
throw new AssertionFailure("Could not instantiate LinkedHashMap", e);
}
}
public static Map createLinkedHashMap(int anticipatedSize) {
if ( anticipatedSize <= 0 ) {
return createLinkedHashMap();
}
int initialCapacity = anticipatedSize + (int)( anticipatedSize * LOAD_FACTOR_V );
try {
return ( Map ) MAP_CAPACITY_CTOR.newInstance( new Object[] { new Integer( initialCapacity ), LOAD_FACTOR } );
}
catch (Exception e) {
throw new AssertionFailure("Could not instantiate LinkedHashMap", e);
}
}
private LinkedHashCollectionHelper() {}
}