com.google.common.collect.Maps.newLinkedHashMapWithExpectedSize()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中com.google.common.collect.Maps.newLinkedHashMapWithExpectedSize()方法的一些代码示例,展示了Maps.newLinkedHashMapWithExpectedSize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Maps.newLinkedHashMapWithExpectedSize()方法的具体详情如下:
包路径:com.google.common.collect.Maps
类名称:Maps
方法名:newLinkedHashMapWithExpectedSize

Maps.newLinkedHashMapWithExpectedSize介绍

[英]Creates a LinkedHashMap instance, with a high enough "initial capacity" that it should hold expectedSize elements without growth. This behavior cannot be broadly guaranteed, but it is observed to be true for OpenJDK 1.7. It also can't be guaranteed that the method isn't inadvertently oversizing the returned map.
[中]创建一个LinkedHashMap实例,该实例具有足够高的“初始容量”,可以容纳expectedSize元素而不会增长。这种行为不能得到广泛的保证,但OpenJDK1.7的情况是如此。也不能保证该方法不会无意中过度调整返回的映射。

代码示例

代码示例来源:origin: google/guava

/**
 * Returns the platform preferred implementation of an insertion ordered map based on a hash
 * table.
 */
static <K, V> Map<K, V> newLinkedHashMapWithExpectedSize(int expectedSize) {
 return Maps.newLinkedHashMapWithExpectedSize(expectedSize);
}

代码示例来源:origin: google/guava

@Override
public Map<C, V> get() {
 return Maps.newLinkedHashMapWithExpectedSize(expectedSize);
}

代码示例来源:origin: google/guava

private LinkedHashMultiset(int distinctElements) {
 super(Maps.<E, Count>newLinkedHashMapWithExpectedSize(distinctElements));
}

代码示例来源:origin: google/j2objc

@Override
public Map<C, V> get() {
 return Maps.newLinkedHashMapWithExpectedSize(expectedSize);
}

代码示例来源:origin: wildfly/wildfly

/**
 * Returns the platform preferred implementation of an insertion ordered map based on a hash
 * table.
 */
static <K, V> Map<K, V> newLinkedHashMapWithExpectedSize(int expectedSize) {
 return Maps.newLinkedHashMapWithExpectedSize(expectedSize);
}

代码示例来源:origin: wildfly/wildfly

@Override
public Map<C, V> get() {
 return Maps.newLinkedHashMapWithExpectedSize(expectedSize);
}

代码示例来源:origin: wildfly/wildfly

private LinkedHashMultiset(int distinctElements) {
 super(Maps.<E, Count>newLinkedHashMapWithExpectedSize(distinctElements));
}

代码示例来源:origin: google/guava

/** Returns an empty mutable map whose keys will respect this {@link ElementOrder}. */
<K extends T, V> Map<K, V> createMap(int expectedSize) {
 switch (type) {
  case UNORDERED:
   return Maps.newHashMapWithExpectedSize(expectedSize);
  case INSERTION:
   return Maps.newLinkedHashMapWithExpectedSize(expectedSize);
  case SORTED:
   return Maps.newTreeMap(comparator());
  default:
   throw new AssertionError();
 }
}

代码示例来源:origin: google/j2objc

/** Returns an empty mutable map whose keys will respect this {@link ElementOrder}. */
<K extends T, V> Map<K, V> createMap(int expectedSize) {
 switch (type) {
  case UNORDERED:
   return Maps.newHashMapWithExpectedSize(expectedSize);
  case INSERTION:
   return Maps.newLinkedHashMapWithExpectedSize(expectedSize);
  case SORTED:
   return Maps.newTreeMap(comparator());
  default:
   throw new AssertionError();
 }
}

代码示例来源:origin: wildfly/wildfly

/** Returns an empty mutable map whose keys will respect this {@link ElementOrder}. */
<K extends T, V> Map<K, V> createMap(int expectedSize) {
 switch (type) {
  case UNORDERED:
   return Maps.newHashMapWithExpectedSize(expectedSize);
  case INSERTION:
   return Maps.newLinkedHashMapWithExpectedSize(expectedSize);
  case SORTED:
   return Maps.newTreeMap(comparator());
  default:
   throw new AssertionError();
 }
}

代码示例来源:origin: google/guava

/** Same test as above but for newLinkedHashMapWithExpectedSize */
@GwtIncompatible // reflection
@AndroidIncompatible // relies on assumptions about OpenJDK
public void testNewLinkedHashMapWithExpectedSize_wontGrow() throws Exception {
 assertTrue(bucketsOf(Maps.newLinkedHashMapWithExpectedSize(0)) <= 1);
 for (int size = 1; size < 200; size++) {
  assertWontGrow(
    size,
    Maps.newLinkedHashMapWithExpectedSize(size),
    Maps.newLinkedHashMapWithExpectedSize(size));
 }
}

代码示例来源:origin: google/guava

/**
 * Creates an empty {@code HashBasedTable} with the specified map sizes.
 *
 * @param expectedRows the expected number of distinct row keys
 * @param expectedCellsPerRow the expected number of column key / value mappings in each row
 * @throws IllegalArgumentException if {@code expectedRows} or {@code expectedCellsPerRow} is
 *     negative
 */
