java类com.google.common.collect.ListMultimap的实例源码

JvmComponentPlugin.java 文件源码 项目:Reer 阅读 26 收藏 0 点赞 0 评论 0
private static ListMultimap<String, LocalJava> indexByPath(ModelMap<LocalJava> localJavaInstalls) {
    final ListMultimap<String, LocalJava> index = ArrayListMultimap.create();
    for (LocalJava localJava : localJavaInstalls) {
        try {
            index.put(localJava.getPath().getCanonicalPath(), localJava);
        } catch (IOException e) {
            // ignore this installation for validation, it will be caught later
        }
    }
    return index;
}
IvyModuleDescriptorConverter.java 文件源码 项目:Reer 阅读 19 收藏 0 点赞 0 评论 0
private static void addDependency(List<IvyDependencyMetadata> result, DependencyDescriptor dependencyDescriptor) {
    ModuleRevisionId revisionId = dependencyDescriptor.getDependencyRevisionId();
    ModuleVersionSelector requested = DefaultModuleVersionSelector.newSelector(revisionId.getOrganisation(), revisionId.getName(), revisionId.getRevision());

    ListMultimap<String, String> configMappings = ArrayListMultimap.create();
    for (Map.Entry<String, List<String>> entry : readConfigMappings(dependencyDescriptor).entrySet()) {
        configMappings.putAll(entry.getKey(), entry.getValue());
    }

    List<Artifact> artifacts = Lists.newArrayList();
    for (DependencyArtifactDescriptor ivyArtifact : dependencyDescriptor.getAllDependencyArtifacts()) {
        IvyArtifactName ivyArtifactName = new DefaultIvyArtifactName(ivyArtifact.getName(), ivyArtifact.getType(), ivyArtifact.getExt(), (String) ivyArtifact.getExtraAttributes().get(CLASSIFIER));
        artifacts.add(new Artifact(ivyArtifactName, Sets.newHashSet(ivyArtifact.getConfigurations())));
    }

    List<Exclude> excludes = Lists.newArrayList();
    for (ExcludeRule excludeRule : dependencyDescriptor.getAllExcludeRules()) {
        excludes.add(forIvyExclude(excludeRule));
    }

    result.add(new IvyDependencyMetadata(
        requested,
        dependencyDescriptor.getDynamicConstraintDependencyRevisionId().getRevision(),
        false,
        dependencyDescriptor.isChanging(),
        dependencyDescriptor.isTransitive(),
        configMappings,
        artifacts,
        excludes));
}
ComponentAttributeMatcher.java 文件源码 项目:Reer 阅读 24 收藏 0 点赞 0 评论 0
private List<HasAttributes> selectClosestMatches(List<HasAttributes> fullMatches) {
    Set<Attribute<?>> requestedAttributes = consumerAttributesContainer.keySet();
    // if there's more than one compatible match, prefer the closest. However there's a catch.
    // We need to look at all candidates globally, and select the closest match for each attribute
    // then see if there's a non-empty intersection.
    List<HasAttributes> remainingMatches = Lists.newArrayList(fullMatches);
    List<HasAttributes> best = Lists.newArrayListWithCapacity(fullMatches.size());
    final ListMultimap<AttributeValue<Object>, HasAttributes> candidatesByValue = ArrayListMultimap.create();
    for (Attribute<?> attribute : requestedAttributes) {
        Object requestedValue = consumerAttributesContainer.getAttribute(attribute);
        for (HasAttributes match : fullMatches) {
            Map<Attribute<Object>, AttributeValue<Object>> matchedAttributes = matchDetails.get(match).matchesByAttribute;
            candidatesByValue.put(matchedAttributes.get(attribute), match);
        }
        final AttributeValue<Object> requested = AttributeValue.of(requestedValue);
        disambiguate(remainingMatches, candidatesByValue, requested, consumerAttributeSchema.getMatchingStrategy(attribute), best);
        if (remainingMatches.isEmpty()) {
            // the intersection is empty, so we cannot choose
            return fullMatches;
        }
        candidatesByValue.clear();
        best.clear();
    }
    if (!remainingMatches.isEmpty()) {
        // there's a subset (or not) of best matches
        return remainingMatches;
    }
    return null;
}
ComponentAttributeMatcher.java 文件源码 项目:Reer 阅读 21 收藏 0 点赞 0 评论 0
private static void disambiguate(List<HasAttributes> remainingMatches,
                                 ListMultimap<AttributeValue<Object>, HasAttributes> candidatesByValue,
                                 AttributeValue<Object> requested,
                                 AttributeMatchingStrategy<?> matchingStrategy,
                                 List<HasAttributes> best) {
    AttributeMatchingStrategy<Object> ms = Cast.uncheckedCast(matchingStrategy);
    MultipleCandidatesDetails<Object> details = new CandidateDetails(requested, candidatesByValue, best);
    DisambiguationRuleChainInternal<Object> disambiguationRules = (DisambiguationRuleChainInternal<Object>) ms.getDisambiguationRules();
    disambiguationRules.execute(details);
    remainingMatches.retainAll(best);
}
TestTablePermissions.java 文件源码 项目:ditb 阅读 23 收藏 0 点赞 0 评论 0
public void checkMultimapEqual(ListMultimap<String,TablePermission> first,
    ListMultimap<String,TablePermission> second) {
  assertEquals(first.size(), second.size());
  for (String key : first.keySet()) {
    List<TablePermission> firstPerms = first.get(key);
    List<TablePermission> secondPerms = second.get(key);
    assertNotNull(secondPerms);
    assertEquals(firstPerms.size(), secondPerms.size());
    LOG.info("First permissions: "+firstPerms.toString());
    LOG.info("Second permissions: "+secondPerms.toString());
    for (TablePermission p : firstPerms) {
      assertTrue("Permission "+p.toString()+" not found", secondPerms.contains(p));
    }
  }
}
TestTablePermissions.java 文件源码 项目:ditb 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Test we can read permissions serialized with Writables.
 * @throws DeserializationException
 */
