コード例 #1
0
ファイル: LocalSdk.java プロジェクト: glowingyilia/ddmlib
 @NonNull
 public IAndroidTarget[] getMissingTargets() {
   synchronized (mLocalPackages) {
     if (mCachedMissingTargets == null) {
       Map<MissingTarget, MissingTarget> result = Maps.newHashMap();
       Set<ISystemImage> seen = Sets.newHashSet();
       for (IAndroidTarget target : getTargets()) {
         Collections.addAll(seen, target.getSystemImages());
       }
       for (LocalPkgInfo local : getPkgsInfos(PkgType.PKG_ADDON_SYS_IMAGE)) {
         LocalAddonSysImgPkgInfo info = (LocalAddonSysImgPkgInfo) local;
         ISystemImage image = info.getSystemImage();
         if (!seen.contains(image)) {
           addOrphanedSystemImage(image, info.getDesc(), result);
         }
       }
       for (LocalPkgInfo local : getPkgsInfos(PkgType.PKG_SYS_IMAGE)) {
         LocalSysImgPkgInfo info = (LocalSysImgPkgInfo) local;
         ISystemImage image = info.getSystemImage();
         if (!seen.contains(image)) {
           addOrphanedSystemImage(image, info.getDesc(), result);
         }
       }
       mCachedMissingTargets = result.keySet();
     }
     return mCachedMissingTargets.toArray(new IAndroidTarget[mCachedMissingTargets.size()]);
   }
 }
コード例 #2
0
 /**
  * update a reader: if !original, this is a reader that is being introduced by this transaction;
  * otherwise it must be in the originals() set, i.e. a reader guarded by this transaction
  */
 public void update(SSTableReader reader, boolean original) {
   assert !staged.update.contains(reader)
       : "each reader may only be updated once per checkpoint: " + reader;
   assert !identities.contains(reader.instanceId)
       : "each reader instance may only be provided as an update once: " + reader;
   // check it isn't obsolete, and that it matches the original flag
   assert !(logged.obsolete.contains(reader) || staged.obsolete.contains(reader))
       : "may not update a reader that has been obsoleted";
   assert original == originals.contains(reader)
       : String.format(
           "the 'original' indicator was incorrect (%s provided): %s", original, reader);
   staged.update.add(reader);
   identities.add(reader.instanceId);
   if (!isOffline()) reader.setupKeyCache();
 }
コード例 #3
0
ファイル: PseudocodeImpl.java プロジェクト: libai1987/kotlin
 private Set<Instruction> collectReachableInstructions() {
   Set<Instruction> visited = Sets.newHashSet();
   PseudocodeTraverserKt.traverseFollowingInstructions(
       getEnterInstruction(), visited, FORWARD, null);
   if (!visited.contains(getExitInstruction())) {
     visited.add(getExitInstruction());
   }
   if (!visited.contains(errorInstruction)) {
     visited.add(errorInstruction);
   }
   if (!visited.contains(getSinkInstruction())) {
     visited.add(getSinkInstruction());
   }
   return visited;
 }
コード例 #4
0
 /**
  * mark this reader as for obsoletion. this does not actually obsolete the reader until commit()
  * is called, but on checkpoint() the reader will be removed from the live set
  */
 public void obsolete(SSTableReader reader) {
   logger.debug("Staging for obsolescence {}", reader);
   // check this is: a reader guarded by the transaction, an instance we have already worked with
   // and that we haven't already obsoleted it, nor do we have other changes staged for it
   assert identities.contains(reader.instanceId)
       : "only reader instances that have previously been provided may be obsoleted: " + reader;
   assert originals.contains(reader)
       : "only readers in the 'original' set may be obsoleted: " + reader + " vs " + originals;
   assert !(logged.obsolete.contains(reader) || staged.obsolete.contains(reader))
       : "may not obsolete a reader that has already been obsoleted: " + reader;
   assert !staged.update.contains(reader)
       : "may not obsolete a reader that has a staged update (must checkpoint first): " + reader;
   assert current(reader) == reader
       : "may only obsolete the latest version of the reader: " + reader;
   staged.obsolete.add(reader);
 }
