Java Code Examples for com.google.common.collect.Multimap#containsEntry()

The following examples show how to use com.google.common.collect.Multimap#containsEntry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewTypeDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private static void addViewTags(Multimap<String, String> map, Element element) {
    String id = element.getAttributeNS(ANDROID_URI, ATTR_ID);
    if (id != null && !id.isEmpty()) {
        id = LintUtils.stripIdPrefix(id);
        if (!map.containsEntry(id, element.getTagName())) {
            map.put(id, element.getTagName());
        }
    }

    NodeList children = element.getChildNodes();
    for (int i = 0, n = children.getLength(); i < n; i++) {
        Node child = children.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            addViewTags(map, (Element) child);
        }
    }
}
 
Example 2
Source File: MemoryPerUserWaveViewHandlerImpl.java    From swellrt with Apache License 2.0 6 votes vote down vote up
@Override
public ListenableFuture<Void> onParticipantAdded(WaveletName waveletName, ParticipantId user) {
  Multimap<WaveId, WaveletId> perUserView = explicitPerUserWaveViews.getIfPresent(user);
  if (perUserView != null) {
    if (!perUserView.containsEntry(waveletName.waveId, waveletName.waveletId)) {
      perUserView.put(waveletName.waveId, waveletName.waveletId);
      if(LOG.isFineLoggable()) {
        LOG.fine("Added wavelet: " + waveletName + " to the view of user: " + user.getAddress());
        LOG.fine("View size is now: " + perUserView.size());
      }
    }
  }
  SettableFuture<Void> task = SettableFuture.create();
  task.set(null);
  return task;
}
 
Example 3
Source File: MemoryPerUserWaveViewHandlerImpl.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
@Override
public ListenableFuture<Void> onParticipantAdded(WaveletName waveletName, ParticipantId user) {
  Multimap<WaveId, WaveletId> perUserView = explicitPerUserWaveViews.getIfPresent(user);
  if (perUserView != null) {
    if (!perUserView.containsEntry(waveletName.waveId, waveletName.waveletId)) {
      perUserView.put(waveletName.waveId, waveletName.waveletId);
      if(LOG.isFineLoggable()) {
        LOG.fine("Added wavelet: " + waveletName + " to the view of user: " + user.getAddress());
        LOG.fine("View size is now: " + perUserView.size());
      }
    }
  }
  SettableFuture<Void> task = SettableFuture.create();
  task.set(null);
  return task;
}
 
Example 4
Source File: ExpandCompositeTerms.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Attempts to create composites using both the leaf nodes and the anded nodes from our ancestors. Each of the composites created must contain at least one
 * of the leaf nodes in order to be valid. The used leaf nodes are passed back via the usedLeafNodes param. The used anded nodes are passed back via the
 * parentData.
 *
 * @param parentData
 *            Contains the ancestor anded nodes, anded nodes used to create the returned composites, and a flag indicating whether composites were found
 * @param nonLeafNodes
 *            A collection of non-leaf child nodes, from the parent node
 * @param leafNodes
 *            A multimap of leaf child nodes, keyed by field name, from the parent node
 * @param usedLeafNodes
 *            A multimap of used leaf child nodes, keyed by field name, used to create the returned composites
 * @return A list of modified and unmodified non-leaf child nodes, from the parent node
 */
private List<JexlNode> processNonLeafNodes(ExpandData parentData, Collection<JexlNode> nonLeafNodes, Multimap<String,JexlNode> leafNodes,
                Multimap<String,JexlNode> usedLeafNodes) {
    // descend into the child nodes, passing the anded leaf nodes down,
    // in order to determine whether or not composites can be made
    List<JexlNode> unmodifiedNodes = new ArrayList<>();
    List<JexlNode> modifiedNodes = new ArrayList<>();
    for (JexlNode nonLeafNode : nonLeafNodes) {
        ExpandData eData = new ExpandData();
        
        // add the anded leaf nodes from our ancestors
        eData.andedNodes.putAll(parentData.andedNodes);
        
        // add our anded leaf nodes
        eData.andedNodes.putAll(leafNodes);
        
        // descend into the non-leaf node to see if composites can be made
        JexlNode processedNode = (JexlNode) nonLeafNode.jjtAccept(this, eData);
        
        // if composites were made, save the processed node, and determine which leaf
        // nodes were used from this and node (if any)
        if (eData.foundComposite) {
            parentData.foundComposite = true;
            modifiedNodes.add(processedNode);
            for (Entry<String,JexlNode> usedAndedNode : eData.usedAndedNodes.entries())
                if (leafNodes.containsEntry(usedAndedNode.getKey(), usedAndedNode.getValue()))
                    usedLeafNodes.put(usedAndedNode.getKey(), usedAndedNode.getValue());
                else
                    parentData.usedAndedNodes.put(usedAndedNode.getKey(), usedAndedNode.getValue());
        } else
            unmodifiedNodes.add(nonLeafNode);
    }
    
    // add unmodified nodes, then modified nodes
    List<JexlNode> processedNodes = new ArrayList<>();
    processedNodes.addAll(unmodifiedNodes);
    processedNodes.addAll(modifiedNodes);
    
    return processedNodes;
}
 
