Java 类com.google.common.collect.ListMultimap 实例源码

项目:Reer    文件:GradlePomModuleDescriptorBuilder.java   
public void addDependencyForRelocation(ModuleVersionSelector selector) {

        // Some POMs depend on themselves through their parent POM, don't add this dependency
        // since Ivy doesn't allow this!
        // Example: http://repo2.maven.org/maven2/com/atomikos/atomikos-util/3.6.4/atomikos-util-3.6.4.pom
        if (selector.getGroup().equals(descriptor.getComponentIdentifier().getGroup())
            && selector.getName().equals(descriptor.getComponentIdentifier().getModule())) {
            return;
        }

        // TODO - this is a constant
        ListMultimap<String, String> confMappings = ArrayListMultimap.create();
        // Map dependency on all public configurations
        for (Configuration m2Conf : GradlePomModuleDescriptorBuilder.MAVEN2_CONFIGURATIONS.values()) {
            if (m2Conf.isVisible()) {
                confMappings.put(m2Conf.getName(), m2Conf.getName());
            }
        }

        dependencies.add(new IvyDependencyMetadata(selector, confMappings));
    }
项目:Reer    文件:TaskDetailPrinter.java   
private ListMultimap<Class, Task> groupTasksByType(List<Task> tasks) {
    final Set<Class> taskTypes = new TreeSet<Class>(new Comparator<Class>() {
        public int compare(Class o1, Class o2) {
            return o1.getSimpleName().compareTo(o2.getSimpleName());
        }
    });
    taskTypes.addAll(collect(tasks, new Transformer<Class, Task>() {
        public Class transform(Task original) {
            return getDeclaredTaskType(original);
        }
    }));

    ListMultimap<Class, Task> tasksGroupedByType = ArrayListMultimap.create();
    for (final Class taskType : taskTypes) {
        tasksGroupedByType.putAll(taskType, filter(tasks, new Spec<Task>() {
            public boolean isSatisfiedBy(Task element) {
                return getDeclaredTaskType(element).equals(taskType);
            }
        }));
    }
    return tasksGroupedByType;
}
项目:ditb    文件:AccessController.java   
void initialize(RegionCoprocessorEnvironment e) throws IOException {
  final Region region = e.getRegion();
  Configuration conf = e.getConfiguration();
  Map<byte[], ListMultimap<String,TablePermission>> tables =
      AccessControlLists.loadAll(region);
  // For each table, write out the table's permissions to the respective
  // znode for that table.
  for (Map.Entry<byte[], ListMultimap<String,TablePermission>> t:
    tables.entrySet()) {
    byte[] entry = t.getKey();
    ListMultimap<String,TablePermission> perms = t.getValue();
    byte[] serialized = AccessControlLists.writePermissionsAsBytes(perms, conf);
    this.authManager.getZKPermissionWatcher().writeToZookeeper(entry, serialized);
  }
  initialized = true;
}
项目:dremio-oss    文件:TestHardAssignmentCreator.java   
@Test
public void twoFilesOnSameHost() throws Exception {
  final List<CompleteWork> workUnits = asList(
      newWork("/10.0.0.1/table/foo1", 1024, ENDPOINT_1_1, 0.33),
      newWork("/10.0.0.1/table/foo2", 2048, ENDPOINT_1_2, 0.66)
  );

  ListMultimap<Integer, CompleteWork> mappings;
  List<NodeEndpoint> endpoints;

  endpoints = asList(ENDPOINT_1_1, ENDPOINT_1_2);
  mappings = INSTANCE.getMappings(endpoints, workUnits);
  verifyAssignments(mappings, endpoints, workUnits);

  // Assign only one endpoint from 10.0.0.1
  endpoints = asList(ENDPOINT_1_2);
  mappings = INSTANCE.getMappings(endpoints, workUnits);
  verifyAssignments(mappings, endpoints, workUnits);

  // Negative case - fails because the assigned list contains ENDPOINTS running on 10.0.0.2, but there are no files on
  // 10.0.0.2
  verifyAssignmentFails(workUnits, ENDPOINT_1_1, ENDPOINT_2_1);
}
项目:n4js    文件:PolyfillValidatorFragment.java   
/**
 * Find clashes by name.
 *
 * @param myPolyMember
 *            current validated Polyfill
 * @param pivotPolyMember
 *            other polyfill in same project
 * @return pairs of contrandicting or same polyfills.
 */
