private void assertCorrectParamsInMap(Multimap<String, String> paramMap) {
   assertEquals(4, paramMap.values().size());
   assertEquals(3, paramMap.keySet().size());
   assertTrue(paramMap.containsEntry("key", "value"));
   assertTrue(paramMap.containsEntry("key2", "value1"));
   assertTrue(paramMap.containsEntry("key2", "value2"));
   assertTrue(paramMap.containsEntry("key3", "null"));
 }
    /**
     * Returns true if the given resource is private in the library
     *
     * @param type the type of the resource
     * @param name the name of the resource
     * @return true if the given resource is private
     */
    @Override
    public boolean isPrivate(@NonNull ResourceType type, @NonNull String name) {
      //noinspection SimplifiableIfStatement
      if (mPublic == null) {
        // No public definitions: Everything assumed to be public
        return false;
      }

      //noinspection SimplifiableIfStatement
      if (!mAll.containsEntry(name, type)) {
        // Don't respond to resource URLs that are not part of this project
        // since we won't have private information on them
        return false;
      }
      return !mPublic.containsEntry(name, type);
    }
Exemplo n.º 3
0
 private static void mergeAllTimestampsMapIntoMap(
     Multimap<Cell, Long> globalResult, Multimap<Cell, Long> partResult) {
   for (Map.Entry<Cell, Long> e : partResult.entries()) {
     if (!globalResult.containsEntry(e.getKey(), e.getValue())) {
       globalResult.put(e.getKey(), e.getValue());
     }
   }
 }
Exemplo n.º 4
0
  /** @inheritDoc */
  public boolean update(Collection<MetabolicReaction> reactions) {

    boolean changed = false;

    for (MetabolicReaction reaction : reactions) {
      if (reactionMap.containsEntry(reaction.getIdentifier(), reaction)) {
        changed = update(reaction) || changed;
      }
    }

    return changed;
  }
Exemplo n.º 5
0
 /**
  * Helper used by scanXyz methods below to check whether a directory should be visited. It can be
  * skipped if it's not a directory or if it's already marked as visited in mVisitedDirs for the
  * given package type -- in which case the directory is added to the visited map.
  *
  * @param pkgType The package type being scanned.
  * @param directory The file or directory to check.
  * @return False if directory can/should be skipped. True if directory should be visited, in which
  *     case it's registered in mVisitedDirs.
  */
 private boolean shouldVisitDir(@NonNull PkgType pkgType, @NonNull File directory) {
   if (!mFileOp.isDirectory(directory)) {
     return false;
   }
   synchronized (mLocalPackages) {
     if (mVisitedDirs.containsEntry(pkgType, new LocalDirInfo.MapComparator(directory))) {
       return false;
     }
     mVisitedDirs.put(pkgType, new LocalDirInfo(mFileOp, directory));
   }
   return true;
 }
Exemplo n.º 6
0
  /**
   * For unique local packages. Returns the cached LocalPkgInfo for the requested type. Loads it
   * from disk if not cached.
   *
   * @param filter {@link PkgType#PKG_TOOLS} or {@link PkgType#PKG_PLATFORM_TOOLS} or {@link
   *     PkgType#PKG_DOC}.
   * @return null if the package is not installed.
   */
  @Nullable
  public LocalPkgInfo getPkgInfo(@NonNull PkgType filter) {
    if (filter != PkgType.PKG_TOOLS
        && filter != PkgType.PKG_PLATFORM_TOOLS
        && filter != PkgType.PKG_DOC
        && filter != PkgType.PKG_NDK) {
      assert false;
      return null;
    }

    LocalPkgInfo info = null;
    synchronized (mLocalPackages) {
      Collection<LocalPkgInfo> existing = mLocalPackages.get(filter);
      assert existing.size() <= 1;
      if (!existing.isEmpty()) {
        return existing.iterator().next();
      }

      File uniqueDir = new File(mSdkRoot, filter.getFolderName());

      if (!mVisitedDirs.containsEntry(filter, new LocalDirInfo.MapComparator(uniqueDir))) {
        switch (filter) {
          case PKG_TOOLS:
            info = scanTools(uniqueDir);
            break;
          case PKG_PLATFORM_TOOLS:
            info = scanPlatformTools(uniqueDir);
            break;
          case PKG_DOC:
            info = scanDoc(uniqueDir);
            break;
          case PKG_NDK:
            info = scanNdk(uniqueDir);
          default:
            break;
        }
      }

      // Whether we have found a valid pkg or not, this directory has been visited.
      mVisitedDirs.put(filter, new LocalDirInfo(mFileOp, uniqueDir));

      if (info != null) {
        mLocalPackages.put(filter, info);
      }
    }

    return info;
  }
