Tabnine Logo
Map.get
Code IndexAdd Tabnine to your IDE (free)

How to use
get
method
in
java.util.Map

Best Java code snippets using java.util.Map.get (Showing top 20 results out of 357,381)

Refine searchRefine arrow

  • Map.put
  • Map.containsKey
  • List.add
  • Map.keySet
  • List.size
  • List.get
  • Map.Entry.getValue
  • Map.Entry.getKey
canonical example by Tabnine

private void mappingWordsLength(List<String> wordsList) {
 Map<Integer, Set<String>> mapping = new HashMap<>();
 for (String word : wordsList) {
  mapping.computeIfAbsent(word.length(), HashSet::new).add(word);
 }
 List<Integer> lengths = new LinkedList<>(mapping.keySet());
 Collections.sort(lengths);
 lengths.forEach(n -> System.out.println(mapping.get(n).size() + " words with " + n + " chars"));
}
origin: square/okhttp

@Override public List<InetAddress> lookup(String hostname) throws UnknownHostException {
 requestedHosts.add(hostname);
 List<InetAddress> result = hostAddresses.get(hostname);
 if (result != null) return result;
 throw new UnknownHostException();
}
origin: square/retrofit

ServiceMethod<?> loadServiceMethod(Method method) {
 ServiceMethod<?> result = serviceMethodCache.get(method);
 if (result != null) return result;
 synchronized (serviceMethodCache) {
  result = serviceMethodCache.get(method);
  if (result == null) {
   result = ServiceMethod.parseAnnotations(this, method);
   serviceMethodCache.put(method, result);
  }
 }
 return result;
}
origin: spring-projects/spring-framework

/**
 * If the name is the expected name specified in the constructor, return the
 * object provided in the constructor. If the name is unexpected, a
 * respective NamingException gets thrown.
 */
@Override
public Object lookup(String name) throws NamingException {
  Object object = this.jndiObjects.get(name);
  if (object == null) {
    throw new NamingException("Unexpected JNDI name '" + name + "': expecting " + this.jndiObjects.keySet());
  }
  return object;
}
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: square/okhttp

static String extractStatusLine(Map<String, List<String>> javaResponseHeaders)
  throws ProtocolException {
 List<String> values = javaResponseHeaders.get(null);
 if (values == null || values.size() == 0) {
  // The status line is missing. This suggests a badly behaving cache.
  throw new ProtocolException(
    "CacheResponse is missing a \'null\' header containing the status line. Headers="
      + javaResponseHeaders);
 }
 return values.get(0);
}
origin: spring-projects/spring-framework

private byte[] encodeHeaderKey(String input, boolean escape) {
  String inputToUse = (escape ? escape(input) : input);
  if (this.headerKeyAccessCache.containsKey(inputToUse)) {
    return this.headerKeyAccessCache.get(inputToUse);
  }
  synchronized (this.headerKeyUpdateCache) {
    byte[] bytes = this.headerKeyUpdateCache.get(inputToUse);
    if (bytes == null) {
      bytes = inputToUse.getBytes(StandardCharsets.UTF_8);
      this.headerKeyAccessCache.put(inputToUse, bytes);
      this.headerKeyUpdateCache.put(inputToUse, bytes);
    }
    return bytes;
  }
}
origin: apache/kafka

private void createConnectionsMaxReauthMsMap(Map<String, ?> configs) {
  for (String mechanism : jaasContexts.keySet()) {
    String prefix = ListenerName.saslMechanismPrefix(mechanism);
    Long connectionsMaxReauthMs = (Long) configs.get(prefix + BrokerSecurityConfigs.CONNECTIONS_MAX_REAUTH_MS);
    if (connectionsMaxReauthMs == null)
      connectionsMaxReauthMs = (Long) configs.get(BrokerSecurityConfigs.CONNECTIONS_MAX_REAUTH_MS);
    if (connectionsMaxReauthMs != null)
      connectionsMaxReauthMsByMechanism.put(mechanism, connectionsMaxReauthMs);
  }
}
origin: airbnb/lottie-android