コード例 #5
0
ファイル: PseudocodeImpl.java プロジェクト: libai1987/kotlin
 private void collectAndCacheReachableInstructions() {
   Set<Instruction> reachableInstructions = collectReachableInstructions();
   for (Instruction instruction : mutableInstructionList) {
     if (reachableInstructions.contains(instruction)) {
       instructions.add(instruction);
     }
   }
   markDeadInstructions();
 }
コード例 #6
0
 /**
  * return the current version of the provided reader, whether or not it is visible or staged; i.e.
  * returns the first version present by testing staged, logged and originals in order.
  */
 public SSTableReader current(SSTableReader reader) {
   Set<SSTableReader> container;
   if (staged.contains(reader))
     container = staged.update.contains(reader) ? staged.update : staged.obsolete;
   else if (logged.contains(reader))
     container = logged.update.contains(reader) ? logged.update : logged.obsolete;
   else if (originals.contains(reader)) container = originals;
   else throw new AssertionError();
   return select(reader, container);
 }
コード例 #7
0
  public boolean isLeaving(InetAddress endpoint) {
    assert endpoint != null;

    lock.readLock().lock();
    try {
      return leavingEndPoints.contains(endpoint);
    } finally {
      lock.readLock().unlock();
    }
  }
コード例 #8
0
 /** remove the reader from the set we're modifying */
 public void cancel(SSTableReader cancel) {
   logger.debug("Cancelling {} from transaction", cancel);
   assert originals.contains(cancel)
       : "may only cancel a reader in the 'original' set: " + cancel + " vs " + originals;
   assert !(staged.contains(cancel) || logged.contains(cancel))
       : "may only cancel a reader that has not been updated or obsoleted in this transaction: "
           + cancel;
   originals.remove(cancel);
   marked.remove(cancel);
   maybeFail(unmarkCompacting(singleton(cancel), null));
 }
コード例 #9
0
ファイル: PseudocodeImpl.java プロジェクト: libai1987/kotlin
 private void markDeadInstructions() {
   Set<Instruction> instructionSet = Sets.newHashSet(instructions);
   for (Instruction instruction : mutableInstructionList) {
     if (!instructionSet.contains(instruction)) {
       ((InstructionImpl) instruction).setMarkedAsDead(true);
       for (Instruction nextInstruction : instruction.getNextInstructions()) {
         nextInstruction.getPreviousInstructions().remove(instruction);
       }
     }
   }
 }
コード例 #10
0
ファイル: MetaDataClient.java プロジェクト: QimengZou/phoenix
  public PColumn newColumn(int position, ColumnDef def, PrimaryKeyConstraint pkConstraint)
      throws SQLException {
    try {
      Set<String> pkColumnNames =
          pkConstraint == null ? Collections.<String>emptySet() : pkConstraint.getColumnNames();
      String columnName = def.getColumnDefName().getColumnName().getName();
      PName familyName = null;
      if (def.isPK() && !pkColumnNames.isEmpty()) {
        throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_ALREADY_EXISTS)
            .setColumnName(columnName)
            .build()
            .buildException();
      }
      boolean isPK = def.isPK() || pkColumnNames.contains(columnName);
      if (def.getColumnDefName().getFamilyName() != null) {
        String family = def.getColumnDefName().getFamilyName().getName();
        if (isPK) {
          throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_WITH_FAMILY_NAME)
              .setColumnName(columnName)
              .setFamilyName(family)
              .build()
              .buildException();
        } else if (!def.isNull()) {
          throw new SQLExceptionInfo.Builder(SQLExceptionCode.KEY_VALUE_NOT_NULL)
              .setColumnName(columnName)
              .setFamilyName(family)
              .build()
              .buildException();
        }
        familyName = new PNameImpl(family);
      } else if (!isPK) {
        familyName = QueryConstants.DEFAULT_COLUMN_FAMILY_NAME;
      }

      ColumnModifier columnModifier = def.getColumnModifier();
      if (pkConstraint != null && pkConstraint.getColumnModifier(columnName) != null) {
        columnModifier = pkConstraint.getColumnModifier(columnName);
      }

      PColumn column =
          new PColumnImpl(
              new PNameImpl(columnName),
              familyName,
              def.getDataType(),
              def.getMaxLength(),
              def.getScale(),
              def.isNull(),
              position,
              columnModifier);
      return column;
    } catch (IllegalArgumentException e) { // Based on precondition check in constructor
      throw new SQLException(e);
    }
  }
