當前位置: 首頁>>代碼示例>>Java>>正文


Java Preconditions.checkElementIndex方法代碼示例

本文整理匯總了Java中com.google.common.base.Preconditions.checkElementIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java Preconditions.checkElementIndex方法的具體用法?Java Preconditions.checkElementIndex怎麽用?Java Preconditions.checkElementIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.base.Preconditions的用法示例。


在下文中一共展示了Preconditions.checkElementIndex方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAt

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
@Override
public L getAt(int index) {
  if (size != Integer.MAX_VALUE) {
    Preconditions.checkElementIndex(index, size());
  } // else no check necessary, all index values are valid
  ArrayReference<? extends L> existingRef = locks.get(index);
  L existing = existingRef == null ? null : existingRef.get();
  if (existing != null) {
    return existing;
  }
  L created = supplier.get();
  ArrayReference<L> newRef = new ArrayReference<L>(created, index, queue);
  while (!locks.compareAndSet(index, existingRef, newRef)) {
    // we raced, we need to re-read and try again
    existingRef = locks.get(index);
    existing = existingRef == null ? null : existingRef.get();
    if (existing != null) {
      return existing;
    }
  }
  drainQueue();
  return created;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:24,代碼來源:Striped.java

示例2: getFinalization

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
/**
 * Algorithm 7.37: GetFinalization
 *
 * @param i            the voter index
 * @param upper_bold_p the point matrix, one point per voter per candidate
 * @param upper_b      the current ballot list
 * @return this authority's part of the finalization code
 */
public FinalizationCodePart getFinalization(Integer i, List<List<Point>> upper_bold_p, Collection<BallotEntry> upper_b) {
    BigInteger p_prime = publicParameters.getPrimeField().getP_prime();
    Preconditions.checkArgument(upper_bold_p.stream().flatMap(Collection::stream)
                    .allMatch(point -> BigInteger.ZERO.compareTo(point.x) <= 0 &&
                            point.x.compareTo(p_prime) < 0 &&
                            BigInteger.ZERO.compareTo(point.y) <= 0 &&
                            point.y.compareTo(p_prime) < 0),
            "All points' coordinates must be in Z_p_prime");
    Preconditions.checkElementIndex(i, upper_bold_p.size());

    Object[] bold_p_i = upper_bold_p.get(i).toArray();
    byte[] upper_f_i = ByteArrayUtils.truncate(hash.recHash_L(bold_p_i), publicParameters.getUpper_l_f());

    BallotEntry ballotEntry = upper_b.stream().filter(b -> Objects.equals(b.getI(), i)).findFirst().orElseThrow(
            () -> new BallotNotFoundRuntimeException(String.format("Couldn't find any ballot for voter %d", i))
    );

    return new FinalizationCodePart(upper_f_i, ballotEntry.getBold_r());
}
 
開發者ID:republique-et-canton-de-geneve,項目名稱:chvote-protocol-poc,代碼行數:28,代碼來源:VoteConfirmationAuthorityAlgorithms.java

示例3: publishKeyPart

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
@Override
public void publishKeyPart(int j, EncryptionPublicKey publicKey) {
    Preconditions.checkState(publicParameters != null,
            "The public parameters need to have been defined first");
    Preconditions.checkElementIndex(j, publicParameters.getS(),
            "The index j should be lower than the number of authorities");
    publicKeyParts.put(j, publicKey);
}
 
開發者ID:republique-et-canton-de-geneve,項目名稱:chvote-protocol-poc,代碼行數:9,代碼來源:DefaultBulletinBoard.java

示例4: publishPublicCredentials

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
@Override
public void publishPublicCredentials(int j, List<Point> publicCredentials) {
    Preconditions.checkState(publicParameters != null,
            "The public parameters need to have been defined first");
    Preconditions.checkElementIndex(j, publicParameters.getS(),
            "The index j should be lower than the number of authorities");
    publicCredentialsParts.put(j, publicCredentials);
}
 
開發者ID:republique-et-canton-de-geneve,項目名稱:chvote-protocol-poc,代碼行數:9,代碼來源:DefaultBulletinBoard.java

示例5: publishShuffleAndProof

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
@Override
public void publishShuffleAndProof(int j, List<Encryption> shuffle, ShuffleProof proof) {
    Preconditions.checkElementIndex(j, publicParameters.getS(),
            "j needs to be within bounds");
    Preconditions.checkArgument(shuffles.size() == j,
            "Shuffle j can only be inserted after the previous shuffles");
    Preconditions.checkArgument(shuffleProofs.size() == j,
            "Shuffle proof j can only be inserted after the previous shuffle proof");
    shuffles.put(j, shuffle);
    shuffleProofs.put(j, proof);
}
 
開發者ID:republique-et-canton-de-geneve,項目名稱:chvote-protocol-poc,代碼行數:12,代碼來源:DefaultBulletinBoard.java

示例6: getPreviousShuffle

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
@Override
public List<Encryption> getPreviousShuffle(int j) {
    Preconditions.checkElementIndex(j, publicParameters.getS(),
            "j needs to be within bounds");
    Preconditions.checkArgument(shuffles.containsKey(j),
            "Can't retrieve a shuffle that hasn't been inserted");
    return shuffles.get(j);
}
 
開發者ID:republique-et-canton-de-geneve,項目名稱:chvote-protocol-poc,代碼行數:9,代碼來源:DefaultBulletinBoard.java

示例7: publishPartialDecryptionAndProof

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
@Override
public void publishPartialDecryptionAndProof(int j, List<BigInteger> partialDecryption, DecryptionProof proof) {
    Preconditions.checkElementIndex(j, publicParameters.getS(),
            "j needs to be within bounds");
    Preconditions.checkState(shuffles.size() == publicParameters.getS(),
            "The decryptions may only start when all the shuffles have been published");
    Preconditions.checkState(shuffleProofs.size() == publicParameters.getS(),
            "The decryptions may only start when all the shuffles proofs have been published");
    Preconditions.checkArgument(!partialDecryptions.containsKey(j),
            "Partial decryptions may not be updated");
    Preconditions.checkArgument(!decryptionProofs.containsKey(j),
            "Partial decryptions proofs may not be updated");
    partialDecryptions.put(j, partialDecryption);
    decryptionProofs.put(j, proof);
}
 
開發者ID:republique-et-canton-de-geneve,項目名稱:chvote-protocol-poc,代碼行數:16,代碼來源:DefaultBulletinBoard.java

示例8: checkBallot

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
/**
 * Algorithm 7.22: CheckBallot
 *
 * @param i          the voter index
 * @param alpha      the submitted ballot, including the oblivious transfer query
 * @param pk         the encryption public key
 * @param bold_x_hat the vector of public voter credentials
 * @param upper_b    the current ballot list
 * @return true if the ballot was valid
 */
public boolean checkBallot(Integer i, BallotAndQuery alpha, EncryptionPublicKey pk,
                           List<BigInteger> bold_x_hat, Collection<BallotEntry> upper_b) {
    Preconditions.checkNotNull(i);
    Preconditions.checkNotNull(alpha);
    List<BigInteger> bold_a = alpha.getBold_a();
    Preconditions.checkNotNull(bold_a);
    Preconditions.checkArgument(bold_a.stream().allMatch(generalAlgorithms::isMember),
            "All of the a_j's must be members of G_q");
    Preconditions.checkArgument(generalAlgorithms.isMember(alpha.getB()),
            "b must be a member of G_q");

    int numberOfSelections = bold_a.size();
    Preconditions.checkArgument(numberOfSelections > 0);
    Voter voter = electionSet.getVoters().get(i);
    int k_i = electionSet.getElections().stream().filter(e -> electionSet.isEligible(voter, e))
            .mapToInt(Election::getNumberOfSelections).sum();
    Preconditions.checkArgument(numberOfSelections == k_i,
            "A voter may not submit more than his allowed number of selections");
    Preconditions.checkNotNull(pk);
    Preconditions.checkNotNull(bold_x_hat);
    Preconditions.checkElementIndex(i, bold_x_hat.size());
    Preconditions.checkNotNull(upper_b);

    BigInteger p = publicParameters.getEncryptionGroup().getP();
    BigInteger x_hat_i = bold_x_hat.get(i);
    if (!hasBallot(i, upper_b) && alpha.getX_hat().compareTo(x_hat_i) == 0) {
        BigInteger a = bold_a.stream().reduce(BigInteger::multiply)
                .orElse(ONE)
                .mod(p);
        return checkBallotProof(alpha.getPi(), alpha.getX_hat(), a, alpha.getB(), pk);
    }
    return false;
}
 
開發者ID:republique-et-canton-de-geneve,項目名稱:chvote-protocol-poc,代碼行數:44,代碼來源:VoteCastingAuthorityAlgorithms.java

示例9: checkShuffleProofs

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
/**
 * Algorithms 7.47: checkShuffleProofs
 *
 * @param bold_pi   the shuffle proofs generated by the authorities
 * @param e_0       the original encryption
 * @param bold_E    the vector of the re-encryption lists, per authority
 * @param publicKey the public key
 * @param j         the index of this authority
 * @return true if all the proofs generated by the other authorities are valid, false otherwise
 */
public boolean checkShuffleProofs(List<ShuffleProof> bold_pi, List<Encryption> e_0,
                                  List<List<Encryption>> bold_E, EncryptionPublicKey publicKey, int j) {
    int s = publicParameters.getS();
    int N = e_0.size();
    Preconditions.checkArgument(bold_pi.size() == s,
            "there should be as many proofs as there are authorities");
    Preconditions.checkArgument(bold_E.size() == s,
            "there should be as many lists of re-encryptions as there are authorities");
    Preconditions.checkArgument(bold_E.stream().map(List::size).allMatch(l -> l == N),
            "every re-encryption list should have length N");
    Preconditions.checkElementIndex(j, s,
            "The index of the authority should be valid with respect to the number of authorities");

    // insert e_0 at index 0, thus offsetting all indices for bold_E by 1
    List<List<Encryption>> tmp_bold_e = new ArrayList<>();
    tmp_bold_e.add(0, e_0);
    tmp_bold_e.addAll(bold_E);
    for (int i = 0; i < s; i++) {
        if (i != j) {
            if (!checkShuffleProof(
                    bold_pi.get(i), tmp_bold_e.get(i), tmp_bold_e.get(i + 1), publicKey)) {
                return false;
            }
        }
    }
    return true;
}
 
開發者ID:republique-et-canton-de-geneve,項目名稱:chvote-protocol-poc,代碼行數:38,代碼來源:DecryptionAuthorityAlgorithms.java

示例10: populate

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
private void populate(List<PlanFragment> fragments){
  Map<NodeEndpoint, NodeTracker> trackers = new HashMap<>();
  Map<FragmentHandle, FragmentData> dataCollectors = new HashMap<>();
  ArrayListMultimap<Integer, FragmentData> majors = ArrayListMultimap.create();

  for(PlanFragment fragment : fragments) {
    final NodeEndpoint assignment = fragment.getAssignment();

    NodeTracker tracker = trackers.get(assignment);
    if (tracker == null) {
      tracker = new NodeTracker(assignment);
      trackers.put(assignment, tracker);
    }

    tracker.addFragment();
    FragmentData data = new FragmentData(fragment.getHandle(), assignment);
    dataCollectors.put(fragment.getHandle(), data);
    majors.put(fragment.getHandle().getMajorFragmentId(), data);
  }

  // Major fragments are required to be dense: numbered 0 through N-1
  MajorFragmentReporter[] tempReporters = new MajorFragmentReporter[majors.asMap().size()];
  for(Map.Entry<Integer, Collection<FragmentData>> e : majors.asMap().entrySet()) {
    Preconditions.checkElementIndex(e.getKey(), majors.asMap().size());
    Preconditions.checkState(tempReporters[e.getKey()] == null);
    tempReporters[e.getKey()] = new MajorFragmentReporter(e.getKey(), e.getValue());
  }

  this.reporters = ImmutableList.copyOf(tempReporters);
  this.nodeMap = ImmutableMap.copyOf(trackers);
  this.fragmentDataMap = ImmutableMap.copyOf(dataCollectors);
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:33,代碼來源:QueryManager.java

示例11: reconfigure

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
void reconfigure(int sizeIndex, int[] bucketSizes, long bucketCapacity) {
  Preconditions.checkElementIndex(sizeIndex, bucketSizes.length);
  this.sizeIndex = sizeIndex;
  itemAllocationSize = bucketSizes[sizeIndex];
  itemCount = (int) (bucketCapacity / (long) itemAllocationSize);
  freeCount = itemCount;
  usedCount = 0;
  freeList = new int[itemCount];
  for (int i = 0; i < freeCount; ++i)
    freeList[i] = i;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:12,代碼來源:BucketAllocator.java

示例12: get

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
@Override
public E get(int index) {
  Preconditions.checkElementIndex(index, 1);
  return element;
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:6,代碼來源:SingletonImmutableList.java

示例13: isLeftAt

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
boolean isLeftAt(int index) {
  Preconditions.checkElementIndex(index, pathLength);
  return ((Long.MIN_VALUE >>> index) & leftRight) == 0;
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:5,代碼來源:TreePath.java

示例14: get

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
private byte[] get(short idx) {
  Preconditions.checkElementIndex(idx, currSize);
  moveToHead(indexToNode[idx]);
  return indexToNode[idx].container;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:6,代碼來源:LRUDictionary.java

示例15: get

import com.google.common.base.Preconditions; //導入方法依賴的package包/類
/**
 * Returns the {@code int} value present at the given index.
 *
 * @throws IndexOutOfBoundsException if {@code index} is negative, or greater than or equal to
 *     {@link #length}
 */
public int get(int index) {
  Preconditions.checkElementIndex(index, length());
  return array[start + index];
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:11,代碼來源:ImmutableIntArray.java


注:本文中的com.google.common.base.Preconditions.checkElementIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。