本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例12: get
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public E get(int index) {
Preconditions.checkElementIndex(index, 1);
return element;
}
示例13: isLeftAt
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
boolean isLeftAt(int index) {
Preconditions.checkElementIndex(index, pathLength);
return ((Long.MIN_VALUE >>> index) & leftRight) == 0;
}
示例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;
}
示例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];
}