private ListMultimap<TMember, TMember> findClashingMembersByName(EList<TMember> myPolyMember,
        EList<TMember> pivotPolyMember) {
    ListMultimap<TMember, TMember> ret = LinkedListMultimap.create();
    for (TMember my : myPolyMember) {
        String myName = my.getName();
        if (myName == null)
            continue; // broken AST
        for (TMember other : pivotPolyMember) {
            String otherName = other.getName();
            if (myName.equals(otherName)) {
                ret.put(my, other);
            }
        }
    }
    return ret;
}
项目:memory-graph    文件:MatchClauseExecutor.java   
private boolean vertexIsMatch(
        MemgraphCypherQueryContext ctx,
        Vertex vertex,
        List<String> labelNames,
        ListMultimap<String, CypherAstBase> propertiesMap,
        ExpressionScope scope
) {
    Set<String> vertexLabelNames = ctx.getVertexLabels(vertex);
    for (String labelName : labelNames) {
        if (!vertexLabelNames.contains(labelName)) {
            return false;
        }
    }

    return propertyMapMatch(ctx, vertex, propertiesMap, scope);
}
项目:guava-mock    文件:ListMultimapTestSuiteBuilder.java   
@Override
TestSuite computeMultimapAsMapGetTestSuite(
    FeatureSpecificTestSuiteBuilder<
            ?, ? extends OneSizeTestContainerGenerator<ListMultimap<K, V>, Entry<K, V>>>
        parentBuilder) {
  Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
  if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
    return new TestSuite();
  } else {
    return ListTestSuiteBuilder.using(
            new MultimapAsMapGetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
        .withFeatures(features)
        .named(parentBuilder.getName() + ".asMap[].get[key]")
        .suppressing(parentBuilder.getSuppressedTests())
        .createTestSuite();
  }
}
项目:googles-monorepo-demo    文件:ListMultimapEqualsTester.java   
@CollectionSize.Require(SEVERAL)
public void testOrderingAffectsEqualsComparisons() {
  ListMultimap<K, V> multimap1 =
      getSubjectGenerator()
          .create(
              Helpers.mapEntry(k0(), v0()),
              Helpers.mapEntry(k0(), v1()),
              Helpers.mapEntry(k0(), v0()));
  ListMultimap<K, V> multimap2 =
      getSubjectGenerator()
          .create(
              Helpers.mapEntry(k0(), v1()),
              Helpers.mapEntry(k0(), v0()),
              Helpers.mapEntry(k0(), v0()));
  new EqualsTester().addEqualityGroup(multimap1).addEqualityGroup(multimap2).testEquals();
}
项目:dremio-oss    文件:TestHardAssignmentCreator.java   
private static final void verifyAssignments(ListMultimap<Integer, CompleteWork> assignments,
    List<NodeEndpoint> inputEps, List<CompleteWork> inputWorks) {
  final String summary = summary(assignments, inputEps, inputWorks);
  final Set<CompleteWork> assignedSet = Sets.newHashSet(assignments.values());
  for(CompleteWork cw : inputWorks) {
    assertTrue("Input work not present in assigned work unit list: " + summary,
        assignedSet.contains(cw));
    assertTrue(summary, assignedSet.remove(cw));
  }

  assertTrue("There are some extra works in assigned work unit list: " + summary, assignedSet.size() == 0);

  int i = 0;
  HashSet<CompleteWork> inputWorkSet = new HashSet<>(inputWorks);
  for(NodeEndpoint ep : inputEps) {
    Collection<CompleteWork> assignedWorks = assignments.get(i);
    for(CompleteWork assignedWork : assignedWorks) {
      assertEquals("Wrong endpoint assigned: " + summary,
          ep.getAddress(), assignedWork.getAffinity().get(0).getEndpoint().getAddress());
      assertTrue(summary, inputWorkSet.remove(assignedWork));
    }
    i++;
  }

}
项目:guava-mock    文件:ListMultimapEqualsTester.java   
@CollectionSize.Require(SEVERAL)
public void testOrderingAffectsEqualsComparisons() {
  ListMultimap<K, V> multimap1 =
      getSubjectGenerator()
          .create(
              Helpers.mapEntry(k0(), v0()),
              Helpers.mapEntry(k0(), v1()),
              Helpers.mapEntry(k0(), v0()));
  ListMultimap<K, V> multimap2 =
      getSubjectGenerator()
          .create(
              Helpers.mapEntry(k0(), v1()),
              Helpers.mapEntry(k0(), v0()),
              Helpers.mapEntry(k0(), v0()));
  new EqualsTester().addEqualityGroup(multimap1).addEqualityGroup(multimap2).testEquals();
}
项目:Simple-Chunks    文件:ChunkLoadingHandler.java   
@Override
public ListMultimap<String, ForgeChunkManager.Ticket> playerTicketsLoaded(ListMultimap<String, ForgeChunkManager.Ticket> tickets, World world)
{
    // We don't care what order the tickets are in, but filter out the invalid ones
    ListMultimap<String, ForgeChunkManager.Ticket> validTickets = ArrayListMultimap.create();

    for (String playerName : tickets.keySet())
    {
        List<ForgeChunkManager.Ticket> playerTickets = new ArrayList<>();

        for (ForgeChunkManager.Ticket tkt : tickets.get(playerName))
        {
            BlockPos ticketPosition = NBTUtil.getPosFromTag(tkt.getModData().getCompoundTag("position"));
            TileEntity te = world.getTileEntity(ticketPosition);
            if (te instanceof TileEntityChunkLoader)
            {
                playerTickets.add(tkt);
            }
        }

        validTickets.putAll(playerName, playerTickets);
    }

    return validTickets;
}
项目:ditb    文件:TableAuthManager.java   
/**
 * Updates the internal permissions cache for a single table, splitting
 * the permissions listed into separate caches for users and groups to optimize
 * group lookups.
 *
 * @param table
 * @param tablePerms
 */