Exemplo n.º 7
0
 /**
  * Is the specified channel active for the player?
  *
  * @param channel
  * @param player
  * @return
  */
 public boolean isChannelActive(String channel, Player player) {
   return activeChannels.containsEntry(player, channel);
 }
 @Override
 public boolean containsEntry(final Object key, final Object value) {
   return _forward.containsEntry(key, value);
 }
Exemplo n.º 9
0
 @Override
 public boolean containerContains(Container container, Parcel parcel) {
   synchronized (this) {
     return containerContents.containsEntry(container, parcel);
   }
 }
    @Override
    public void visit(NodeTraversal t, Node n, Node parent) {
      if (!NodeUtil.isReferenceName(n)) {
        return;
      }

      String name = n.getString();
      Scope referencedIn = t.getScope();
      Var var = referencedIn.getVar(name);
      if (var == null) {
        return;
      }

      if (!var.isLet() && !var.isConst()) {
        return;
      }

      // Traverse nodes up from let/const declaration:
      // If we hit a function or the root before a loop - Not a loop closure.
      // if we hit a loop first - maybe loop closure.
      Scope declaredIn = var.getScope();
      Node loopNode = null;
      for (Scope s = declaredIn; ; s = s.getParent()) {
        Node scopeRoot = s.getRootNode();
        if (NodeUtil.isLoopStructure(s.getRootNode())) {
          loopNode = scopeRoot;
          break;
        } else if (scopeRoot.getParent() != null
            && NodeUtil.isLoopStructure(scopeRoot.getParent())) {
          loopNode = scopeRoot.getParent();
          break;
        } else if (s.isFunctionBlockScope() || s.isGlobal()) {
          return;
        }
      }

      referenceMap.put(var, n);

      // Traverse scopes from reference scope to declaration scope.
      // If we hit a function - loop closure detected.
      for (Scope s = referencedIn; s != declaredIn; s = s.getParent()) {
        if (s.isFunctionBlockScope()) {
          Node function = s.getRootNode().getParent();
          if (functionHandledMap.containsEntry(function, name)) {
            return;
          }
          functionHandledMap.put(function, name);

          if (!loopObjectMap.containsKey(loopNode)) {
            loopObjectMap.put(
                loopNode,
                new LoopObject(LOOP_OBJECT_NAME + "$" + compiler.getUniqueNameIdSupplier().get()));
          }
          LoopObject object = loopObjectMap.get(loopNode);
          object.vars.add(var);

          functionLoopObjectsMap.put(function, object);
          return;
        }
      }
    }
Exemplo n.º 11
0
  private BranchBatch validateChangeList(OpenRepo or, Collection<ChangeData> submitted)
      throws IntegrationException {
    logDebug("Validating {} changes", submitted.size());
    List<ChangeData> toSubmit = new ArrayList<>(submitted.size());
    Multimap<ObjectId, PatchSet.Id> revisions = getRevisions(or, submitted);

    SubmitType submitType = null;
    ChangeData choseSubmitTypeFrom = null;
    for (ChangeData cd : submitted) {
      Change.Id changeId = cd.getId();
      ChangeControl ctl;
      Change chg;
      try {
        ctl = cd.changeControl();
        chg = cd.change();
      } catch (OrmException e) {
        logProblem(changeId, e);
        continue;
      }
      if (chg.currentPatchSetId() == null) {
        String msg = "Missing current patch set on change";
        logError(msg + " " + changeId);
        problems.put(changeId, msg);
        continue;
      }

      PatchSet ps;
      Branch.NameKey destBranch = chg.getDest();
      try {
        ps = cd.currentPatchSet();
      } catch (OrmException e) {
        logProblem(changeId, e);
        continue;
      }
      if (ps == null || ps.getRevision() == null || ps.getRevision().get() == null) {
        logProblem(changeId, "Missing patch set or revision on change");
        continue;
      }

      String idstr = ps.getRevision().get();
      ObjectId id;
      try {
        id = ObjectId.fromString(idstr);
      } catch (IllegalArgumentException e) {
        logProblem(changeId, e);
        continue;
      }

      if (!revisions.containsEntry(id, ps.getId())) {
        // TODO this is actually an error, the branch is gone but we
        // want to merge the issue. We can't safely do that if the
        // tip is not reachable.
        //
        logProblem(
            changeId,
            "Revision "
                + idstr
                + " of patch set "
                + ps.getPatchSetId()
                + " does not match "
                + ps.getId().toRefName()
                + " for change");
        continue;
      }

      CodeReviewCommit commit;
      try {
        commit = or.rw.parseCommit(id);
      } catch (IOException e) {
        logProblem(changeId, e);
        continue;
      }

      // TODO(dborowitz): Consider putting ChangeData in CodeReviewCommit.
      commit.setControl(ctl);
      commit.setPatchsetId(ps.getId());
      commits.put(changeId, commit);

      MergeValidators mergeValidators = mergeValidatorsFactory.create();
      try {
        mergeValidators.validatePreMerge(or.repo, commit, or.project, destBranch, ps.getId());
      } catch (MergeValidationException mve) {
        problems.put(changeId, mve.getMessage());
        continue;
      }

      SubmitType st = getSubmitType(cd);
      if (st == null) {
        logProblem(changeId, "No submit type for change");
        continue;
      }
      if (submitType == null) {
        submitType = st;
        choseSubmitTypeFrom = cd;
      } else if (st != submitType) {
        problems.put(
            changeId,
            String.format(
                "Change has submit type %s, but previously chose submit type %s "
                    + "from change %s in the same batch",
                st, submitType, choseSubmitTypeFrom.getId()));
        continue;
      }
      commit.add(or.canMergeFlag);
      toSubmit.add(cd);
    }
    logDebug("Submitting on this run: {}", toSubmit);
    return new AutoValue_MergeOp_BranchBatch(submitType, toSubmit);
  }