Example 5
Source File: ModuleDependencyValidator.java    From bundletool with Apache License 2.0 5 votes vote down vote up
/** Checks that a module doesn't depend on itself. */
private static void checkNoReflexiveDependencies(Multimap<String, String> moduleDependenciesMap) {
  for (String moduleName : moduleDependenciesMap.keySet()) {
    // The base module is the only one that will have a self-loop in the dependencies map.
    if (!moduleName.equals(BASE_MODULE_NAME.getName())) {
      if (moduleDependenciesMap.containsEntry(moduleName, moduleName)) {
        throw InvalidBundleException.builder()
            .withUserMessage("Module '%s' depends on itself via <uses-split>.", moduleName)
            .build();
      }
    }
  }
}
 
Example 6
Source File: ModuleDependenciesUtils.java    From bundletool with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a map of module dependencies.
 *
 * <p>If module "a" contains {@code <uses-split name="b"/>} manifest entry, then the map contains
 * entry ("a", "b").
 *
 * <p>All modules implicitly depend on the "base" module. Hence the map contains also dependency
 * ("base", "base").
 */
public static Multimap<String, String> buildAdjacencyMap(ImmutableList<BundleModule> modules) {
  Multimap<String, String> moduleDependenciesMap = ArrayListMultimap.create();

  for (BundleModule module : modules) {
    String moduleName = module.getName().getName();
    AndroidManifest manifest = module.getAndroidManifest();

    checkArgument(
        !moduleDependenciesMap.containsKey(moduleName),
        "Module named '%s' was passed in multiple times.",
        moduleName);

    moduleDependenciesMap.putAll(moduleName, manifest.getUsesSplits());

    // Check that module does not declare explicit dependency on the "base" module
    // (whose split ID actually is empty instead of "base" anyway).
    if (moduleDependenciesMap.containsEntry(moduleName, BASE_MODULE_NAME.getName())) {
      throw InvalidBundleException.builder()
          .withUserMessage(
              "Module '%s' declares dependency on the '%s' module, which is implicit.",
              moduleName, BASE_MODULE_NAME)
          .build();
    }

    // Add implicit dependency on the base. Also ensures that every module has a key in the map.
    moduleDependenciesMap.put(moduleName, BASE_MODULE_NAME.getName());
  }

  return Multimaps.unmodifiableMultimap(moduleDependenciesMap);
}
 
Example 7
Source File: NullAway.java    From NullAway with MIT License 5 votes vote down vote up
/**
 * @param fieldSymbol the field
 * @param initTreePath TreePath to the initializer method / block
 * @param state visitor state
 * @return true if the field is always initialized (by some other initializer) before the
 *     initializer corresponding to initTreePath executes
 */
private boolean fieldInitializedByPreviousInitializer(
    Symbol fieldSymbol, TreePath initTreePath, VisitorState state) {
  TreePath enclosingClassPath = initTreePath.getParentPath();
  ClassTree enclosingClass = (ClassTree) enclosingClassPath.getLeaf();
  Multimap<Tree, Element> tree2Init =
      initTree2PrevFieldInit.get(ASTHelpers.getSymbol(enclosingClass));
  if (tree2Init == null) {
    tree2Init = computeTree2Init(enclosingClassPath, state);
    initTree2PrevFieldInit.put(ASTHelpers.getSymbol(enclosingClass), tree2Init);
  }
  return tree2Init.containsEntry(initTreePath.getLeaf(), fieldSymbol);
}
 
Example 8
Source File: PersistenceSecurityImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void applyConstraints(Entity entity, Set<EntityId> handled) {
    MetaClass metaClass = entity.getMetaClass();
    EntityId entityId = new EntityId(referenceToEntitySupport.getReferenceId(entity), metaClass.getName());
    if (handled.contains(entityId)) {
        return;
    }
    handled.add(entityId);
    if (entity instanceof BaseGenericIdEntity) {
        BaseGenericIdEntity baseGenericIdEntity = (BaseGenericIdEntity) entity;
        Multimap<String, Object> filteredData = BaseEntityInternalAccess.getFilteredData(baseGenericIdEntity);
        for (MetaProperty property : metaClass.getProperties()) {
            if (metadataTools.isPersistent(property) && PersistenceHelper.isLoaded(entity, property.getName())) {
                Object value = entity.getValue(property.getName());
                if (value instanceof Collection) {
                    Collection entities = (Collection) value;
                    for (Iterator<Entity> iterator = entities.iterator(); iterator.hasNext(); ) {
                        Entity item = iterator.next();
                        if (filteredData != null && filteredData.containsEntry(property.getName(),
                                referenceToEntitySupport.getReferenceId(item))) {
                            iterator.remove();
                        } else {
                            applyConstraints(item, handled);
                        }
                    }
                } else if (value instanceof Entity) {
                    if (filteredData != null && filteredData.containsEntry(property.getName(),
                            referenceToEntitySupport.getReferenceId((Entity) value))) {
                        baseGenericIdEntity.setValue(property.getName(), null);
                    } else {
                        applyConstraints((Entity) value, handled);
                    }
                }
            }
        }
    }
}
 