private void updateTableCache(TableName table,
                              ListMultimap<String,TablePermission> tablePerms) {
  PermissionCache<TablePermission> newTablePerms = new PermissionCache<TablePermission>();

  for (Map.Entry<String,TablePermission> entry : tablePerms.entries()) {
    if (AuthUtil.isGroupPrincipal(entry.getKey())) {
      newTablePerms.putGroup(AuthUtil.getGroupName(entry.getKey()), entry.getValue());
    } else {
      newTablePerms.putUser(entry.getKey(), entry.getValue());
    }
  }

  tableCache.put(table, newTablePerms);
  mtime.incrementAndGet();
}
项目:dremio-oss    文件:AssignmentCreator.java   
/**
 * Does the work of creating the mappings for this AssignmentCreator
 * @return the minor fragment id to work units mapping
 */
private ListMultimap<Integer, T> getMappings() {
  Stopwatch watch = Stopwatch.createStarted();
  maxWork = (int) Math.ceil(units.size() / ((float) incomingEndpoints.size()));
  LinkedList<WorkEndpointListPair<T>> workList = getWorkList();
  LinkedList<WorkEndpointListPair<T>> unassignedWorkList;
  Map<NodeEndpoint,FragIteratorWrapper> endpointIterators = getEndpointIterators();

  unassignedWorkList = assign(workList, endpointIterators, true);

  assignLeftovers(unassignedWorkList, endpointIterators, true);
  assignLeftovers(unassignedWorkList, endpointIterators, false);

  if (!unassignedWorkList.isEmpty()) {
    throw new IllegalStateException("There are still unassigned work units");
  }

  logger.debug("Took {} ms to assign {} work units to {} fragments", watch.elapsed(TimeUnit.MILLISECONDS), units.size(), incomingEndpoints.size());
  return mappings;
}
项目:clearwsd    文件:TsvResourceInitializer.java   
@Override
public MultimapResource<K> get() {
    ListMultimap<String, String> multimap = ArrayListMultimap.create();
    MultimapResource<K> resource = new MultimapResource<>(key);
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(path.openStream()))) {
        String line;
        while ((line = reader.readLine()) != null) {
            line = line.trim();
            if (line.trim().isEmpty()) {
                continue;
            }
            List<String> fields = Arrays.asList(line.split("\t"));
            apply(fields, multimap);
        }
    } catch (Exception e) {
        throw new RuntimeException("Error initializing TSV resource.", e);
    }
    resource.multimap(ImmutableListMultimap.copyOf(multimap));
    resource.mappingFunction(mappingFunction);
    return resource;
}
项目:dremio-oss    文件:TestAssignment.java   
@Test
public void manyFiles() throws Exception {
  List<CompleteWork> chunks = generateChunks(1000);

  Iterator<NodeEndpoint> incomingEndpointsIterator = Iterators.cycle(endpoints);

  List<NodeEndpoint> incomingEndpoints = Lists.newArrayList();

  final int width = 28 * 30;
  for (int i = 0; i < width; i++) {
    incomingEndpoints.add(incomingEndpointsIterator.next());
  }

  ListMultimap<Integer, CompleteWork> mappings = AssignmentCreator.getMappings(incomingEndpoints, chunks);
  System.out.println(mappings.keySet().size());
  for (int i = 0; i < width; i++) {
    Assert.assertTrue("no mapping for entry " + i, mappings.get(i) != null && mappings.get(i).size() > 0);
  }
}
项目:ditb    文件:TableAuthManager.java   
/**
 * Updates the internal global permissions cache
 *
 * @param userPerms
 */