private List<ContentGroup> getContentsForCharacter(FontCharacter character) {
 if (contentsForCharacter.containsKey(character)) {
  return contentsForCharacter.get(character);
 }
 List<ShapeGroup> shapes = character.getShapes();
 int size = shapes.size();
 List<ContentGroup> contents = new ArrayList<>(size);
 for (int i = 0; i < size; i++) {
  ShapeGroup sg = shapes.get(i);
  contents.add(new ContentGroup(lottieDrawable, this, sg));
 }
 contentsForCharacter.put(character, contents);
 return contents;
}
origin: jenkinsci/jenkins

private List<AbstractProject> get(Map<AbstractProject, List<DependencyGroup>> map, AbstractProject src, boolean up) {
  List<DependencyGroup> v = map.get(src);
  if(v==null) return Collections.emptyList();
  List<AbstractProject> result = new ArrayList<AbstractProject>(v.size());
  for (DependencyGroup d : v) result.add(up ? d.getUpstreamProject() : d.getDownstreamProject());
  return result;
}
origin: alibaba/druid

public static String getVerticalFormattedOutput(List<Map<String, Object>> content, String[] titleFields) {
  List<String[]> printContents = new ArrayList<String[]>();
  int maxCol = content.size() > MAX_COL ? MAX_COL : content.size();
  for (String titleField : titleFields) {
    String[] row = new String[maxCol + 1];
    row[0] = titleField;
    for (int j = 0; j < maxCol; j++) {
      Map<String, Object> sqlStat = content.get(j);
      Object value = sqlStat.get(titleField);
      row[j + 1] = handleAndConvert(value, titleField);
    }
    printContents.add(row);
  }
  return TableFormatter.format(printContents);
}
origin: hankcs/HanLP

public int addCategory(String category)
{
  Integer id = categoryId.get(category);
  if (id == null)
  {
    id = categoryId.size();
    categoryId.put(category, id);
    assert idCategory.size() == id;
    idCategory.add(category);
  }
  return id;
}
origin: spring-projects/spring-framework

/**
 * Add an option argument for the given option name and add the given value to the
 * list of values associated with this option (of which there may be zero or more).
 * The given value may be {@code null}, indicating that the option was specified
 * without an associated value (e.g. "--foo" vs. "--foo=bar").
 */
public void addOptionArg(String optionName, @Nullable String optionValue) {
  if (!this.optionArgs.containsKey(optionName)) {
    this.optionArgs.put(optionName, new ArrayList<>());
  }
  if (optionValue != null) {
    this.optionArgs.get(optionName).add(optionValue);
  }
}
origin: google/guava

 @Override
 public Iterable<Entry<E>> order(List<Entry<E>> insertionOrder) {
  // We mimic the order from gen.
  Map<E, Entry<E>> map = new LinkedHashMap<>();
  for (Entry<E> entry : insertionOrder) {
   map.put(entry.getElement(), entry);
  }
  Set<E> seen = new HashSet<>();
  List<Entry<E>> order = new ArrayList<>();
  for (E e : gen.order(new ArrayList<E>(map.keySet()))) {
   if (seen.add(e)) {
    order.add(map.get(e));
   }
  }
  return order;
 }
}
origin: spring-projects/spring-framework

@Test
public void testGenericTypeNestingListOfMapOfInteger() throws Exception {
  List<Map<String, String>> list = new LinkedList<>();
  Map<String, String> map = new HashMap<>();
  map.put("testKey", "5");
  list.add(map);
  NestedGenericCollectionBean gb = new NestedGenericCollectionBean();
  BeanWrapper bw = new BeanWrapperImpl(gb);
  bw.setPropertyValue("listOfMapOfInteger", list);
  Object obj = gb.getListOfMapOfInteger().get(0).get("testKey");
  assertTrue(obj instanceof Integer);
  assertEquals(5, ((Integer) obj).intValue());
}
origin: robolectric/robolectric