コード例 #11
0
ファイル: SimpleNetwork.java プロジェクト: rooma92/Terasology
 private void listConnectedNotVisitedNetworkingNodes(
     Set<NetworkNode> visitedNodes, NetworkNode location, Collection<NetworkNode> result) {
   for (Side connectingOnSide : SideBitFlag.getSides(location.connectionSides)) {
     final ImmutableBlockLocation possibleConnectionLocation =
         location.location.move(connectingOnSide);
     for (NetworkNode possibleConnection : networkingNodes.get(possibleConnectionLocation)) {
       if (!visitedNodes.contains(possibleConnection)
           && SideBitFlag.hasSide(possibleConnection.connectionSides, connectingOnSide.reverse()))
         result.add(possibleConnection);
     }
   }
 }
コード例 #12
0
  /**
   * remove the provided readers from this Transaction, and return a new Transaction to manage them
   * only permitted to be called if the current Transaction has never been used
   */
  public LifecycleTransaction split(Collection<SSTableReader> readers) {
    logger.debug("Splitting {} into new transaction", readers);
    checkUnused();
    for (SSTableReader reader : readers)
      assert identities.contains(reader.instanceId)
          : "may only split the same reader instance the transaction was opened with: " + reader;

    for (SSTableReader reader : readers) {
      identities.remove(reader.instanceId);
      originals.remove(reader);
      marked.remove(reader);
    }
    return new LifecycleTransaction(tracker, operationType, readers);
  }
コード例 #13
0
 @VisibleForTesting
 public ReaderState state(SSTableReader reader) {
   SSTableReader currentlyVisible =
       ReaderState.visible(reader, in(logged.obsolete), logged.update, originals);
   SSTableReader nextVisible =
       ReaderState.visible(
           reader,
           orIn(staged.obsolete, logged.obsolete),
           staged.update,
           logged.update,
           originals);
   return new ReaderState(
       ReaderState.Action.get(logged.update.contains(reader), logged.obsolete.contains(reader)),
       ReaderState.Action.get(staged.update.contains(reader), staged.obsolete.contains(reader)),
       currentlyVisible,
       nextVisible,
       originals.contains(reader));
 }
コード例 #14
0
  private static void test() {
    String customerKey = "customer";
    String productKey = "product";

    IntStream.range(0, 5)
        .forEach(
            index ->
                customerCache.put(
                    customerKey + index, new Customer(customerKey + index, "name" + index)));
    IntStream.range(0, 100)
        .forEach(
            index ->
                productCache.put(
                    productKey + index, new Product(productKey + index, "category" + (index % 5))));

    Random random = new Random();

    Set<String> productIds = new HashSet<>();
    int activeProductSize = productCache.size() / 10;

    for (int i = 0; i < 1000; i++) {
      Customer customer = customerCache.get(customerKey + random.nextInt(customerCache.size()));

      int randomSuffix = random.nextInt(activeProductSize);
      if (randomSuffix < 3) {
        randomSuffix = random.nextInt(productCache.size());
      }
      Product product = productCache.get(productKey + randomSuffix);
      if (!productIds.contains(product.id)) {
        purchasesCache.put(customer.id, product.id);
        productIds.add(product.id);
      }
    }
    createProductAssociativityGraphPerCategory();

    ProductRecommendationSystem recommendationSystem = new ProductRecommendationSystem(7);
    for (int i = 0; i < activeProductSize * 2; i++) {
      Customer customer = customerCache.get(customerKey + random.nextInt(customerCache.size()));
      Product product = productCache.get(productKey + random.nextInt(activeProductSize));

      List<Product> recommendations = recommendationSystem.purchase(customer, product);
      System.out.printf("%s%n", recommendations);
    }
  }