private void updateGlobalCache(ListMultimap<String,TablePermission> userPerms) {
  PermissionCache<Permission> newCache = null;
  try {
    newCache = initGlobal(conf);
    for (Map.Entry<String,TablePermission> entry : userPerms.entries()) {
      if (AuthUtil.isGroupPrincipal(entry.getKey())) {
        newCache.putGroup(AuthUtil.getGroupName(entry.getKey()),
            new Permission(entry.getValue().getActions()));
      } else {
        newCache.putUser(entry.getKey(), new Permission(entry.getValue().getActions()));
      }
    }
    globalCache = newCache;
    mtime.incrementAndGet();
  } catch (IOException e) {
    // Never happens
    LOG.error("Error occured while updating the global cache", e);
  }
}
项目:Equella    文件:ItemDaoImpl.java   
@Override
@Transactional(propagation = Propagation.MANDATORY)
public ListMultimap<Long, Attachment> getAttachmentsForItemIds(Collection<Long> ids)
{
    if( ids.isEmpty() )
    {
        return ImmutableListMultimap.of();
    }
    List<Object[]> attachments = getHibernateTemplate().findByNamedParam(
        "select a, i.id from Item i join i.attachments a where i.id in (:items) order by index(a) ASC", "items",
        ids);
    ListMultimap<Long, Attachment> multiMap = ArrayListMultimap.create();
    for( Object[] attachmentRow : attachments )
    {
        multiMap.put((Long) attachmentRow[1], (Attachment) attachmentRow[0]);
    }
    return multiMap;
}
项目:Equella    文件:ItemDaoImpl.java   
@Override
@Transactional(propagation = Propagation.MANDATORY)
public ListMultimap<Long, ItemNavigationNode> getNavigationNodesForItemIds(Collection<Long> ids)
{
    if( ids.isEmpty() )
    {
        return ImmutableListMultimap.of();
    }
    List<Object[]> node = getHibernateTemplate().findByNamedParam(
        "select n, i.id from ItemNavigationNode n join n.item i where i.id in (:items) order by n.index ASC",
        "items", ids);
    ListMultimap<Long, ItemNavigationNode> multiMap = ArrayListMultimap.create();
    for( Object[] nodeRow : node )
    {
        multiMap.put((Long) nodeRow[1], (ItemNavigationNode) nodeRow[0]);
    }
    return multiMap;
}
项目:Equella    文件:ItemDaoImpl.java   
@Override
@Transactional(propagation = Propagation.MANDATORY)
public Multimap<Long, String> getCollaboratorsForItemIds(Collection<Long> itemIds)
{
    if( itemIds.isEmpty() )
    {
        return ImmutableMultimap.of();
    }
    List<Object[]> attachments = getHibernateTemplate().findByNamedParam(
        "select c, i.id from Item i join i.collaborators c where i.id in (:items)", "items", itemIds);
    ListMultimap<Long, String> multiMap = ArrayListMultimap.create();
    for( Object[] attachmentRow : attachments )
    {
        multiMap.put((Long) attachmentRow[1], (String) attachmentRow[0]);
    }
    return multiMap;
}
项目:Equella    文件:ItemCommentDaoImpl.java   
@SuppressWarnings("unchecked")
@Override
@Transactional(propagation = Propagation.MANDATORY)
public Multimap<Long, Comment> getCommentsForItems(Collection<Long> itemIds)
{
    if( itemIds.isEmpty() )
    {
        return ImmutableListMultimap.of();
    }
    List<Object[]> attachments = getHibernateTemplate()
        .findByNamedParam("select c, i.id from Item i join i.comments c where i.id in (:items)", "items", itemIds);
    ListMultimap<Long, Comment> multiMap = ArrayListMultimap.create();
    for( Object[] attachmentRow : attachments )
    {
        multiMap.put((Long) attachmentRow[1], (Comment) attachmentRow[0]);
    }
    return multiMap;
}
项目:javaide    文件:DataMerger.java   
/**
 * Returns a map of the data items.
 * @return a map of items.
 *
 * @see DataMap
 */
