本文整理汇总了Java中com.google.common.base.Optional.fromNullable方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.fromNullable方法的具体用法?Java Optional.fromNullable怎么用?Java Optional.fromNullable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.base.Optional
的用法示例。
在下文中一共展示了Optional.fromNullable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findLatestTaskResultStatistics
import com.google.common.base.Optional; //导入方法依赖的package包/类
/**
* 获取最近一条任务运行结果统计数据.
*
* @param statisticInterval 统计时间间隔
* @return 任务运行结果统计数据对象
*/
public Optional<TaskResultStatistics> findLatestTaskResultStatistics(final StatisticInterval statisticInterval) {
TaskResultStatistics result = null;
String sql = String.format("SELECT id, success_count, failed_count, statistics_time, creation_time FROM %s order by id DESC LIMIT 1",
TABLE_TASK_RESULT_STATISTICS + "_" + statisticInterval);
try (
Connection conn = dataSource.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(sql);
ResultSet resultSet = preparedStatement.executeQuery()
) {
while (resultSet.next()) {
result = new TaskResultStatistics(resultSet.getLong(1), resultSet.getInt(2), resultSet.getInt(3),
statisticInterval, new Date(resultSet.getTimestamp(4).getTime()), new Date(resultSet.getTimestamp(5).getTime()));
}
} catch (final SQLException ex) {
// TODO 记录失败直接输出日志,未来可考虑配置化
log.error("Fetch latest taskResultStatistics from DB error:", ex);
}
return Optional.fromNullable(result);
}
示例2: obtainExpectedResponse
import com.google.common.base.Optional; //导入方法依赖的package包/类
private TestSuiteResponse obtainExpectedResponse(IfExpression rule) {
TestSuiteResponse response = new TestSuiteResponse();
for (Expressions expressions : RulesUtils.getReturn(rule)) {
if (expressions instanceof Server) {
Optional<String> path = Optional.fromNullable(((Server) expressions).getPath());
if (path.or("").contains("/")) {
XreStackPath stackPath = new XreStackPath(path.get() + "/" + serviceName);
response.setFlavor(stackPath.getFlavor());
response.setXreStack(stackPath.getStackOnlyPath());
} else {
response.setFlavor(path.or(""));
}
response.setRule(rule.getId());
return response;
} else {
log.warn("Rule {} is skipped. ServerGroup is not supported", rule.getId());
}
}
return null;
}
示例3: getSessionId
import com.google.common.base.Optional; //导入方法依赖的package包/类
protected Optional<SessionId> getSessionId() {
// Are there any uris in Policy that contain the session id as a query string rather than as part of the path or is this just here coz it was copied from shared-rest ?
String parameter = httpServletRequest.getParameter(Urls.SharedUrls.SESSION_ID_PARAM);
if (Strings.isNullOrEmpty(parameter)) {
parameter = httpServletRequest.getParameter(Urls.SharedUrls.RELAY_STATE_PARAM);
}
if (Strings.isNullOrEmpty(parameter)) {
MultivaluedMap<String, String> pathParameters = uriInfo.getPathParameters();
parameter = pathParameters.getFirst(Urls.SharedUrls.SESSION_ID_PARAM);
}
if (Strings.isNullOrEmpty(parameter)) {
return Optional.absent();
} else {
return Optional.fromNullable(new SessionId(parameter));
}
}
示例4: testFromNullable
import com.google.common.base.Optional; //导入方法依赖的package包/类
/**
* 创建Optional: fromNullable(T)
*/
@Test
public void testFromNullable() {
String str = "";
Optional<String> op1 = Optional.fromNullable(str);
str = null;
// 此时即使str为null,也不会抛异常
Optional<String> op2 = Optional.fromNullable(str);
}
示例5: getView
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public ViewTable getView(final List<String> path, final SchemaConfig schemaConfig) {
if (path.size() != 2) {
logger.debug("path must consists of 2 segments [pluginName, layoutId]. got {}",
MoreObjects.toStringHelper(this).add("path", path));
return null;
}
final String layoutId = path.get(1);
final Optional<RelNode> layout = Optional.fromNullable(plans.getIfPresent(layoutId));
if (!layout.isPresent()) {
return null;
}
return new MaterializedTestViewTable(layout.get(), schemaConfig.getUserName(), schemaConfig.getViewExpansionContext());
}
示例6: findProject
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public Optional<? extends IN4JSProject> findProject(URI nestedLocation) {
if (nestedLocation == null) {
return Optional.absent();
}
IN4JSProject result = model.findProjectWith(nestedLocation);
return Optional.fromNullable(result);
}
示例7: getImplementationId
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public Optional<String> getImplementationId() {
if (!exists()) {
return Optional.absent();
}
final ProjectDescription pd = model.getProjectDescription(getLocation());
if (pd == null) {
return Optional.absent();
}
return Optional.fromNullable(pd.getImplementationId());
}
示例8: getRoutingContext
import com.google.common.base.Optional; //导入方法依赖的package包/类
public static Optional<QName> getRoutingContext(final DataSchemaNode schemaNode) {
for (UnknownSchemaNode extension : schemaNode.getUnknownSchemaNodes()) {
if (CONTEXT_REFERENCE.equals(extension.getNodeType())) {
return Optional.fromNullable(extension.getQName());
}
}
return Optional.absent();
}
示例9: buildDTO
import com.google.common.base.Optional; //导入方法依赖的package包/类
private static InboundResponseFromIdpDto buildDTO(IdpIdaStatus.Status status, String idpEntityId,
Optional<LevelOfAssurance> levelOfAssurance,
Optional<String> fraudText) {
return new InboundResponseFromIdpDto(
status,
Optional.fromNullable("message"),
idpEntityId,
Optional.fromNullable("authnStatement"),
Optional.of("encrypted-mds-assertion"),
Optional.fromNullable("pid"),
Optional.fromNullable("principalipseenbyidp"),
levelOfAssurance,
fraudText,
fraudText);
}
示例10: withInternationalPostCode
import com.google.common.base.Optional; //导入方法依赖的package包/类
public AddressBuilder withInternationalPostCode(final String internationalPostCode) {
this.internationalPostCode = Optional.fromNullable(internationalPostCode);
return this;
}
示例11: ClusteredBy
import com.google.common.base.Optional; //导入方法依赖的package包/类
public ClusteredBy(@Nullable Expression column, @Nullable Expression numberOfShards) {
this.column = Optional.fromNullable(column);
this.numberOfShards = Optional.fromNullable(numberOfShards);
}
示例12: validateSingleMatch
import com.google.common.base.Optional; //导入方法依赖的package包/类
public void validateSingleMatch(final Match match) {
Optional<Match> matchOptional = Optional.fromNullable(match);
Preconditions.checkState(matchOptional.isPresent(), Messages.CANNOT_GET_MATCH_FROM_SEASON_MATCH_IS_NULL);
}
示例13: CurrentTime
import com.google.common.base.Optional; //导入方法依赖的package包/类
public CurrentTime(Type type, @Nullable Integer precision)
{
checkNotNull(type, "type is null");
this.type = type;
this.precision = Optional.fromNullable(precision);
}
示例14: withPrincipalIpAddressSeenByIdp
import com.google.common.base.Optional; //导入方法依赖的package包/类
public FraudFromIdpBuilder withPrincipalIpAddressSeenByIdp(String principalIpAddressAsSeenByIdp) {
this.principalIpAddressAsSeenByIdp = Optional.fromNullable(principalIpAddressAsSeenByIdp);
return this;
}
示例15: sendSnapshotChunk
import com.google.common.base.Optional; //导入方法依赖的package包/类
/**
* Sends a snapshot chunk to a given follower
* InstallSnapshot should qualify as a heartbeat too.
*/
private void sendSnapshotChunk(final ActorSelection followerActor, final FollowerLogInformation followerLogInfo) {
if (snapshotHolder.isPresent()) {
LeaderInstallSnapshotState installSnapshotState = followerLogInfo.getInstallSnapshotState();
if (installSnapshotState == null) {
installSnapshotState = new LeaderInstallSnapshotState(context.getConfigParams().getSnapshotChunkSize(),
logName());
followerLogInfo.setLeaderInstallSnapshotState(installSnapshotState);
}
try {
// Ensure the snapshot bytes are set - this is a no-op.
installSnapshotState.setSnapshotBytes(snapshotHolder.get().getSnapshotBytes());
if (!installSnapshotState.canSendNextChunk()) {
return;
}
byte[] nextSnapshotChunk = installSnapshotState.getNextChunk();
log.debug("{}: next snapshot chunk size for follower {}: {}", logName(), followerLogInfo.getId(),
nextSnapshotChunk.length);
int nextChunkIndex = installSnapshotState.incrementChunkIndex();
Optional<ServerConfigurationPayload> serverConfig = Optional.absent();
if (installSnapshotState.isLastChunk(nextChunkIndex)) {
serverConfig = Optional.fromNullable(context.getPeerServerInfo(true));
}
followerActor.tell(
new InstallSnapshot(currentTerm(), context.getId(),
snapshotHolder.get().getLastIncludedIndex(),
snapshotHolder.get().getLastIncludedTerm(),
nextSnapshotChunk,
nextChunkIndex,
installSnapshotState.getTotalChunks(),
Optional.of(installSnapshotState.getLastChunkHashCode()),
serverConfig
).toSerializable(followerLogInfo.getRaftVersion()),
actor()
);
} catch (IOException e) {
throw new RuntimeException(e);
}
log.debug("{}: InstallSnapshot sent to follower {}, Chunk: {}/{}", logName(), followerActor.path(),
installSnapshotState.getChunkIndex(), installSnapshotState.getTotalChunks());
}
}