コード例 #15
0
ファイル: CommandContext.java プロジェクト: RainoBoy97/Intake
  /**
   * Parse the given array of arguments.
   *
   * <p>Empty arguments are removed from the list of arguments.
   *
   * @param args an array with arguments
   * @param expectedValueFlags a set containing all value flags (pass null to disable value flag
   *     parsing)
   * @param allowHangingFlag true if hanging flags are allowed
   * @param namespace the locals, null to create empty one
   * @throws CommandException thrown on a parsing error
   */
  public CommandContext(
      String[] args,
      Set<Character> expectedValueFlags,
      boolean allowHangingFlag,
      Namespace namespace)
      throws CommandException {
    if (expectedValueFlags == null) {
      expectedValueFlags = Collections.emptySet();
    }

    originalArgs = args;
    command = args[0];
    this.namespace = namespace != null ? namespace : new Namespace();
    boolean isHanging = false;
    SuggestionContext suggestionContext = SuggestionContext.hangingValue();

    // Eliminate empty args and combine multiword args first
    List<Integer> argIndexList = new ArrayList<Integer>(args.length);
    List<String> argList = new ArrayList<String>(args.length);
    for (int i = 1; i < args.length; ++i) {
      isHanging = false;

      String arg = args[i];
      if (arg.isEmpty()) {
        isHanging = true;
        continue;
      }

      argIndexList.add(i);

      switch (arg.charAt(0)) {
        case '\'':
        case '"':
          final StringBuilder build = new StringBuilder();
          final char quotedChar = arg.charAt(0);

          int endIndex;
          for (endIndex = i; endIndex < args.length; ++endIndex) {
            final String arg2 = args[endIndex];
            if (arg2.charAt(arg2.length() - 1) == quotedChar && arg2.length() > 1) {
              if (endIndex != i) build.append(' ');
              build.append(arg2.substring(endIndex == i ? 1 : 0, arg2.length() - 1));
              break;
            } else if (endIndex == i) {
              build.append(arg2.substring(1));
            } else {
              build.append(' ').append(arg2);
            }
          }

          if (endIndex < args.length) {
            arg = build.toString();
            i = endIndex;
          }

          // In case there is an empty quoted string
          if (arg.isEmpty()) {
            continue;
          }
          // else raise exception about hanging quotes?
      }
      argList.add(arg);
    }

    // Then flags

    List<Integer> originalArgIndices = Lists.newArrayListWithCapacity(argIndexList.size());
    List<String> parsedArgs = Lists.newArrayListWithCapacity(argList.size());
    Map<Character, String> valueFlags = Maps.newHashMap();
    List<Character> booleanFlags = Lists.newArrayList();

    for (int nextArg = 0; nextArg < argList.size(); ) {
      // Fetch argument
      String arg = argList.get(nextArg++);
      suggestionContext = SuggestionContext.hangingValue();

      // Not a flag?
      if (arg.charAt(0) != '-' || arg.length() == 1 || !arg.matches("^-[a-zA-Z\\?]+$")) {
        if (!isHanging) {
          suggestionContext = SuggestionContext.lastValue();
        }

        originalArgIndices.add(argIndexList.get(nextArg - 1));
        parsedArgs.add(arg);
        continue;
      }

      // Handle flag parsing terminator --
      if (arg.equals("--")) {
        while (nextArg < argList.size()) {
          originalArgIndices.add(argIndexList.get(nextArg));
          parsedArgs.add(argList.get(nextArg++));
        }
        break;
      }

      // Go through the flag characters
      for (int i = 1; i < arg.length(); ++i) {
        char flagName = arg.charAt(i);

        if (expectedValueFlags.contains(flagName)) {
          if (valueFlags.containsKey(flagName)) {
            throw new CommandException("Value flag '" + flagName + "' already given");
          }

          if (nextArg >= argList.size()) {
            if (allowHangingFlag) {
              suggestionContext = SuggestionContext.flag(flagName);
              break;
            } else {
              throw new CommandException("No value specified for the '-" + flagName + "' flag.");
            }
          }

          // If it is a value flag, read another argument and add it
          valueFlags.put(flagName, argList.get(nextArg++));
          if (!isHanging) {
            suggestionContext = SuggestionContext.flag(flagName);
          }
        } else {
          booleanFlags.add(flagName);
        }
      }
    }

    ImmutableMap.Builder<Character, String> allFlagsBuilder =
        new ImmutableMap.Builder<Character, String>().putAll(valueFlags);
    for (Character flag : booleanFlags) {
      allFlagsBuilder.put(flag, "true");
    }

    this.parsedArgs = ImmutableList.copyOf(parsedArgs);
    this.originalArgIndices = ImmutableList.copyOf(originalArgIndices);
    this.booleanFlags = ImmutableSet.copyOf(booleanFlags);
    this.valueFlags = ImmutableMap.copyOf(valueFlags);
    this.allFlags = allFlagsBuilder.build();
    this.suggestionContext = suggestionContext;
  }
