java.util.LinkedHashMap.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(182)

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

LinkedHashMap.<init>介绍

[英]Constructs a new empty LinkedHashMap instance.
[中]构造一个新的空LinkedHashMap实例。

代码示例

代码示例来源:origin: spring-projects/spring-framework

private static Map<String, String> addCharsetParameter(Charset charset, Map<String, String> parameters) {
  Map<String, String> map = new LinkedHashMap<>(parameters);
  map.put(PARAM_CHARSET, charset.name());
  return map;
}

代码示例来源:origin: square/okhttp

public Challenge(String scheme, Map<String, String> authParams) {
 if (scheme == null) throw new NullPointerException("scheme == null");
 if (authParams == null) throw new NullPointerException("authParams == null");
 this.scheme = scheme;
 Map<String, String> newAuthParams = new LinkedHashMap<>();
 for (Entry<String, String> authParam : authParams.entrySet()) {
  String key = (authParam.getKey() == null) ? null : authParam.getKey().toLowerCase(US);
  newAuthParams.put(key, authParam.getValue());
 }
 this.authParams = unmodifiableMap(newAuthParams);
}

代码示例来源:origin: square/okhttp

public BasicCertificateChainCleaner(X509Certificate... caCerts) {
 subjectToCaCerts = new LinkedHashMap<>();
 for (X509Certificate caCert : caCerts) {
  X500Principal subject = caCert.getSubjectX500Principal();
  Set<X509Certificate> subjectCaCerts = subjectToCaCerts.get(subject);
  if (subjectCaCerts == null) {
   subjectCaCerts = new LinkedHashSet<>(1);
   subjectToCaCerts.put(subject, subjectCaCerts);
  }
  subjectCaCerts.add(caCert);
 }
}

代码示例来源:origin: square/retrofit

void addContributor(String owner, String repo, String name, int contributions) {
  Map<String, List<Contributor>> repoContributors = ownerRepoContributors.get(owner);
  if (repoContributors == null) {
   repoContributors = new LinkedHashMap<>();
   ownerRepoContributors.put(owner, repoContributors);
  }
  List<Contributor> contributors = repoContributors.get(repo);
  if (contributors == null) {
   contributors = new ArrayList<>();
   repoContributors.put(repo, contributors);
  }
  contributors.add(new Contributor(name, contributions));
 }
}

代码示例来源:origin: stackoverflow.com

public static Map<TimeUnit,Long> computeDiff(Date date1, Date date2) {
  long diffInMillies = date2.getTime() - date1.getTime();
  List<TimeUnit> units = new ArrayList<TimeUnit>(EnumSet.allOf(TimeUnit.class));
  Collections.reverse(units);
  Map<TimeUnit,Long> result = new LinkedHashMap<TimeUnit,Long>();
  long milliesRest = diffInMillies;
  for ( TimeUnit unit : units ) {
    long diff = unit.convert(milliesRest,TimeUnit.MILLISECONDS);
    long diffInMilliesForUnit = unit.toMillis(diff);
    milliesRest = milliesRest - diffInMilliesForUnit;
    result.put(unit,diff);
  }
  return result;
}

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

public Map<String, List<String>> getTableToColumnAccessMap() {
 // Must be deterministic order map for consistent q-test output across Java versions
 Map<String, List<String>> mapping = new LinkedHashMap<String, List<String>>();
 for (Map.Entry<String, Set<String>> entry : tableToColumnAccessMap.entrySet()) {
  List<String> sortedCols = new ArrayList<String>(entry.getValue());
  Collections.sort(sortedCols);
  mapping.put(entry.getKey(), sortedCols);
 }
 return mapping;
}

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

public Arguments()
{
  namedArgs = new LinkedHashMap<>();
  positionalArgs = new ArrayList<>();
}

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

/**
   * {@inheritDoc}
   */
  public Map<TypeDescription, Class<?>> inject(Map<? extends TypeDescription, byte[]> types) {
    Map<String, byte[]> binaryRepresentations = new LinkedHashMap<String, byte[]>();
    for (Map.Entry<? extends TypeDescription, byte[]> entry : types.entrySet()) {
      binaryRepresentations.put(entry.getKey().getName(), entry.getValue());
    }
    Map<String, Class<?>> loadedTypes = injectRaw(binaryRepresentations);
    Map<TypeDescription, Class<?>> result = new LinkedHashMap<TypeDescription, Class<?>>();
    for (TypeDescription typeDescription : types.keySet()) {
      result.put(typeDescription, loadedTypes.get(typeDescription.getName()));
    }
    return result;
  }
}

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

private void update(Map<TopicPartition, S> partitionToState) {
  LinkedHashMap<String, List<TopicPartition>> topicToPartitions = new LinkedHashMap<>();
  for (TopicPartition tp : partitionToState.keySet()) {
    List<TopicPartition> partitions = topicToPartitions.computeIfAbsent(tp.topic(), k -> new ArrayList<>());
    partitions.add(tp);
  }
  for (Map.Entry<String, List<TopicPartition>> entry : topicToPartitions.entrySet()) {
    for (TopicPartition tp : entry.getValue()) {
      S state = partitionToState.get(tp);
      map.put(tp, state);
    }
  }
}

代码示例来源:origin: stackoverflow.com

Map<String,String> map=new LinkedHashMap<>();
map.put("Active","33");
map.put("Renewals Completed","3");
map.put("Application","15");
Map.Entry<String,String> entry=map.entrySet().iterator().next();
String key= entry.getKey();
String value=entry.getValue();
System.out.println(key);
System.out.println(value);

代码示例来源:origin: spring-projects/spring-framework

