當前位置: 首頁>>代碼示例>>Java>>正文


Java ListMultimap.containsKey方法代碼示例

本文整理匯總了Java中com.google.common.collect.ListMultimap.containsKey方法的典型用法代碼示例。如果您正苦於以下問題:Java ListMultimap.containsKey方法的具體用法?Java ListMultimap.containsKey怎麽用?Java ListMultimap.containsKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.collect.ListMultimap的用法示例。


在下文中一共展示了ListMultimap.containsKey方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getMappings

import com.google.common.collect.ListMultimap; //導入方法依賴的package包/類
public <T extends CompleteWork> ListMultimap<Integer, T> getMappings(
    final List<NodeEndpoint> endpoints, final List<T> units) throws PhysicalOperatorSetupException {
  verify(endpoints, units, units.size() >= endpoints.size(), "There should be at least one work unit for each hard affinity node.");

  // First, group endpoints by hostname. There could be multiple endpoints on same host
  final ListMultimap<String, Integer> endpointsOnHostMap = ArrayListMultimap.create();
  int index = 0;
  for(NodeEndpoint incoming : endpoints) {
    endpointsOnHostMap.put(incoming.getAddress(), index);
    index++;
  }

  // Convert the multi-map <String,Integer> into a map <String, Iterator<Integer>>
  final Map<String, Iterator<Integer>> endpointIteratorOnHostMap = Maps.newHashMap();
  for(Map.Entry<String, Collection<Integer>> entry: endpointsOnHostMap.asMap().entrySet()) {
    endpointIteratorOnHostMap.put(entry.getKey(), Iterables.cycle(entry.getValue()).iterator());
  }

  final ListMultimap<Integer, T> mappings = ArrayListMultimap.create();
  for(T unit: units) {
    final List<EndpointAffinity> affinities = unit.getAffinity();
    verify(endpoints, units, affinities.size() == 1,
        "Expected the hard affinity work unit to have affinity to only one endpoint");
    final EndpointAffinity endpointAffinity = affinities.get(0);
    final String host = endpointAffinity.getEndpoint().getAddress();
    final Iterator<Integer> endpointsOnHost = endpointIteratorOnHostMap.get(host);
    if (endpointsOnHost == null) {
      verify(endpoints, units, false, "There are no endpoints in assigned list running on host %s", host);
    }

    final int endpointId = endpointIteratorOnHostMap.get(host).next();
    mappings.put(endpointId, unit);
  }

  // Go through the mappings and make sure at least one unit for every assigned endpoint,
  // otherwise we will end up with fragments that don't have any work assigned. If an assignment is not present for
  // endpoint, throw an exception
  for(int i = 0; i < endpoints.size(); i++) {
    if (!mappings.containsKey(i)) {
      verify(endpoints, units, false, "Endpoint %s has no assigned work.", endpoints.get(i));
    }
  }

  return mappings;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:46,代碼來源:HardAssignmentCreator.java


注:本文中的com.google.common.collect.ListMultimap.containsKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。