Exemplo n.º 12
0
  /**
   * Retrieve all the info about the requested package types. This is used for the package types
   * that have one or more instances, each with different versions. The resulting array is sorted
   * according to the PkgInfo's sort order.
   *
   * <p>To force the LocalSdk parser to load <b>everything</b>, simply call this method with the
   * {@link PkgType#PKG_ALL} argument to load all the known package types.
   *
   * <p>Note: you can use this with {@link PkgType#PKG_TOOLS}, {@link PkgType#PKG_PLATFORM_TOOLS}
   * and {@link PkgType#PKG_DOC} but since there can only be one package of these types, it is more
   * efficient to use {@link #getPkgInfo(PkgType)} to query them.
   *
   * @param filters One or more of {@link PkgType#PKG_ADDON}, {@link PkgType#PKG_PLATFORM}, {@link
   *     PkgType#PKG_BUILD_TOOLS}, {@link PkgType#PKG_EXTRA}, {@link PkgType#PKG_SOURCE}, {@link
   *     PkgType#PKG_SYS_IMAGE}
   * @return A list (possibly empty) of matching installed packages. Never returns null.
   */
  @NonNull
  public LocalPkgInfo[] getPkgsInfos(@NonNull EnumSet<PkgType> filters) {
    List<LocalPkgInfo> list = Lists.newArrayList();

    for (PkgType filter : filters) {
      if (filter == PkgType.PKG_TOOLS
          || filter == PkgType.PKG_PLATFORM_TOOLS
          || filter == PkgType.PKG_DOC
          || filter == PkgType.PKG_NDK) {
        LocalPkgInfo info = getPkgInfo(filter);
        if (info != null) {
          list.add(info);
        }
      } else {
        synchronized (mLocalPackages) {
          Collection<LocalPkgInfo> existing = mLocalPackages.get(filter);
          assert existing != null; // Multimap returns an empty set if not found

          if (!existing.isEmpty()) {
            list.addAll(existing);
            continue;
          }

          File subDir = new File(mSdkRoot, filter.getFolderName());

          if (!mVisitedDirs.containsEntry(filter, new LocalDirInfo.MapComparator(subDir))) {
            switch (filter) {
              case PKG_BUILD_TOOLS:
                scanBuildTools(subDir, existing);
                break;

              case PKG_PLATFORM:
                scanPlatforms(subDir, existing);
                break;

              case PKG_SYS_IMAGE:
                scanSysImages(subDir, existing, false);
                break;

              case PKG_ADDON_SYS_IMAGE:
                scanSysImages(subDir, existing, true);
                break;

              case PKG_ADDON:
                scanAddons(subDir, existing);
                break;

              case PKG_SAMPLE:
                scanSamples(subDir, existing);
                break;

              case PKG_SOURCE:
                scanSources(subDir, existing);
                break;

              case PKG_EXTRA:
                scanExtras(subDir, existing);
                break;

              case PKG_TOOLS:
              case PKG_PLATFORM_TOOLS:
              case PKG_DOC:
              case PKG_NDK:
                break;
              default:
                throw new IllegalArgumentException("Unsupported pkg type " + filter.toString());
            }
            mVisitedDirs.put(filter, new LocalDirInfo(mFileOp, subDir));
            list.addAll(existing);
          }
        }
      }
    }

    Collections.sort(list);
    return list.toArray(new LocalPkgInfo[list.size()]);
  }