public static <R, C, V> HashBasedTable<R, C, V> create(
  int expectedRows, int expectedCellsPerRow) {
 checkNonnegative(expectedCellsPerRow, "expectedCellsPerRow");
 Map<R, Map<C, V>> backingMap = Maps.newLinkedHashMapWithExpectedSize(expectedRows);
 return new HashBasedTable<>(backingMap, new Factory<C, V>(expectedCellsPerRow));
}

代码示例来源:origin: google/j2objc

/**
 * Creates an empty {@code HashBasedTable} with the specified map sizes.
 *
 * @param expectedRows the expected number of distinct row keys
 * @param expectedCellsPerRow the expected number of column key / value mappings in each row
 * @throws IllegalArgumentException if {@code expectedRows} or {@code expectedCellsPerRow} is
 *     negative
 */
public static <R, C, V> HashBasedTable<R, C, V> create(
  int expectedRows, int expectedCellsPerRow) {
 checkNonnegative(expectedCellsPerRow, "expectedCellsPerRow");
 Map<R, Map<C, V>> backingMap = Maps.newLinkedHashMapWithExpectedSize(expectedRows);
 return new HashBasedTable<>(backingMap, new Factory<C, V>(expectedCellsPerRow));
}

代码示例来源:origin: wildfly/wildfly

/**
 * Creates an empty {@code HashBasedTable} with the specified map sizes.
 *
 * @param expectedRows the expected number of distinct row keys
 * @param expectedCellsPerRow the expected number of column key / value mappings in each row
 * @throws IllegalArgumentException if {@code expectedRows} or {@code expectedCellsPerRow} is
 *     negative
 */
public static <R, C, V> HashBasedTable<R, C, V> create(
  int expectedRows, int expectedCellsPerRow) {
 checkNonnegative(expectedCellsPerRow, "expectedCellsPerRow");
 Map<R, Map<C, V>> backingMap = Maps.newLinkedHashMapWithExpectedSize(expectedRows);
 return new HashBasedTable<>(backingMap, new Factory<C, V>(expectedCellsPerRow));
}

代码示例来源:origin: apache/hive

final Map<Future<Boolean>, Path> moveFutures = Maps.newLinkedHashMapWithExpectedSize(srcs.length);
final int moveFilesThreadCount = HiveConf.getIntVar(conf, ConfVars.HIVE_MOVE_FILES_THREAD_COUNT);
final ExecutorService pool = moveFilesThreadCount > 0

代码示例来源:origin: com.diffplug.guava/guava-collect

@Override
  <K, V> Map<K, Collection<V>> createMap() {
    return newLinkedHashMapWithExpectedSize(expectedKeys);
  }
};

代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger

/** Returns an empty mutable map whose keys will respect this {@link ElementOrder}. */
<K extends T, V> Map<K, V> createMap(int expectedSize) {
 switch (type) {
  case UNORDERED:
   return Maps.newHashMapWithExpectedSize(expectedSize);
  case INSERTION:
   return Maps.newLinkedHashMapWithExpectedSize(expectedSize);
  case SORTED:
   return Maps.newTreeMap(comparator());
  default:
   throw new AssertionError();
 }
}

代码示例来源:origin: com.google.javascript/closure-compiler

public NameBasedDefinitionProvider(AbstractCompiler compiler, boolean allowComplexFunctionDefs) {
 this.compiler = compiler;
 this.allowComplexFunctionDefs = allowComplexFunctionDefs;
 int numInputs = compiler.getNumberOfInputs();
 // Estimates below were generated by experimentation with large Google projects.
 this.definitionsByName = LinkedHashMultimap.create(numInputs * 15, 1);
 int estimatedDefinitionSites = numInputs * 22;
 this.definitionSitesByDefinitionSiteNode =
   Maps.newLinkedHashMapWithExpectedSize(estimatedDefinitionSites);
 this.definitionSitesByScopeNode = HashMultimap.create(estimatedDefinitionSites, 1);
 this.definitionNodes = Sets.newHashSetWithExpectedSize(estimatedDefinitionSites);
}

代码示例来源:origin: xyz.codemeans.protobuf4j/protobuf4j-orm

private Map<Object, Object> mapToMap(Map<?, ?> map, Descriptors.FieldDescriptor keyFd,
  Descriptors.FieldDescriptor valFd) {
 Map<Object, Object> newMap = Maps.newLinkedHashMapWithExpectedSize(map.size());
 for (Map.Entry entry : map.entrySet()) {
  Object key = basicTypeFieldResolver.toSqlValue(keyFd, entry.getKey());
  Object value = basicTypeFieldResolver.toSqlValue(valFd, entry.getValue());
  newMap.put(key, value);
 }
 return newMap;
}

代码示例来源:origin: xyz.codemeans.protobuf4j/protobuf4j-orm

private Map<Object, Object> collectionToMap(Collection<? extends MapEntry> valueCollection,
  Descriptors.FieldDescriptor keyFd, Descriptors.FieldDescriptor valFd) {
 Map<Object, Object> map = Maps.newLinkedHashMapWithExpectedSize(valueCollection.size());
 for (MapEntry entry : valueCollection) {
  Object key = basicTypeFieldResolver.toSqlValue(keyFd, entry.getKey());
  Object value = basicTypeFieldResolver.toSqlValue(valFd, entry.getValue());
  map.put(key, value);
 }
 return map;
}

相关文章