/** * Given a map, determine the proper initial size for a new Map to hold the same number of values. * Specifically we want to account for load size and load factor to prevent immediate resizing. * * @param original The original map * * @return The proper size. */ public static int determineProperSizing(Map original) { return determineProperSizing( original.size() ); }
/** * Build a properly sized map, especially handling load size and load factor to prevent immediate resizing. * <p/> * Especially helpful for copy map contents. * * @param size The size to make the map. * * @return The sized map. */ public static <K, V> Map<K, V> mapOfSize(int size) { return new HashMap<>( determineProperSizing( size ), LOAD_FACTOR ); }
/** * Given a set, determine the proper initial size for a new set to hold the same number of values. * Specifically we want to account for load size and load factor to prevent immediate resizing. * * @param original The original set * * @return The proper size. */ public static int determineProperSizing(Set original) { return determineProperSizing( original.size() ); }
@Override public Set<ManagedType<?>> getManagedTypes() { final int setSize = CollectionHelper.determineProperSizing( jpaEntityTypeMap.size() + jpaMappedSuperclassTypeMap.size() + jpaEmbeddableTypes.size() ); final Set<ManagedType<?>> managedTypes = new HashSet<>( setSize ); managedTypes.addAll( jpaEntityTypesByEntityName.values() ); managedTypes.addAll( jpaMappedSuperclassTypeMap.values() ); managedTypes.addAll( jpaEmbeddableTypes ); return managedTypes; }
public static <K, V> HashMap<K, V> makeCopy( Map<K, V> original, Function<K, K> keyTransformer, Function<V, V> valueTransformer) { if ( original == null ) { return null; } final HashMap<K, V> copy = new HashMap<>( determineProperSizing( original ) ); original.forEach( (key, value) -> copy.put( keyTransformer.apply( key ), valueTransformer.apply( value ) ) ); return copy; }
public HQLQueryPlanKey(String query, boolean shallow, Map enabledFilters) { this.query = query; this.shallow = shallow; if ( CollectionHelper.isEmpty( enabledFilters ) ) { filterKeys = Collections.emptySet(); } else { final Set<DynamicFilterKey> tmp = new HashSet<DynamicFilterKey>( CollectionHelper.determineProperSizing( enabledFilters ), CollectionHelper.LOAD_FACTOR ); for ( Object o : enabledFilters.values() ) { tmp.add( new DynamicFilterKey( (FilterImpl) o ) ); } this.filterKeys = Collections.unmodifiableSet( tmp ); } int hash = query.hashCode(); hash = 29 * hash + ( shallow ? 1 : 0 ); hash = 29 * hash + filterKeys.hashCode(); this.hashCode = hash; }
/** * Read this object state back in from the given stream as part of de-serialization * * @param in The stream from which to read our serial state */ @Override @SuppressWarnings("unchecked") public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { sorted = in.readBoolean(); final int numberOfExecutables = in.readInt(); executables.ensureCapacity( numberOfExecutables ); if ( numberOfExecutables > 0 ) { for ( int i = 0; i < numberOfExecutables; i++ ) { E e = (E) in.readObject(); executables.add( e ); } } final int numberOfQuerySpaces = in.readInt(); if ( numberOfQuerySpaces < 0 ) { this.querySpaces = null; } else { querySpaces = new HashSet<Serializable>( CollectionHelper.determineProperSizing( numberOfQuerySpaces ) ); for ( int i = 0; i < numberOfQuerySpaces; i++ ) { querySpaces.add( in.readUTF() ); } } }
private DynamicFilterKey(FilterImpl filter) { this.filterName = filter.getName(); if ( filter.getParameters().isEmpty() ) { parameterMetadata = Collections.emptyMap(); } else { parameterMetadata = new HashMap<String,Integer>( CollectionHelper.determineProperSizing( filter.getParameters() ), CollectionHelper.LOAD_FACTOR ); for ( Object o : filter.getParameters().entrySet() ) { final Map.Entry entry = (Map.Entry) o; final String key = (String) entry.getKey(); final Integer valueCount; if ( Collection.class.isInstance( entry.getValue() ) ) { valueCount = ( (Collection) entry.getValue() ).size(); } else { valueCount = 1; } parameterMetadata.put( key, valueCount ); } } int hash = filterName.hashCode(); hash = 31 * hash + parameterMetadata.hashCode(); this.hashCode = hash; }
@Override @SuppressWarnings({ "unchecked" }) public void addUniqueConstraints(Table table, List uniqueConstraints) { List<UniqueConstraintHolder> constraintHolders = new ArrayList<>( CollectionHelper.determineProperSizing( uniqueConstraints.size() ) ); int keyNameBase = determineCurrentNumberOfUniqueConstraintHolders( table ); for ( String[] columns : ( List<String[]> ) uniqueConstraints ) { final String keyName = "key" + keyNameBase++; constraintHolders.add( new UniqueConstraintHolder().setName( keyName ).setColumns( columns ) ); } addUniqueConstraintHolders( table, constraintHolders ); }
final HashSet<String> aliases = new HashSet<String>( CollectionHelper.determineProperSizing( selections.size() ) );
/** * Build a list of {@link org.hibernate.cfg.UniqueConstraintHolder} instances given a list of * {@link UniqueConstraint} annotations. * * @param annotations The {@link UniqueConstraint} annotations. * * @return The built {@link org.hibernate.cfg.UniqueConstraintHolder} instances. */ public static List<UniqueConstraintHolder> buildUniqueConstraintHolders(UniqueConstraint[] annotations) { List<UniqueConstraintHolder> result; if ( annotations == null || annotations.length == 0 ) { result = java.util.Collections.emptyList(); } else { result = new ArrayList<UniqueConstraintHolder>( CollectionHelper.determineProperSizing( annotations.length ) ); for ( UniqueConstraint uc : annotations ) { result.add( new UniqueConstraintHolder() .setName( uc.name() ) .setColumns( uc.columnNames() ) ); } } return result; }
CollectionHelper.determineProperSizing( ( (Map) originalSnapshot ).size() ), CollectionHelper.LOAD_FACTOR );
/** * Build a properly sized map, especially handling load size and load factor to prevent immediate resizing. * <p/> * Especially helpful for copy map contents. * * @param size The size to make the map. * @return The sized map. */ public static <K,V> Map<K,V> mapOfSize(int size) { return new HashMap<K,V>( determineProperSizing( size ), LOAD_FACTOR ); }
/** * Given a set, determine the proper initial size for a new set to hold the same number of values. * Specifically we want to account for load size and load factor to prevent immediate resizing. * * @param original The original set * @return The proper size. */ public static int determineProperSizing(Set original) { return determineProperSizing( original.size() ); }
/** * Given a set, determine the proper initial size for a new set to hold the same number of values. * Specifically we want to account for load size and load factor to prevent immediate resizing. * * @param original The original set * @return The proper size. */ public static int determineProperSizing(Set original) { return determineProperSizing( original.size() ); }
/** * Given a map, determine the proper initial size for a new Map to hold the same number of values. * Specifically we want to account for load size and load factor to prevent immediate resizing. * * @param original The original map * * @return The proper size. */ public static int determineProperSizing(Map original) { return determineProperSizing( original.size() ); }
/** * Given a map, determine the proper initial size for a new Map to hold the same number of values. * Specifically we want to account for load size and load factor to prevent immediate resizing. * * @param original The original map * @return The proper size. */ public static int determineProperSizing(Map original) { return determineProperSizing( original.size() ); }
/** * Given a map, determine the proper initial size for a new Map to hold the same number of values. * Specifically we want to account for load size and load factor to prevent immediate resizing. * * @param original The original map * @return The proper size. */ public static int determineProperSizing(Map original) { return determineProperSizing( original.size() ); }
/** * Build a properly sized map, especially handling load size and load factor to prevent immediate resizing. * <p/> * Especially helpful for copy map contents. * * @param size The size to make the map. * * @return The sized map. */ public static <K, V> Map<K, V> mapOfSize(int size) { return size < 1 ? new HashMap<>() : new HashMap<>( determineProperSizing( size ), LOAD_FACTOR ); }
@Override @SuppressWarnings({"unchecked"}) public Set<ManagedType<?>> getManagedTypes() { final int setSize = CollectionHelper.determineProperSizing( getEntityDescriptorMap().size() + getMappedSuperclassDescriptorMap().size() + getEmbeddedDescriptorMap().size() ); final Set<ManagedType<?>> managedTypes = new HashSet<>( setSize ); managedTypes.addAll( getEntityDescriptorMap().values() ); managedTypes.addAll( getMappedSuperclassDescriptorMap().values() ); managedTypes.addAll( getEmbeddedDescriptorMap().values() ); return managedTypes; }