Tabnine Logo
LinkedHashMap
Code IndexAdd Tabnine to your IDE (free)

How to use
LinkedHashMap
in
java.util

Best Java code snippets using java.util.LinkedHashMap (Showing top 20 results out of 76,509)

origin: spring-projects/spring-framework

@Override
public Map<String, String> toSingleValueMap() {
  LinkedHashMap<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size());
  this.headers.forEach((key, value) -> singleValueMap.put(key, value.get(0)));
  return singleValueMap;
}
origin: apache/kafka

@Override
public V get(K key) {
  return cache.get(key);
}
origin: google/guava

@Override
public Iterable<Entry<K, Collection<V>>> order(List<Entry<K, Collection<V>>> insertionOrder) {
 Map<K, Collection<V>> map = new HashMap<>();
 List<Entry<K, V>> builder = new ArrayList<>();
 for (Entry<K, Collection<V>> entry : insertionOrder) {
  for (V v : entry.getValue()) {
   builder.add(mapEntry(entry.getKey(), v));
  }
  map.put(entry.getKey(), entry.getValue());
 }
 Iterable<Entry<K, V>> ordered = multimapGenerator.order(builder);
 LinkedHashMap<K, Collection<V>> orderedMap = new LinkedHashMap<>();
 for (Entry<K, V> entry : ordered) {
  orderedMap.put(entry.getKey(), map.get(entry.getKey()));
 }
 return orderedMap.entrySet();
}
origin: apache/kafka

public void moveToEnd(TopicPartition topicPartition) {
  S state = map.remove(topicPartition);
  if (state != null)
    map.put(topicPartition, state);
}
origin: lipangit/JiaoZiVideoPlayer

public Object getValueFromLinkedMap(int index) {
  int currentIndex = 0;
  for (Object key : urlsMap.keySet()) {
    if (currentIndex == index) {
      return urlsMap.get(key);
    }
    currentIndex++;
  }
  return null;
}
origin: google/guava

 @Override
 protected Map<String, String> create(Entry<String, String>[] entries) {
  return populate(new LinkedHashMap<String, String>(), entries);
 }
})
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: apache/incubator-druid

private void resolveWaitingFutures()
{
 final LinkedHashMap<CustomSettableFuture, Counter> waitingFuturesCopy = new LinkedHashMap<>();
 synchronized (waitingFutures) {
  waitingFuturesCopy.putAll(waitingFutures);
  waitingFutures.clear();
 }
 for (Map.Entry<CustomSettableFuture, Counter> e : waitingFuturesCopy.entrySet()) {
  try {
   e.getKey().set(getRequestsSinceWithoutWait(e.getValue()));
  }
  catch (Exception ex) {
   e.getKey().setException(ex);
  }
 }
}
origin: google/guava

@SuppressWarnings("serial")
public void testLinkedHashMapWithInitialMap() {
 Map<String, String> map =
   new LinkedHashMap<String, String>(
     ImmutableMap.of(
       "Hello", "World",
       "first", "second",
       "polygene", "lubricants",
       "alpha", "betical"));
 LinkedHashMap<String, String> copy = Maps.newLinkedHashMap(map);
 Iterator<Entry<String, String>> iter = copy.entrySet().iterator();
 assertTrue(iter.hasNext());
 Entry<String, String> entry = iter.next();
 assertEquals("Hello", entry.getKey());
 assertEquals("World", entry.getValue());
 assertTrue(iter.hasNext());
 entry = iter.next();
 assertEquals("first", entry.getKey());
 assertEquals("second", entry.getValue());
 assertTrue(iter.hasNext());
 entry = iter.next();
 assertEquals("polygene", entry.getKey());
 assertEquals("lubricants", entry.getValue());
 assertTrue(iter.hasNext());
 entry = iter.next();
 assertEquals("alpha", entry.getKey());
 assertEquals("betical", entry.getValue());
 assertFalse(iter.hasNext());
}
origin: alibaba/druid

public JdbcSqlStat createSqlStat(String sql) {
  lock.writeLock().lock();
  try {
    JdbcSqlStat sqlStat = sqlStatMap.get(sql);
    if (sqlStat == null) {
      sqlStat = new JdbcSqlStat(sql);
      sqlStat.setDbType(this.dbType);
      sqlStat.setName(this.name);
      sqlStatMap.put(sql, sqlStat);
    }
    return sqlStat;
  } finally {
    lock.writeLock().unlock();
  }
}
origin: apache/incubator-dubbo

@Override
public V put(K key, V value) {
  lock.lock();
  try {
    return super.put(key, value);
  } finally {
    lock.unlock();
  }
}
origin: google/guava

@VisibleForTesting
static ImmutableMap<File, ClassLoader> getClassPathEntries(ClassLoader classloader) {
 LinkedHashMap<File, ClassLoader> entries = Maps.newLinkedHashMap();
 // Search parent first, since it's the order ClassLoader#loadClass() uses.
 ClassLoader parent = classloader.getParent();
 if (parent != null) {
  entries.putAll(getClassPathEntries(parent));
 }
 for (URL url : getClassLoaderUrls(classloader)) {
  if (url.getProtocol().equals("file")) {
   File file = toFile(url);
   if (!entries.containsKey(file)) {
    entries.put(file, classloader);
   }
  }
 }
 return ImmutableMap.copyOf(entries);
}
origin: google/guava

