com.google.common.base.Verify.verifyNotNull()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中com.google.common.base.Verify.verifyNotNull()方法的一些代码示例,展示了Verify.verifyNotNull()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Verify.verifyNotNull()方法的具体详情如下:
包路径:com.google.common.base.Verify
类名称:Verify
方法名:verifyNotNull

Verify.verifyNotNull介绍

[英]Ensures that reference is non-null, throwing a VerifyException with a default message otherwise.
[中]确保引用不为null,否则会抛出带有默认消息的VerifyException。

代码示例

代码示例来源:origin: google/guava

/**
 * Ensures that {@code reference} is non-null, throwing a {@code VerifyException} with a default
 * message otherwise.
 *
 * @return {@code reference}, guaranteed to be non-null, for convenience
 * @throws VerifyException if {@code reference} is {@code null}
 * @see Preconditions#checkNotNull Preconditions.checkNotNull()
 */
@CanIgnoreReturnValue
public static <T> T verifyNotNull(@Nullable T reference) {
 return verifyNotNull(reference, "expected a non-null reference");
}

代码示例来源:origin: googleapis/google-cloud-java

private BigtableTableAdminSettings(Builder builder) throws IOException {
 this.projectId = Preconditions.checkNotNull(builder.projectId, "Project id must be set");
 this.instanceId = Preconditions.checkNotNull(builder.instanceId, "Instance id must be set");
 this.stubSettings =
   Verify.verifyNotNull(builder.stubSettings, "stubSettings should never be null").build();
}

代码示例来源:origin: googleapis/google-cloud-java

private BigtableInstanceAdminSettings(Builder builder) throws IOException {
 Preconditions.checkNotNull(builder.projectId, "Project ud must be set");
 Verify.verifyNotNull(builder.stubSettings, "stubSettings should never be null");
 this.projectId = builder.projectId;
 this.stubSettings = builder.stubSettings.build();
}

代码示例来源:origin: google/guava

public void testVerifyNotNull_simple_failure() {
 try {
  verifyNotNull(null);
  fail();
 } catch (VerifyException expected) {
 }
}

代码示例来源:origin: google/guava

public void testVerifyNotNull_simple_success() {
 String result = verifyNotNull(NON_NULL_STRING);
 assertSame(NON_NULL_STRING, result);
}

代码示例来源:origin: google/guava

public void testVerifyNotNull_complexMessage_success() {
 String result = verifyNotNull(NON_NULL_STRING, "%s", IGNORE_ME);
 assertSame(NON_NULL_STRING, result);
}

代码示例来源:origin: google/j2objc

/**
 * Ensures that {@code reference} is non-null, throwing a {@code VerifyException} with a default
 * message otherwise.
 *
 * @return {@code reference}, guaranteed to be non-null, for convenience
 * @throws VerifyException if {@code reference} is {@code null}
 * @see Preconditions#checkNotNull Preconditions.checkNotNull()
 */
@CanIgnoreReturnValue
public static <T> T verifyNotNull(@NullableDecl T reference) {
 return verifyNotNull(reference, "expected a non-null reference");
}

代码示例来源:origin: GoogleContainerTools/jib

/**
 * Pushes the image manifest for a specific tag.
 *
 * @param manifestTemplate the image manifest
 * @param imageTag the tag to push on
 * @return the digest of the pushed image
 * @throws IOException if communicating with the endpoint fails
 * @throws RegistryException if communicating with the endpoint fails
 */
public DescriptorDigest pushManifest(BuildableManifestTemplate manifestTemplate, String imageTag)
  throws IOException, RegistryException {
 return Verify.verifyNotNull(
   callRegistryEndpoint(
     new ManifestPusher(
       registryEndpointRequestProperties, manifestTemplate, imageTag, eventDispatcher)));
}

代码示例来源:origin: google/google-java-format

@Override
public int getLineNumber(int inputPosition) {
 Verify.verifyNotNull(unit, "Expected compilation unit to be set.");
 return unit.getLineMap().getLineNumber(inputPosition);
}

代码示例来源:origin: google/google-java-format

@Override
public int getColumnNumber(int inputPosition) {
 Verify.verifyNotNull(unit, "Expected compilation unit to be set.");
 return unit.getLineMap().getColumnNumber(inputPosition);
}

代码示例来源:origin: wildfly/wildfly

/**
 * Ensures that {@code reference} is non-null, throwing a {@code VerifyException} with a default
 * message otherwise.
 *
 * @return {@code reference}, guaranteed to be non-null, for convenience
 * @throws VerifyException if {@code reference} is {@code null}
 * @see Preconditions#checkNotNull Preconditions.checkNotNull()
 */
@CanIgnoreReturnValue
public static <T> T verifyNotNull(@NullableDecl T reference) {
 return verifyNotNull(reference, "expected a non-null reference");
}

代码示例来源:origin: google/guava

public void testVerifyNotNull_simpleMessage_failure() {
 try {
  verifyNotNull(null, FORMAT, 5);
  fail();
 } catch (VerifyException expected) {
  checkMessage(expected);
 }
}

代码示例来源:origin: googleapis/google-cloud-java

/** Gets the id of this AppProfile. */
@SuppressWarnings("WeakerAccess")
public String getId() {
 AppProfileName fullName =
   Verify.verifyNotNull(AppProfileName.parse(proto.getName()), "Name can never be null");
 //noinspection ConstantConditions
 return fullName.getAppProfile();
}

代码示例来源:origin: googleapis/google-cloud-java

/** Gets the id of the instance that owns this AppProfile. */
@SuppressWarnings("WeakerAccess")
public String getInstanceId() {
 AppProfileName fullName =
   Verify.verifyNotNull(AppProfileName.parse(proto.getName()), "Name can never be null");
 //noinspection ConstantConditions
 return fullName.getInstance();
}

代码示例来源:origin: googleapis/google-cloud-java

/** Gets the instance's id. */
@SuppressWarnings("WeakerAccess")
public String getId() {
 // Constructor ensures that name is not null
 InstanceName fullName =
   Verify.verifyNotNull(InstanceName.parse(proto.getName()), "Name can never be null");
 //noinspection ConstantConditions
 return fullName.getInstance();
}

代码示例来源:origin: googleapis/google-cloud-java

/** Gets the instance id. */
@SuppressWarnings("WeakerAccess")
public String getInstanceId() {
 // Constructor ensures that name is not null
 ClusterName fullName =
   Verify.verifyNotNull(ClusterName.parse(stateProto.getName()), "Name can never be null");
 //noinspection ConstantConditions
 return fullName.getInstance();
}

代码示例来源:origin: googleapis/google-cloud-java

/** Gets the cluster's id. */
@SuppressWarnings("WeakerAccess")
public String getId() {
 // Constructor ensures that name is not null
 ClusterName fullName =
   Verify.verifyNotNull(ClusterName.parse(stateProto.getName()), "Name can never be null");
 //noinspection ConstantConditions
 return fullName.getCluster();
}

代码示例来源:origin: googleapis/google-cloud-java

/** Get the zone where this cluster is located. */
@SuppressWarnings("WeakerAccess")
public String getZone() {
 LocationName location = Verify.verifyNotNull(LocationName.parse(stateProto.getLocation()));
 //noinspection ConstantConditions
 return location.getLocation();
}

代码示例来源:origin: google/truth

descriptionWasDerived = false;
} else {
 description = verifyNotNull(step.descriptionUpdate.apply(description));
 descriptionWasDerived = true;

代码示例来源:origin: google/error-prone

Verify.verifyNotNull(equals);
Verify.verifyNotNull(hashCode);

相关文章

微信公众号

最新文章

更多