本文整理汇总了Java中com.google.common.base.Verify类的典型用法代码示例。如果您正苦于以下问题:Java Verify类的具体用法?Java Verify怎么用?Java Verify使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Verify类属于com.google.common.base包,在下文中一共展示了Verify类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TypevarContext
import com.google.common.base.Verify; //导入依赖的package包/类
TypevarContext(TypeElement element, String renderedTypeString) {
List<? extends TypeParameterElement> typeParameters = element.getTypeParameters();
if (!typeParameters.isEmpty()) {
this.arguments = SourceTypes.extract(renderedTypeString).getValue();
this.parameters = Lists.newArrayList();
for (TypeParameterElement p : typeParameters) {
parameters.add(p.getSimpleName().toString());
}
// we allow having no arguments in a string as raw type/unspecified argument scenario
Verify.verify(arguments.isEmpty() || (parameters.size() == arguments.size()), parameters + " =/> " + arguments);
} else {
this.parameters = Collections.emptyList();
this.arguments = Collections.emptyList();
}
}
示例2: signature
import com.google.common.base.Verify; //导入依赖的package包/类
private boolean signature(Statement.Builder builder) {
Term t = terms.peek();
if (t.is("@")) {
do {
builder.addAnnotations(terms.next());
Verify.verify(terms.peek().isWordOrNumber());
builder.addAnnotations(terms.next());
} while (terms.peek().is("."));
if (terms.peek().is("(")) {
builder.addAllAnnotations(collectUntilMatching(")"));
}
return false;
} else if (t.is("<")) {
builder.addAllSignature(collectUntilMatching(">"));
return false;
} else if (t.is("class")) {
builder.addSignature(terms.next());
return true;
} else {
builder.addSignature(terms.next());
return false;
}
}
示例3: await
import com.google.common.base.Verify; //导入依赖的package包/类
/** Waits for the supplier to return a present value. */
private <T> T await(Supplier<Optional<T>> compute) throws IOException {
AtomicReference<T> result = new AtomicReference<>();
BooleanSupplier condition =
() -> {
Optional<T> value = compute.get();
if (value.isPresent()) {
result.set(value.get());
}
return value.isPresent();
};
try {
monitor.enterWhen(monitor.newGuard(condition));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException(e);
}
try {
return Verify.verifyNotNull(result.get());
} finally {
monitor.leave();
}
}
示例4: from
import com.google.common.base.Verify; //导入依赖的package包/类
/**
* Classifies an identifier's case format.
*/
static JavaCaseFormat from(String name) {
Verify.verify(!name.isEmpty());
boolean firstUppercase = false;
boolean hasUppercase = false;
boolean hasLowercase = false;
boolean first = true;
for (int i = 0; i < name.length(); i++) {
char c = name.charAt(i);
if (!Character.isAlphabetic(c)) {
continue;
}
if (first) {
firstUppercase = Character.isUpperCase(c);
first = false;
}
hasUppercase |= Character.isUpperCase(c);
hasLowercase |= Character.isLowerCase(c);
}
if (firstUppercase) {
return hasLowercase ? UPPER_CAMEL : UPPERCASE;
} else {
return hasUppercase ? LOWER_CAMEL : LOWERCASE;
}
}
示例5: encodeBits
import com.google.common.base.Verify; //导入依赖的package包/类
/**
* Encodes an arbitrary bitstring into a RAPPOR report.
*
* @param bits A bitstring in which only the least significant numBits bits may be 1.
*/
private byte[] encodeBits(BitSet bits) {
BitSet permanentRandomizedResponse = computePermanentRandomizedResponse(bits);
BitSet encodedBitSet = computeInstantaneousRandomizedResponse(permanentRandomizedResponse);
// BitSet.toByteArray only returns enough bytes to capture the most significant bit
// that is set. For example, a BitSet with no bits set could return a length-0 array.
// In contrast, we guarantee that our output is sized according to numBits.
byte[] encodedBytes = encodedBitSet.toByteArray();
byte[] output = new byte[(numBits + 7) / 8];
Verify.verify(encodedBytes.length <= output.length);
System.arraycopy(
encodedBytes, // src
0, // srcPos
output, // dest
0, // destPos
encodedBytes.length); // length
return output;
}
示例6: toLeaderState
import com.google.common.base.Verify; //导入依赖的package包/类
/**
* Transform frontend metadata for a particular client into its {@link LeaderFrontendState} counterpart.
*
* @param shard parent shard
* @return Leader frontend state
*/
@Nonnull LeaderFrontendState toLeaderState(@Nonnull final Shard shard) {
// Note: we have to make sure to *copy* all current state and not leak any views, otherwise leader/follower
// interactions would get intertwined leading to inconsistencies.
final Map<LocalHistoryIdentifier, LocalFrontendHistory> histories = new HashMap<>();
for (FrontendHistoryMetadataBuilder e : currentHistories.values()) {
if (e.getIdentifier().getHistoryId() != 0) {
final AbstractFrontendHistory state = e.toLeaderState(shard);
Verify.verify(state instanceof LocalFrontendHistory);
histories.put(e.getIdentifier(), (LocalFrontendHistory) state);
}
}
final AbstractFrontendHistory singleHistory;
final FrontendHistoryMetadataBuilder singleHistoryMeta = currentHistories.get(
new LocalHistoryIdentifier(identifier, 0));
if (singleHistoryMeta == null) {
final ShardDataTree tree = shard.getDataStore();
singleHistory = StandaloneFrontendHistory.create(shard.persistenceId(), getIdentifier(), tree);
} else {
singleHistory = singleHistoryMeta.toLeaderState(shard);
}
return new LeaderFrontendState(shard.persistenceId(), getIdentifier(), shard.getDataStore(),
purgedHistories.copy(), singleHistory, histories);
}
示例7: readExternal
import com.google.common.base.Verify; //导入依赖的package包/类
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
final int metaSize = in.readInt();
Preconditions.checkArgument(metaSize >= 0, "Invalid negative metadata map length %s", metaSize);
// Default pre-allocate is 4, which should be fine
final Builder<Class<? extends ShardDataTreeSnapshotMetadata<?>>, ShardDataTreeSnapshotMetadata<?>>
metaBuilder = ImmutableMap.builder();
for (int i = 0; i < metaSize; ++i) {
final ShardDataTreeSnapshotMetadata<?> m = (ShardDataTreeSnapshotMetadata<?>) in.readObject();
if (m != null) {
metaBuilder.put(m.getType(), m);
} else {
LOG.warn("Skipping null metadata");
}
}
metadata = metaBuilder.build();
rootNode = Verify.verifyNotNull(SerializationUtils.deserializeNormalizedNode(in));
}
示例8: createLocalHistory
import com.google.common.base.Verify; //导入依赖的package包/类
@Override
public final ClientLocalHistory createLocalHistory() {
final LocalHistoryIdentifier historyId = new LocalHistoryIdentifier(getIdentifier(),
nextHistoryId.getAndIncrement());
final long stamp = lock.readLock();
try {
if (aborted != null) {
Throwables.throwIfUnchecked(aborted);
throw new RuntimeException(aborted);
}
final ClientLocalHistory history = new ClientLocalHistory(this, historyId);
LOG.debug("{}: creating a new local history {}", persistenceId(), history);
Verify.verify(histories.put(historyId, history) == null);
return history;
} finally {
lock.unlockRead(stamp);
}
}
示例9: receiveGossipTick
import com.google.common.base.Verify; //导入依赖的package包/类
/**
* Sends Gossip status to other members in the cluster.
* <br>
* 1. If there are no member, ignore the tick. <br>
* 2. If there's only 1 member, send gossip status (bucket versions) to it. <br>
* 3. If there are more than one member, randomly pick one and send gossip status (bucket versions) to it.
*/
@VisibleForTesting
void receiveGossipTick() {
final Address address;
switch (clusterMembers.size()) {
case 0:
//no members to send gossip status to
return;
case 1:
address = clusterMembers.get(0);
break;
default:
final int randomIndex = ThreadLocalRandom.current().nextInt(0, clusterMembers.size());
address = clusterMembers.get(randomIndex);
break;
}
LOG.trace("Gossiping to [{}]", address);
getLocalStatusAndSendTo(Verify.verifyNotNull(peers.get(address)));
}
示例10: checkNotNull
import com.google.common.base.Verify; //导入依赖的package包/类
@SuppressWarnings("unchecked") // Callers shouldn't be accessing this method.
/* package */ PineappleField(Field field) {
this.field = checkNotNull(field, "Null field");
checkArgument(
field.isAccessible()
|| Modifier.isPublic(field.getModifiers())
&& Modifier.isPublic(field.getDeclaringClass().getModifiers()),
"Field isn't accessible: %s",
field
);
this.declaringClass = (Class<T>) field.getDeclaringClass();
this.fieldType = (Class<V>) field.getType();
this.modifiers = field.getModifiers();
this.primitiveType = PrimitiveType.fromClass(field.getType());
Verify.verify(this.isPrimitive() == field.getType().isPrimitive());
}
示例11: scanClasspath
import com.google.common.base.Verify; //导入依赖的package包/类
private static ImmutableMap<Block, BiFunction<WetServer, IBlockState, ? extends WetBlockState>> scanClasspath() {
ImmutableMap.Builder<Block, BiFunction<WetServer, IBlockState, ? extends WetBlockState>> builder = ImmutableMap.builder();
Reflections reflections = new Reflections(getReflectionsConfiguration("org.fountainmc.world.block"));
Set<Class<?>> types = reflections.getTypesAnnotatedWith(BlockStateImpl.class);
if (types != null) {
for (Class<?> type : types) {
Verify.verify(WetBlockState.class.isAssignableFrom(type), "Class %s isn't instanceof WetBlockState", type.getTypeName());
for (String blockName : ImmutableList.copyOf(type.getAnnotation(BlockStateImpl.class).value())) {
Block block = Verify.verifyNotNull(Block.getBlockFromName(blockName),
"Class %s specified unknown block name minecraft:%s.", type.getTypeName(), blockName);
builder.put(block, (server, state) -> {
try {
Constructor<?> constructor = type.getConstructor(WetServer.class, IBlockState.class);
return (WetBlockState) constructor.newInstance(server, state);
} catch (Exception e) {
e.printStackTrace();
}
return null;
});
}
}
}
return builder.build();
}
示例12: CombatTagLegacySupport
import com.google.common.base.Verify; //导入依赖的package包/类
public CombatTagLegacySupport() {
CombatTagApi api = null;
Plugin plugin = Bukkit.getPluginManager().getPlugin(PLUGIN_NAME);
try {
api = CombatTagApi.getInstance();
} catch (NoClassDefFoundError | NoSuchMethodError e) { // Old version or not installed
try {
if (plugin instanceof CombatTag) {
api = new CombatTagApi((CombatTag) plugin);
}
} catch (NoClassDefFoundError | NoSuchMethodError ignored) {}
}
Verify.verify((plugin == null) == (api == null), "Could %s plugin, but could %s api!", plugin == null ? "not find" : "find", api == null ? "not find" : "find");
this.api = api;
this.plugin = plugin;
}
示例13: evaluateImpl
import com.google.common.base.Verify; //导入依赖的package包/类
@Nullable
@Override
public Object evaluateImpl(Long f) {
Native.LongPtr out = new Native.LongPtr();
boolean status = Native.modelEval(z3context, model, f, false, out);
Verify.verify(status, "Error during model evaluation");
long outValue = out.value;
if (z3creator.isConstant(outValue)) {
return z3creator.convertValue(outValue);
}
// Z3 does not give us a direct API to query for "irrelevant" ASTs during evaluation.
// The only hint we get is that the input AST is not simplified down to a constant:
// thus, it is assumed to be irrelevant.
return null;
}
示例14: getCommitsBetweenReferences
import com.google.common.base.Verify; //导入依赖的package包/类
/**
* Returns a list of commits between two references.
* @param repoPath path to local git repository.
* @param startRef start reference.
* @param endRef end reference.
* @return a list of commits.
* @throws IOException if I/O error occurs.
* @throws GitAPIException if an error occurs when accessing Git API.
*/
private static Set<RevCommit> getCommitsBetweenReferences(String repoPath, String startRef,
String endRef) throws IOException, GitAPIException {
final FileRepositoryBuilder builder = new FileRepositoryBuilder();
final Path path = Paths.get(repoPath);
final Repository repo = builder.findGitDir(path.toFile()).readEnvironment().build();
final ObjectId startCommit = getActualRefObjectId(repo, startRef);
Verify.verifyNotNull(startCommit, "Start reference \"" + startRef + "\" is invalid!");
final ObjectId endCommit = getActualRefObjectId(repo, endRef);
final Iterable<RevCommit> commits =
new Git(repo).log().addRange(startCommit, endCommit).call();
return Sets.newLinkedHashSet(commits);
}
示例15: from
import com.google.common.base.Verify; //导入依赖的package包/类
/** Classifies an identifier's case format. */
static JavaCaseFormat from(String name) {
Verify.verify(!name.isEmpty());
boolean firstUppercase = false;
boolean hasUppercase = false;
boolean hasLowercase = false;
boolean first = true;
for (int i = 0; i < name.length(); i++) {
char c = name.charAt(i);
if (!Character.isAlphabetic(c)) {
continue;
}
if (first) {
firstUppercase = Character.isUpperCase(c);
first = false;
}
hasUppercase |= Character.isUpperCase(c);
hasLowercase |= Character.isLowerCase(c);
}
if (firstUppercase) {
return hasLowercase ? UPPER_CAMEL : UPPERCASE;
} else {
return hasUppercase ? LOWER_CAMEL : LOWERCASE;
}
}