@NonNull
@Override
public ListMultimap<String, I> getDataMap() {
    // put all the sets in a multimap. The result is that for each key,
    // there is a sorted list of items from all the layers, including removed ones.
    ListMultimap<String, I> fullItemMultimap = ArrayListMultimap.create();

    for (S resourceSet : mDataSets) {
        ListMultimap<String, I> map = resourceSet.getDataMap();
        for (Map.Entry<String, Collection<I>> entry : map.asMap().entrySet()) {
            fullItemMultimap.putAll(entry.getKey(), entry.getValue());
        }
    }

    return fullItemMultimap;
}
项目:ditb    文件:AccessControlLists.java   
/**
 * Reads user permission assignments stored in the <code>l:</code> column
 * family of the first table row in <code>_acl_</code>.
 *
 * <p>
 * See {@link AccessControlLists class documentation} for the key structure
 * used for storage.
 * </p>
 */
static ListMultimap<String, TablePermission> getPermissions(Configuration conf,
    byte[] entryName) throws IOException {
  if (entryName == null) entryName = ACL_GLOBAL_NAME;

  // for normal user tables, we just read the table row from _acl_
  ListMultimap<String, TablePermission> perms = ArrayListMultimap.create();
  // TODO: Pass in a Connection rather than create one each time.
  try (Connection connection = ConnectionFactory.createConnection(conf)) {
    try (Table table = connection.getTable(ACL_TABLE_NAME)) {
      Get get = new Get(entryName);
      get.addFamily(ACL_LIST_FAMILY);
      Result row = table.get(get);
      if (!row.isEmpty()) {
        perms = parsePermissions(entryName, row);
      } else {
        LOG.info("No permissions found in " + ACL_TABLE_NAME + " for acl entry "
            + Bytes.toString(entryName));
      }
    }
  }

  return perms;
}
项目:ditb    文件:ProtobufUtil.java   
/**
 * Convert a ListMultimap&lt;String, TablePermission&gt; where key is username
 * to a protobuf UserPermission
 *
 * @param perm the list of user and table permissions
 * @return the protobuf UserTablePermissions
 */