Example 9
Source File: Guava.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@ExpectWarning(value="GC", num=7)
public static void testMultimap(Multimap<String, Integer> mm) {
    mm.containsEntry("x", "y");
    mm.containsEntry(1, 5);
    mm.containsKey(1);
    mm.containsValue("x");
    mm.remove("x", "x");
    mm.remove(1, 2);
    mm.removeAll(1);
}
 
Example 10
Source File: Guava.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@NoWarning("GC")
public static void testMultimapOK(Multimap<String, Integer> mm) {
    mm.containsEntry("x", 1);
    mm.containsKey("x");
    mm.containsValue(1);
    mm.remove("x", 1);
    mm.removeAll("x");
}
 
Example 11
Source File: Guava.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@NoWarning("GC")
public static void testMultimapOK2(Multimap<String, Pair<Integer,Long>> mm) {
    Pair<Integer, Long> p = new Pair<Integer, Long>(1, 1L);
    mm.containsEntry("x", p);
    mm.containsKey("x");
    mm.containsValue(p);
    mm.remove("x", p);
    mm.removeAll("x");
}
 
Example 12
Source File: MemoryPerUserWaveViewHandlerImpl.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public ListenableFuture<Void> onParticipantRemoved(WaveletName waveletName, ParticipantId user) {
  Multimap<WaveId, WaveletId> perUserView = explicitPerUserWaveViews.getIfPresent(user);
  if (perUserView != null) {
    if (perUserView.containsEntry(waveletName.waveId, waveletName.waveletId)) {
      perUserView.remove(waveletName.waveId, waveletName.waveletId);
      LOG.fine("Removed wavelet: " + waveletName
          + " from the view of user: " + user.getAddress());
    }
  }
  SettableFuture<Void> task = SettableFuture.create();
  task.set(null);
  return task;
}
 
Example 13
Source File: MemoryPerUserWaveViewHandlerImpl.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public ListenableFuture<Void> onParticipantRemoved(WaveletName waveletName, ParticipantId user) {
  Multimap<WaveId, WaveletId> perUserView = explicitPerUserWaveViews.getIfPresent(user);
  if (perUserView != null) {
    if (perUserView.containsEntry(waveletName.waveId, waveletName.waveletId)) {
      perUserView.remove(waveletName.waveId, waveletName.waveletId);
      LOG.fine("Removed wavelet: " + waveletName
          + " from the view of user: " + user.getAddress());
    }
  }
  SettableFuture<Void> task = SettableFuture.create();
  task.set(null);
  return task;
}
 
Example 14
Source File: YarnTwillRunnerService.java    From twill with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a {@link Runnable} for renewing {@link SecureStore} for running applications.
 *
 * @param scheduler the schedule to schedule next renewal execution
 * @param renewer the {@link SecureStoreRenewer} to use for renewal
 * @param retryRuns if non-empty, only the given set of application name and run id that need to have
 *                  secure store renewed; if empty, renew all running applications
 * @param retryDelay the delay before retrying applications that are failed to have secure store renewed
 * @param timeUnit the unit for the {@code delay} and {@code failureDelay}.
 * @return a {@link Runnable}
 */
private Runnable createSecureStoreUpdateRunnable(final ScheduledExecutorService scheduler,
                                                 final SecureStoreRenewer renewer,
                                                 final Multimap<String, RunId> retryRuns,
                                                 final long retryDelay, final TimeUnit timeUnit) {
  return new Runnable() {
    @Override
    public void run() {
      // Collects the set of running application runs
      Table<String, RunId, YarnTwillController> liveApps;

      synchronized (YarnTwillRunnerService.this) {
        if (retryRuns.isEmpty()) {
          liveApps = HashBasedTable.create(controllers);
        } else {
          // If this is a renew retry, only renew the one in the retryRuns set
          liveApps = HashBasedTable.create();
          for (Table.Cell<String, RunId, YarnTwillController> cell : controllers.cellSet()) {
            if (retryRuns.containsEntry(cell.getRowKey(), cell.getColumnKey())) {
              liveApps.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
            }
          }
        }
      }

      Multimap<String, RunId> failureRenews = renewSecureStore(liveApps, renewer, false);

      if (!failureRenews.isEmpty()) {
        // If there are failure during the renewal, schedule a retry with a new Runnable.
        LOG.info("Schedule to retry on secure store renewal for applications {} in {} {}",
                 failureRenews.keySet(), retryDelay, timeUnit.name().toLowerCase());
        try {
          scheduler.schedule(
            createSecureStoreUpdateRunnable(scheduler, renewer, failureRenews, retryDelay, timeUnit),
            retryDelay, timeUnit);
        } catch (RejectedExecutionException e) {
          // If the renewal is stopped, the scheduler will be stopped,
          // hence this exception will be thrown and can be safely ignore.
        }
      }
    }
  };
}