@SuppressWarnings({"unchecked", "rawtypes"})
protected void visitMap(Map<?, ?> mapVal) {
  Map newContent = new LinkedHashMap();
  boolean entriesModified = false;
  for (Map.Entry entry : mapVal.entrySet()) {
    Object key = entry.getKey();
    int keyHash = (key != null ? key.hashCode() : 0);
    Object newKey = resolveValue(key);
    int newKeyHash = (newKey != null ? newKey.hashCode() : 0);
    Object val = entry.getValue();
    Object newVal = resolveValue(val);
    newContent.put(newKey, newVal);
    entriesModified = entriesModified || (newVal != val || newKey != key || newKeyHash != keyHash);
  }
  if (entriesModified) {
    mapVal.clear();
    mapVal.putAll(newContent);
  }
}

代码示例来源:origin: square/okhttp

public void run() throws Exception {
 Map<String, String> requestBody = new LinkedHashMap<>();
 requestBody.put("longUrl", "https://publicobject.com/2014/12/04/html-formatting-javadocs/");
 RequestBody jsonRequestBody = RequestBody.create(
   MEDIA_TYPE_JSON, mapJsonAdapter.toJson(requestBody));
 Request request = new Request.Builder()
   .url("https://www.googleapis.com/urlshortener/v1/url?key=" + GOOGLE_API_KEY)
   .post(jsonRequestBody)
   .build();
 try (Response response = client.newCall(request).execute()) {
  if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  System.out.println(response.body().string());
 }
}

代码示例来源:origin: prestodb/presto

public Collection<Set<T>> getEquivalentClasses()
  {
    // map from root element to all element in the tree
    Map<T, Set<T>> rootToTreeElements = new LinkedHashMap<>();
    for (Map.Entry<T, Entry<T>> entry : map.entrySet()) {
      T node = entry.getKey();
      T root = findInternal(node);
      rootToTreeElements.computeIfAbsent(root, unused -> new LinkedHashSet<>());
      rootToTreeElements.get(root).add(node);
    }
    return rootToTreeElements.values();
  }
}

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

private void putAll(Iterable<Entry<K, V>> entries) {
 Map<K, V> map = new LinkedHashMap<>();
 for (Entry<K, V> entry : entries) {
  map.put(entry.getKey(), entry.getValue());
 }
 getMap().putAll(map);
}

代码示例来源:origin: square/leakcanary

private Map<String, Map<String, Exclusion>> unmodifiableRefStringMap(
  Map<String, Map<String, ParamsBuilder>> mapmap) {
 LinkedHashMap<String, Map<String, Exclusion>> fieldNameByClassName = new LinkedHashMap<>();
 for (Map.Entry<String, Map<String, ParamsBuilder>> entry : mapmap.entrySet()) {
  fieldNameByClassName.put(entry.getKey(), unmodifiableRefMap(entry.getValue()));
 }
 return unmodifiableMap(fieldNameByClassName);
}

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

/** @return a copy of the internal {@link Map} that maps {@link MediaItem}s to their children. */
 public Map<MediaItem, List<MediaItem>> getCopyOfMediaItemChildren() {
  final Map<MediaItem, List<MediaItem>> copyOfMediaItemChildren = new LinkedHashMap<>();
  for (MediaItem parent : mediaItemChildren.keySet()) {
   List<MediaItem> children = new ArrayList<>(mediaItemChildren.get(parent));
   copyOfMediaItemChildren.put(parent, children);
  }
  return copyOfMediaItemChildren;
 }
}

代码示例来源:origin: JakeWharton/butterknife

public void addMethodBinding(ListenerClass listener, ListenerMethod method,
  MethodViewBinding binding) {
 Map<ListenerMethod, Set<MethodViewBinding>> methods = methodBindings.get(listener);
 Set<MethodViewBinding> set = null;
 if (methods == null) {
  methods = new LinkedHashMap<>();
  methodBindings.put(listener, methods);
 } else {
  set = methods.get(method);
 }
 if (set == null) {
  set = new LinkedHashSet<>();
  methods.put(method, set);
 }
 set.add(binding);
}

代码示例来源:origin: square/leakcanary

private Map<String, Exclusion> unmodifiableRefMap(Map<String, ParamsBuilder> fieldBuilderMap) {
 Map<String, Exclusion> fieldMap = new LinkedHashMap<>();
 for (Map.Entry<String, ParamsBuilder> fieldEntry : fieldBuilderMap.entrySet()) {
  fieldMap.put(fieldEntry.getKey(), new Exclusion(fieldEntry.getValue()));
 }
 return unmodifiableMap(fieldMap);
}

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

private Map configAsJson(Iterable<StageConfigurationModel> stages) {
  List jsonList = new ArrayList();
  for (StageConfigurationModel stageInfo : stages) {
    Map<String, Object> jsonMap = new LinkedHashMap<>();
    jsonMap.put("name", stageInfo.getName());
    jsonMap.put("isAutoApproved", valueOf(stageInfo.isAutoApproved()));
    jsonList.add(jsonMap);
  }
  Map<String, Object> jsonMap = new LinkedHashMap<>();
  jsonMap.put("stages", jsonList);
  return jsonMap;
}

代码示例来源:origin: square/okhttp

private static Map<ByteString, Integer> nameToFirstIndex() {
 Map<ByteString, Integer> result = new LinkedHashMap<>(STATIC_HEADER_TABLE.length);
 for (int i = 0; i < STATIC_HEADER_TABLE.length; i++) {
  if (!result.containsKey(STATIC_HEADER_TABLE[i].name)) {
   result.put(STATIC_HEADER_TABLE[i].name, i);
  }
 }
 return Collections.unmodifiableMap(result);
}

相关文章