public static AccessControlProtos.UsersAndPermissions toUserTablePermissions(
    ListMultimap<String, TablePermission> perm) {
  AccessControlProtos.UsersAndPermissions.Builder builder =
                AccessControlProtos.UsersAndPermissions.newBuilder();
  for (Map.Entry<String, Collection<TablePermission>> entry : perm.asMap().entrySet()) {
    AccessControlProtos.UsersAndPermissions.UserPermissions.Builder userPermBuilder =
                AccessControlProtos.UsersAndPermissions.UserPermissions.newBuilder();
    userPermBuilder.setUser(ByteString.copyFromUtf8(entry.getKey()));
    for (TablePermission tablePerm: entry.getValue()) {
      userPermBuilder.addPermissions(toPermission(tablePerm));
    }
    builder.addUserPermissions(userPermBuilder.build());
  }
  return builder.build();
}
项目:hashsdn-controller    文件:DOMRpcRoutingTable.java   
DOMRpcRoutingTable remove(final DOMRpcImplementation implementation, final Set<DOMRpcIdentifier> rpcs) {
    if (rpcs.isEmpty()) {
        return this;
    }

    // First decompose the identifiers to a multimap
    final ListMultimap<SchemaPath, YangInstanceIdentifier> toRemove = decomposeIdentifiers(rpcs);

    // Now iterate over existing entries, modifying them as appropriate...
    final Builder<SchemaPath, AbstractDOMRpcRoutingTableEntry> b = ImmutableMap.builder();
    for (Entry<SchemaPath, AbstractDOMRpcRoutingTableEntry> e : this.rpcs.entrySet()) {
        final List<YangInstanceIdentifier> removed = new ArrayList<>(toRemove.removeAll(e.getKey()));
        if (!removed.isEmpty()) {
            final AbstractDOMRpcRoutingTableEntry ne = e.getValue().remove(implementation, removed);
            if (ne != null) {
                b.put(e.getKey(), ne);
            }
        } else {
            b.put(e);
        }
    }

    // All done, whatever is in toRemove, was not there in the first place
    return new DOMRpcRoutingTable(b.build(), schemaContext);
}
项目:javaide    文件:AbstractResourceRepository.java   
/**
 * Returns the resources values matching a given {@link FolderConfiguration}.
 *
 * @param referenceConfig the configuration that each value must match.
 * @return a map with guaranteed to contain an entry for each {@link ResourceType}
 */
@NonNull
public Map<ResourceType, Map<String, ResourceValue>> getConfiguredResources(
        @NonNull FolderConfiguration referenceConfig) {
    Map<ResourceType, Map<String, ResourceValue>> map = Maps.newEnumMap(ResourceType.class);

    synchronized (ITEM_MAP_LOCK) {
        Map<ResourceType, ListMultimap<String, ResourceItem>> itemMap = getMap();
        for (ResourceType key : ResourceType.values()) {
            // get the local results and put them in the map
            map.put(key, getConfiguredResources(itemMap, key, referenceConfig));
        }
    }

    return map;
}
项目:QDrill    文件:AssignmentCreator.java   
/**
 * Does the work of creating the mappings for this AssignmentCreator
 * @return the minor fragment id to work units mapping
 */
