本文整理汇总了Java中com.google.common.base.Preconditions.checkNotNull方法的典型用法代码示例。如果您正苦于以下问题:Java Preconditions.checkNotNull方法的具体用法?Java Preconditions.checkNotNull怎么用?Java Preconditions.checkNotNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.base.Preconditions
的用法示例。
在下文中一共展示了Preconditions.checkNotNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SwitchRepresentation
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
public SwitchRepresentation(@Nonnull IOFSwitch sw, @Nonnull OFSwitchHandshakeHandler handshakeHandler) {
Preconditions.checkNotNull(sw, "switch must not be null");
Preconditions.checkNotNull(handshakeHandler, "handshakeHandler must not be null");
// IOFSwitch
this.buffers = sw.getBuffers();
this.capabilities = sw.getCapabilities();
this.tables = sw.getNumTables();
this.inetAddress = sw.getInetAddress();
this.sortedPorts = sw.getSortedPorts();
this.isConnected = sw.isConnected();
this.connectedSince = sw.getConnectedSince();
this.dpid = sw.getId();
this.attributes = sw.getAttributes();
this.isActive = sw.isActive();
// OFSwitchHandshakeHandler
this.connections = handshakeHandler.getConnections();
this.handshakeState = handshakeHandler.getState();
this.quarantineReason = handshakeHandler.getQuarantineReason();
}
示例2: buildRowKey
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public RowKey buildRowKey(StatEventKey statEventKey) {
Preconditions.checkNotNull(statEventKey);
long timeMs = statEventKey.getTimeMs();
final byte[] partialTimestamp = buildPartialTimestamp(timeMs);
final byte[] rollupBitMask = statEventKey.getRollupMask().asBytes();
List<RowKeyTagValue> rowKeyTagValues = statEventKey.getTagValues().stream()
.map(tagValue -> new RowKeyTagValue(tagValue.getTag(), tagValue.getValue()))
.collect(Collectors.toList());
TimeAgnosticRowKey timeAgnosticRowKey = new TimeAgnosticRowKey(
statEventKey.getStatUuid(),
rollupBitMask,
rowKeyTagValues);
//timeMs is already rounded to the column interval
return new RowKey(timeAgnosticRowKey, partialTimestamp);
}
示例3: toByteArray
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public final byte[] toByteArray(boolean shrink) {
ByteBuffer buffer = ByteBuffer.allocate(size());
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort((short) headerSize());
buffer.putShort((short) flags());
buffer.putInt(keyIndex());
if (isComplex()) {
buffer.putInt(parentEntry());
buffer.putInt(values().size());
for (Map.Entry<Integer, ResourceValue> entry : values().entrySet()) {
buffer.putInt(entry.getKey());
buffer.put(entry.getValue().toByteArray(shrink));
}
} else {
ResourceValue value = value();
Preconditions.checkNotNull(value, "A non-complex TypeChunk entry must have a value.");
buffer.put(value.toByteArray());
}
return buffer.array();
}
示例4: cancelDelegationToken
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
* Cancels a delegation token from the server end-point. It does not require
* being authenticated by the configured <code>Authenticator</code>.
*
* @param url the URL to cancel the delegation token from. Only HTTP/S URLs
* are supported.
* @param token the authentication token with the Delegation Token to cancel.
* @param doAsUser the user to do as, which will be the token owner.
* @throws IOException if an IO error occurred.
*/
public void cancelDelegationToken(URL url, Token token, String doAsUser)
throws IOException {
Preconditions.checkNotNull(url, "url");
Preconditions.checkNotNull(token, "token");
Preconditions.checkNotNull(token.delegationToken,
"No delegation token available");
try {
((KerberosDelegationTokenAuthenticator) getAuthenticator()).
cancelDelegationToken(url, token, token.delegationToken, doAsUser);
} finally {
token.delegationToken = null;
}
}
示例5: subscribe
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public void subscribe(URL url, NotifyListener listener) {
Preconditions.checkNotNull(url);
Preconditions.checkNotNull(listener);
URL urlCopy = url.clone0();
doSubscribe(urlCopy, listener);
//第一次订阅时主动推一次
// List<URL> urls = doDiscover(urlCopy);
// if (urls != null && urls.size() > 0) {
// listener.notify(url, urls);
// }
}
示例6: join
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
* Returns a normalized, combined path out of the given path segments.
*
* @param parts path segments to combine
* @see #normalize(String)
*/
public static final String join(final String... parts) {
final StringBuilder sb = new StringBuilder();
for (final String part:parts) {
Preconditions.checkNotNull(part, "parts cannot contain null");
if (!Strings.isNullOrEmpty(part)) {
sb.append(part).append("/");
}
}
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1);
}
final String path = sb.toString();
return normalize(path);
}
示例7: getSplitsQuery
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
public static SearchQuery getSplitsQuery(DatasetConfig datasetConfig) {
Preconditions.checkNotNull(datasetConfig.getReadDefinition());
Preconditions.checkNotNull(datasetConfig.getReadDefinition().getSplitVersion());
return SearchQueryUtils.and(
SearchQueryUtils.newTermQuery(DATASET_ID, datasetConfig.getId().getId()),
SearchQueryUtils.newTermQuery(SPLIT_VERSION.getIndexFieldName(), datasetConfig.getReadDefinition().getSplitVersion()));
}
示例8: ModelReference
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
private ModelReference(@Nullable ModelPath path, ModelType<T> type, @Nullable ModelPath scope, @Nullable ModelNode.State state, @Nullable String description) {
this.path = path;
this.type = Preconditions.checkNotNull(type, "type");
this.scope = scope;
this.description = description;
this.state = state != null ? state : ModelNode.State.GraphClosed;
}
示例9: createFromEC2
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public EsInstance createFromEC2(Instance awsInstance) throws Exception {
Preconditions.checkNotNull(awsInstance);
EsInstance esInstance = new EsInstance();
esInstance.setId(awsInstance.getInstanceId());
esInstance.setState(awsInstance.getState().getName());
esInstance.setLocation(awsInstance.getPlacement().getAvailabilityZone());
//Region=location-last char. This is what CMDBV1 and people on internet do.
//There should be a better way. Right now, keep as what it is
esInstance.setRegion(
esInstance.getLocation().substring(0, esInstance.getLocation().length() - 1));
esInstance.setAwsLaunchTime(awsInstance.getLaunchTime());
esInstance.setSubnetId(awsInstance.getSubnetId());
esInstance.setVpcId(awsInstance.getVpcId());
//Convert AWS instance to a map of property bags and save it.
esInstance.getCloud()
.put("aws", getAwsInstanceProperties(awsInstance));
Date utcNow = DateTime.now(DateTimeZone.UTC).toDate();
esInstance.setCreatedTime(utcNow);
esInstance.setUpdatedTime(utcNow);
return esInstance;
}
示例10: addDataPoint
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
public StatisticDataSet addDataPoint(StatisticDataPoint dataPoint) {
Preconditions.checkNotNull(dataPoint);
//datapoint must be for the same statConfig as the dataset as a whole
Preconditions.checkArgument(dataPoint.getStatisticConfiguration().getUuid().equals(statisticConfiguration.getUuid()));
Preconditions.checkArgument(dataPoint.getTimeInterval().equals(timeInterval));
this.statisticDataPoints.add(dataPoint);
return this;
}
示例11: addPartition
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
/**
* Creates a new partition with the given name.
*
* @throws IllegalArgumentException if such partition already exists.
*/
public Partition addPartition(String name) {
Preconditions.checkNotNull(name, "Name cannot be null.");
Preconditions.checkArgument(!mPartitionsByName.containsKey(name),
"Partition with such name already exists.");
Partition partition = new Partition(name);
mPartitionsByName.put(name, partition);
return partition;
}
示例12: serialize
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public JsonElement serialize(
final ResolvedDependency resolvedDependency, final Type type, final JsonSerializationContext context) {
Preconditions.checkNotNull(resolvedDependency);
Preconditions.checkNotNull(type);
Preconditions.checkNotNull(context);
final JsonObject jsonObject = new JsonObject();
final JsonElement sourceElement = Either.join(
resolvedDependency.source,
context::serialize,
context::serialize);
jsonObject.add("source", sourceElement);
if (resolvedDependency.target.isPresent()) {
jsonObject.addProperty("target", resolvedDependency.target.get());
}
if (!resolvedDependency.dependencies.isEmpty()) {
jsonObject.add("dependencies", context.serialize(resolvedDependency.dependencies));
}
if (resolvedDependency.buckResource.isPresent()) {
jsonObject.add("buck", context.serialize(resolvedDependency.buckResource.get(), RemoteFile.class));
}
return jsonObject;
}
示例13: verify
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
private void verify() {
Preconditions.checkNotNull(shardingService);
Preconditions.checkNotNull(actorSystem);
Preconditions.checkNotNull(cluster);
Preconditions.checkNotNull(distributedConfigDatastore);
Preconditions.checkNotNull(distributedOperDatastore);
}
示例14: builder
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
@Override
public QueryBuilder builder() {
return Preconditions.checkNotNull(builder);
}
示例15: hasPlacer
import com.google.common.base.Preconditions; //导入方法依赖的package包/类
public boolean hasPlacer(@Nonnull Block block) {
Preconditions.checkNotNull(block, "block");
return this.placedAnvils.containsKey(block);
}