public void testSegmentPut_evict() {
 int maxSize = 10;
 LocalCache<Object, Object> map =
   makeLocalCache(createCacheBuilder().concurrencyLevel(1).maximumSize(maxSize));
 // manually add elements to avoid eviction
 int originalCount = 1024;
 LinkedHashMap<Object, Object> originalMap = Maps.newLinkedHashMap();
 for (int i = 0; i < originalCount; i++) {
  Object key = new Object();
  Object value = new Object();
  map.put(key, value);
  originalMap.put(key, value);
  if (i >= maxSize) {
   Iterator<Object> it = originalMap.keySet().iterator();
   it.next();
   it.remove();
  }
  assertEquals(originalMap, map);
 }
}
origin: alibaba/druid

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
  if (list != null && rowIndex < list.size()) {// 没有超出最大行数
    LinkedHashMap<String, Object> dataNow = list.get(rowIndex);
    if (showKeys != null) {
      int titleLen = showKeys.size();
      if (titleLen > 0 && columnIndex < titleLen) {
        return dataNow.get(showKeys.get(columnIndex));
      }
    } else {
      Object[] values = dataNow.values().toArray();
      if (columnIndex < values.length) {
        return values[columnIndex];
      }
    }
  }
  return null;
}
origin: spring-projects/spring-framework

@Override
public Set<Entry<String, V>> entrySet() {
  return this.targetMap.entrySet();
}
origin: spring-projects/spring-framework

@Override
public Set<String> keySet() {
  return this.targetMap.keySet();
}
origin: apache/kafka

private void checkState(PartitionStates<String> states, LinkedHashMap<TopicPartition, String> expected) {
  assertEquals(expected.keySet(), states.partitionSet());
  assertEquals(expected.size(), states.size());
  List<PartitionStates.PartitionState<String>> statesList = new ArrayList<>();
  for (Map.Entry<TopicPartition, String> entry : expected.entrySet()) {
    statesList.add(new PartitionStates.PartitionState<>(entry.getKey(), entry.getValue()));
    assertTrue(states.contains(entry.getKey()));
  }
  assertEquals(statesList, states.partitionStates());
}
origin: alibaba/druid

public List<JdbcSqlStatValue> getRuningSqlList() {
  List<JdbcSqlStat> stats = new ArrayList<JdbcSqlStat>(sqlStatMap.size());
  lock.readLock().lock();
  try {
    for (Map.Entry<String, JdbcSqlStat> entry : sqlStatMap.entrySet()) {
      JdbcSqlStat stat = entry.getValue();
      if (stat.getRunningCount() >= 0) {
        stats.add(entry.getValue());
      }
    }
  } finally {
    lock.readLock().unlock();
  }
  List<JdbcSqlStatValue> values = new ArrayList<JdbcSqlStatValue>(stats.size());
  for (JdbcSqlStat stat : stats) {
    JdbcSqlStatValue value = stat.getValue(false);
    if (value.getRunningCount() > 0) {
      values.add(value);
    }
  }
  return values;
}
origin: spring-projects/spring-framework

@Override
@Nullable
public V computeIfAbsent(String key, Function<? super String, ? extends V> mappingFunction) {
  String oldKey = this.caseInsensitiveKeys.putIfAbsent(convertKey(key), key);
  if (oldKey != null) {
    return this.targetMap.get(oldKey);
  }
  return this.targetMap.computeIfAbsent(key, mappingFunction);
}
origin: spring-projects/spring-framework

@Override
@Nullable
public V putIfAbsent(String key, @Nullable V value) {
  String oldKey = this.caseInsensitiveKeys.putIfAbsent(convertKey(key), key);
  if (oldKey != null) {
    return this.targetMap.get(oldKey);
  }
  return this.targetMap.putIfAbsent(key, value);
}
java.utilLinkedHashMap

Javadoc

LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations are supported.

All elements are permitted as keys or values, including null.

Entries are kept in a doubly-linked list. The iteration order is, by default, the order in which keys were inserted. Reinserting an already-present key doesn't change the order. If the three argument constructor is used, and accessOrder is specified as true, the iteration will be in the order that entries were accessed. The access order is affected by put, get, and putAll operations, but not by operations on the collection views.

Note: the implementation of LinkedHashMap is not synchronized. If one thread of several threads accessing an instance modifies the map structurally, access to the map needs to be synchronized. For insertion-ordered instances a structural modification is an operation that removes or adds an entry. Access-ordered instances also are structurally modified by put, get, and putAll since these methods change the order of the entries. Changes in the value of an entry are not structural changes.

The Iterator created by calling the iterator method may throw a ConcurrentModificationException if the map is structurally changed while an iterator is used to iterate over the elements. Only the remove method that is provided by the iterator allows for removal of elements during iteration. It is not possible to guarantee that this mechanism works in all cases of unsynchronized concurrent modification. It should only be used for debugging purposes.

Most used methods

  • <init>
    Constructs an insertion-ordered LinkedHashMap instance with the same mappings as the specified map.
  • put
  • get
    Returns the value to which the specified key is mapped, or null if this map contains no mapping for
  • entrySet
  • keySet
  • values
  • size
  • remove
  • containsKey
  • clear
    Removes all of the mappings from this map. The map will be empty after this call returns.
  • isEmpty
  • putAll
  • isEmpty,
  • putAll,
  • equals,
  • hashCode,
  • containsValue,
  • toString,
  • clone,
  • forEach,
  • computeIfAbsent,
  • putIfAbsent

Popular in Java

  • Running tasks concurrently on multiple threads
  • requestLocationUpdates (LocationManager)
  • setContentView (Activity)
  • addToBackStack (FragmentTransaction)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now