private ListMultimap<Integer, T> getMappings() {
  Stopwatch watch = new Stopwatch();
  watch.start();
  maxWork = (int) Math.ceil(units.size() / ((float) incomingEndpoints.size()));
  LinkedList<WorkEndpointListPair<T>> workList = getWorkList();
  LinkedList<WorkEndpointListPair<T>> unassignedWorkList;
  Map<DrillbitEndpoint,FragIteratorWrapper> endpointIterators = getEndpointIterators();

  unassignedWorkList = assign(workList, endpointIterators, true);

  assignLeftovers(unassignedWorkList, endpointIterators, true);
  assignLeftovers(unassignedWorkList, endpointIterators, false);

  if (unassignedWorkList.size() != 0) {
    throw new DrillRuntimeException("There are still unassigned work units");
  }

  logger.debug("Took {} ms to assign {} work units to {} fragments", watch.elapsed(TimeUnit.MILLISECONDS), units.size(), incomingEndpoints.size());
  return mappings;
}
项目:QDrill    文件:TestAssignment.java   
@Test
public void manyFiles() throws Exception {
  List<CompleteFileWork> chunks = generateChunks(1000);

  Iterator<DrillbitEndpoint> incomingEndpointsIterator = Iterators.cycle(endpoints);

  List<DrillbitEndpoint> incomingEndpoints = Lists.newArrayList();

  final int width = 28 * 30;
  for (int i = 0; i < width; i++) {
    incomingEndpoints.add(incomingEndpointsIterator.next());
  }

  ListMultimap<Integer, CompleteFileWork> mappings = AssignmentCreator.getMappings(incomingEndpoints, chunks, null);
  System.out.println(mappings.keySet().size());
  for (int i = 0; i < width; i++) {
    Assert.assertTrue("no mapping for entry " + i, mappings.get(i) != null && mappings.get(i).size() > 0);
  }
}
项目:guava-beta-checker    文件:TestCompiler.java   
/**
 * Asserts that the given diagnostics contain errors with a message containing "[CheckerName]"
 * on the given lines of the given file. If there should be multiple errors on a line, the line
 * number must appear multiple times. There may not be any errors in any other file.
 */
public void assertErrorsOnLines(String file,
    List<Diagnostic<? extends JavaFileObject>> diagnostics, long... lines) {
  ListMultimap<String, Long> actualErrors = ArrayListMultimap.create();
  for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics) {
    String message = diagnostic.getMessage(Locale.US);

    // The source may be null, e.g. for diagnostics about command-line flags
    assertNotNull(message, diagnostic.getSource());
    String sourceName = diagnostic.getSource().getName();

    assertEquals(
        "unexpected error in source file " + sourceName + ": " + message,
        file, sourceName);

    actualErrors.put(diagnostic.getSource().getName(), diagnostic.getLineNumber());

    // any errors from the compiler that are not related to this checker should fail
    assertThat(message).contains("[" + checker.getAnnotation(BugPattern.class).name() + "]");
  }

  assertEquals(
      ImmutableMultiset.copyOf(Longs.asList(lines)),
      ImmutableMultiset.copyOf(actualErrors.get(file)));
}
项目:Reer    文件:JvmComponentPlugin.java   
private static void validateNoDuplicate(ModelMap<LocalJava> jdks) {
    ListMultimap<String, LocalJava> jdksByPath = indexByPath(jdks);
    List<String> errors = Lists.newArrayList();
    for (String path : jdksByPath.keySet()) {
        checkDuplicateForPath(jdksByPath, path, errors);
    }
    if (!errors.isEmpty()) {
        throw new InvalidModelException(String.format("Duplicate Java installation found:\n%s", Joiner.on("\n").join(errors)));
    }
}
项目:Reer    文件:JvmComponentPlugin.java   
private static void checkDuplicateForPath(ListMultimap<String, LocalJava> index, String path, List<String> errors) {
    List<LocalJava> localJavas = index.get(path);
    if (localJavas.size() > 1) {
        errors.add(String.format("   - %s are both pointing to the same JDK installation path: %s",
            Joiner.on(", ").join(Iterables.transform(localJavas, new Function<LocalJava, String>() {
                @Override
                public String apply(LocalJava input) {
                    return "'" + input.getName() + "'";
                }
            })), path));
    }
}
项目:Reer    文件:JvmComponentPlugin.java   
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;
}
项目:Reer    文件:IvyModuleDescriptorConverter.java   
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));
}
项目:Reer    文件:ComponentAttributeMatcher.java   
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;
}
项目:Reer    文件:ComponentAttributeMatcher.java   
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);
}
项目:ditb    文件:TestTablePermissions.java   
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));
    }
  }
}
项目:ditb    文件:TestTablePermissions.java   
/**
 * 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);
}
项目:dremio-oss    文件:Wrapper.java   
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);
  }
}
项目:businessworks    文件:CycleDetectingLock.java   
@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();
}
项目:ditb    文件:TestTablePermissions.java   
@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());
}
项目:dremio-oss    文件:AssignmentCreator2.java   
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;
}