@Test
public void testMigration() throws DeserializationException {
  Configuration conf = UTIL.getConfiguration();
  ListMultimap<String,TablePermission> permissions = createPermissions();
  byte [] bytes = writePermissionsAsBytes(permissions, conf);
  AccessControlLists.readPermissions(bytes, conf);
}
Wrapper.java 文件源码 项目:dremio-oss 阅读 24 收藏 0 点赞 0 评论 0
public void assignEndpoints(ParallelizationParameters parameters, List<NodeEndpoint> assignedEndpoints) throws
    PhysicalOperatorSetupException {
  Preconditions.checkState(!endpointsAssigned);
  endpointsAssigned = true;

  endpoints.addAll(assignedEndpoints);

  final Map<GroupScan, List<CompleteWork>> splitMap = stats.getSplitMap();
  for(GroupScan scan : splitMap.keySet()){
    final ListMultimap<Integer, CompleteWork> assignments;
    if (stats.getDistributionAffinity() == DistributionAffinity.HARD) {
      assignments = HardAssignmentCreator.INSTANCE.getMappings(endpoints, splitMap.get(scan));
    } else {
      if (parameters.useNewAssignmentCreator()) {
        assignments = AssignmentCreator2.getMappings(endpoints, splitMap.get(scan),
            parameters.getAssignmentCreatorBalanceFactor()
        );
      } else {
        assignments = AssignmentCreator.getMappings(endpoints, splitMap.get(scan));
      }
    }
    splitSets.put(scan, assignments);
  }

  // Set the endpoints for this (one at most) sending exchange.
  if (node.getSendingExchange() != null) {
    node.getSendingExchange().setupSenders(majorFragmentId, endpoints);
  }

  // Set the endpoints for each incoming exchange within this fragment.
  for (ExchangeFragmentPair e : node.getReceivingExchangePairs()) {
    e.getExchange().setupReceivers(majorFragmentId, endpoints);
  }
}
CycleDetectingLock.java 文件源码 项目:businessworks 阅读 31 收藏 0 点赞 0 评论 0
@Override public ListMultimap<Long, ID> lockOrDetectPotentialLocksCycle() {
  final long currentThreadId = Thread.currentThread().getId();
  synchronized (CycleDetectingLockFactory.class) {
    checkState();
    ListMultimap<Long, ID> locksInCycle = detectPotentialLocksCycle();
    if (!locksInCycle.isEmpty()) {
      // potential deadlock is found, we don't try to take this lock
      return locksInCycle;
    }

    lockThreadIsWaitingOn.put(currentThreadId, this);
  }

  // this may be blocking, but we don't expect it to cause a deadlock
  lockImplementation.lock();

  synchronized (CycleDetectingLockFactory.class) {
    // current thread is no longer waiting on this lock
    lockThreadIsWaitingOn.remove(currentThreadId);
    checkState();

    // mark it as owned by us
    lockOwnerThreadId = currentThreadId;
    lockReentranceCount++;
    // add this lock to the list of locks owned by a current thread
    locksOwnedByThread.put(currentThreadId, this);
  }
  // no deadlock is found, locking successful
  return ImmutableListMultimap.of();
}
TestTablePermissions.java 文件源码 项目:ditb 阅读 19 收藏 0 点赞 0 评论 0
@Test
public void testGlobalPermission() throws Exception {
  Configuration conf = UTIL.getConfiguration();

  // add some permissions
  AccessControlLists.addUserPermission(conf,
      new UserPermission(Bytes.toBytes("user1"),
          Permission.Action.READ, Permission.Action.WRITE));
  AccessControlLists.addUserPermission(conf,
      new UserPermission(Bytes.toBytes("user2"),
          Permission.Action.CREATE));
  AccessControlLists.addUserPermission(conf,
      new UserPermission(Bytes.toBytes("user3"),
          Permission.Action.ADMIN, Permission.Action.READ, Permission.Action.CREATE));

  ListMultimap<String,TablePermission> perms = AccessControlLists.getTablePermissions(conf, null);
  List<TablePermission> user1Perms = perms.get("user1");
  assertEquals("Should have 1 permission for user1", 1, user1Perms.size());
  assertEquals("user1 should have WRITE permission",
               new Permission.Action[] { Permission.Action.READ, Permission.Action.WRITE },
               user1Perms.get(0).getActions());

  List<TablePermission> user2Perms = perms.get("user2");
  assertEquals("Should have 1 permission for user2", 1, user2Perms.size());
  assertEquals("user2 should have CREATE permission",
               new Permission.Action[] { Permission.Action.CREATE },
               user2Perms.get(0).getActions());

  List<TablePermission> user3Perms = perms.get("user3");
  assertEquals("Should have 1 permission for user3", 1, user3Perms.size());
  assertEquals("user3 should have ADMIN, READ, CREATE permission",
               new Permission.Action[] {
                  Permission.Action.ADMIN, Permission.Action.READ, Permission.Action.CREATE
               },
               user3Perms.get(0).getActions());
}
AssignmentCreator2.java 文件源码 项目:dremio-oss 阅读 19 收藏 0 点赞 0 评论 0
ListMultimap<Integer,T> makeAssignments() {
  List<WorkWrapper> unassigned = new ArrayList<>();

  for (WorkWrapper work : workList) {
    boolean assigned = assignWork(work);
    if (!assigned) {
      unassigned.add(work);
    }
  }

  assignLeftOvers(unassigned);

  ListMultimap<Integer,T> result = ArrayListMultimap.create();

  final AtomicInteger workCount = new AtomicInteger(0);

  for (FragmentWork fragment : getFragments()) {
    result.putAll(fragment.fragmentId, Lists.transform(fragment.workList, new Function<WorkWrapper, T>() {
      @Override
      public T apply(WorkWrapper workWrapper) {
        workCount.incrementAndGet();
        return workWrapper.work;
      }
    }));
  }
  Preconditions.checkState(workCount.get() == workList.size());
  return result;
}


问题


面经


文章

微信
公众号

扫码关注公众号