コード例 #16
0
ファイル: PseudocodeImpl.java プロジェクト: libai1987/kotlin
 @Override
 public boolean isSideEffectFree(@NotNull Instruction instruction) {
   return sideEffectFree.contains(instruction);
 }
コード例 #17
0
ファイル: StandardTitanTx.java プロジェクト: rafatuita/titan
        @Override
        public Iterator<TitanElement> getNew(final StandardElementQuery query) {
          Preconditions.checkArgument(
              query.getType() == StandardElementQuery.Type.VERTEX
                  || query.getType() == StandardElementQuery.Type.EDGE);
          if (query.getType() == StandardElementQuery.Type.VERTEX && hasModifications()) {
            // Collect all keys from the query - ASSUMPTION: query is an AND of KeyAtom
            final Set<TitanKey> keys = Sets.newHashSet();
            KeyAtom<TitanKey> standardIndexKey = null;
            for (KeyCondition<TitanKey> cond : query.getCondition().getChildren()) {
              KeyAtom<TitanKey> atom = (KeyAtom<TitanKey>) cond;
              if (atom.getRelation() == Cmp.EQUAL && isVertexIndexProperty(atom.getKey()))
                standardIndexKey = atom;
              keys.add(atom.getKey());
            }
            Iterator<TitanVertex> vertices;
            if (standardIndexKey == null) {
              Set<TitanVertex> vertexSet = Sets.newHashSet();
              for (TitanRelation r :
                  addedRelations.getView(
                      new Predicate<InternalRelation>() {
                        @Override
                        public boolean apply(@Nullable InternalRelation relation) {
                          return keys.contains(relation.getType());
                        }
                      })) {
                vertexSet.add(((TitanProperty) r).getVertex());
              }
              for (TitanRelation r : deletedRelations.values()) {
                if (keys.contains(r.getType())) {
                  TitanVertex v = ((TitanProperty) r).getVertex();
                  if (!v.isRemoved()) vertexSet.add(v);
                }
              }
              vertices = vertexSet.iterator();
            } else {
              vertices =
                  Iterators.transform(
                      newVertexIndexEntries
                          .get(standardIndexKey.getCondition(), standardIndexKey.getKey())
                          .iterator(),
                      new Function<TitanProperty, TitanVertex>() {
                        @Nullable
                        @Override
                        public TitanVertex apply(@Nullable TitanProperty o) {
                          return o.getVertex();
                        }
                      });
            }

            return (Iterator)
                Iterators.filter(
                    vertices,
                    new Predicate<TitanVertex>() {
                      @Override
                      public boolean apply(@Nullable TitanVertex vertex) {
                        return query.matches(vertex);
                      }
                    });
          } else if (query.getType() == StandardElementQuery.Type.EDGE
              && !addedRelations.isEmpty()) {
            return (Iterator)
                addedRelations
                    .getView(
                        new Predicate<InternalRelation>() {
                          @Override
                          public boolean apply(@Nullable InternalRelation relation) {
                            return (relation instanceof TitanEdge)
                                && !relation.isHidden()
                                && query.matches(relation);
                          }
                        })
                    .iterator();
          } else throw new IllegalArgumentException("Unexpected type: " + query.getType());
        }
コード例 #18
0
 boolean contains(SSTableReader reader) {
   return update.contains(reader) || obsolete.contains(reader);
 }
コード例 #19
0
ファイル: CommandContext.java プロジェクト: RainoBoy97/Intake
 public boolean hasFlag(char ch) {
   return booleanFlags.contains(ch) || valueFlags.containsKey(ch);
 }