@Implementation(minSdk = JELLY_BEAN_MR2)
protected Account[] getAccountsByTypeForPackage(String type, String packageName) {
 List<Account> result = new ArrayList<>();
 Account[] accountsByType = getAccountsByType(type);
 for (Account account : accountsByType) {
  if (packageVisibileAccounts.containsKey(account) && packageVisibileAccounts.get(account).contains(packageName)) {
   result.add(account);
  }
 }
 return result.toArray(new Account[result.size()]);
}
origin: spring-projects/spring-framework

@Nullable
private Object getNativeHeaderValue(Message<?> message, String name) {
  Map<String, List<String>> nativeHeaders = getNativeHeaders(message);
  if (name.startsWith("nativeHeaders.")) {
    name = name.substring("nativeHeaders.".length());
  }
  if (nativeHeaders == null || !nativeHeaders.containsKey(name)) {
    return null;
  }
  List<?> nativeHeaderValues = nativeHeaders.get(name);
  return (nativeHeaderValues.size() == 1 ? nativeHeaderValues.get(0) : nativeHeaderValues);
}
origin: spring-projects/spring-framework

@Test
public void testGenericListOfMaps() throws MalformedURLException {
  GenericBean<String> gb = new GenericBean<>();
  List<Map<Integer, Long>> list = new LinkedList<>();
  list.add(new HashMap<>());
  gb.setListOfMaps(list);
  BeanWrapper bw = new BeanWrapperImpl(gb);
  bw.setPropertyValue("listOfMaps[0][10]", new Long(5));
  assertEquals(new Long(5), bw.getPropertyValue("listOfMaps[0][10]"));
  assertEquals(new Long(5), gb.getListOfMaps().get(0).get(10));
}
origin: spring-projects/spring-framework

private void updateBindingContext(BindingContext context, ServerWebExchange exchange) {
  Map<String, Object> model = context.getModel().asMap();
  model.keySet().stream()
      .filter(name -> isBindingCandidate(name, model.get(name)))
      .filter(name -> !model.containsKey(BindingResult.MODEL_KEY_PREFIX + name))
      .forEach(name -> {
        WebExchangeDataBinder binder = context.createDataBinder(exchange, model.get(name), name);
        model.put(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult());
      });
}
origin: spring-projects/spring-framework

  @Override
  protected List<Entry> buildFeedEntries(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
    List<Entry> entries = new ArrayList<>();
    for (String name : model.keySet()) {
      Entry entry = new Entry();
      entry.setTitle(name);
      Content content = new Content();
      content.setValue((String) model.get(name));
      entry.setSummary(content);
      entries.add(entry);
    }
    return entries;
  }
}
java.utilMapget

Javadoc

Returns the value of the mapping with the specified key.

Popular methods of Map

  • put
    Maps the specified key to the specified value.
  • entrySet
    Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes t
  • containsKey
    Returns whether this Map contains the specified key.
  • keySet
    Returns a set of the keys contained in this Map. The Set is backed by this Map so changes to one are
  • values
    Returns a Collection view of the values contained in this map. The collection is backed by the map,
  • remove
  • size
    Returns the number of mappings in this Map.
  • isEmpty
    Returns true if this map contains no key-value mappings.
  • clear
    Removes all elements from this Map, leaving it empty.
  • putAll
    Copies all of the mappings from the specified map to this map (optional operation). The effect of th
  • forEach
  • equals
    Compares the argument to the receiver, and returns true if the specified object is a Map and both Ma
  • forEach,
  • equals,
  • computeIfAbsent,
  • hashCode,
  • getOrDefault,
  • containsValue,
  • putIfAbsent,
  • compute,
  • merge

Popular in Java

  • Making http post requests using okhttp
  • getContentResolver (Context)
  • getResourceAsStream (ClassLoader)
  • findViewById (Activity)
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Top Sublime Text plugins
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