当前位置: 首页>>代码示例>>Java>>正文


Java Optional.fromNullable方法代码示例

本文整理汇总了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);
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:26,代码来源:StatisticRdbRepository.java

示例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;
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:24,代码来源:FlavorRuleToTestConverter.java

示例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));
    }
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:17,代码来源:PolicyExceptionMapper.java

示例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);
}
 
开发者ID:cbooy,项目名称:cakes,代码行数:14,代码来源:OptionalDemo.java

示例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());
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:16,代码来源:MaterializationTestStoragePlugin.java

示例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);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:9,代码来源:N4JSRuntimeCore.java

示例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());
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:12,代码来源:N4JSProject.java

示例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();
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:9,代码来源:RpcRoutingStrategy.java

示例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);
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:16,代码来源:InboundResponseFromIdpDtoBuilder.java

示例10: withInternationalPostCode

import com.google.common.base.Optional; //导入方法依赖的package包/类
public AddressBuilder withInternationalPostCode(final String internationalPostCode) {
    this.internationalPostCode = Optional.fromNullable(internationalPostCode);
    return this;
}
 
开发者ID:alphagov,项目名称:verify-matching-service-adapter,代码行数:5,代码来源:AddressBuilder.java

示例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);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:5,代码来源:ClusteredBy.java

示例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);
}
 
开发者ID:Lukaszpg,项目名称:jPUBG,代码行数:5,代码来源:MatchValidationService.java

示例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);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:7,代码来源:CurrentTime.java

示例14: withPrincipalIpAddressSeenByIdp

import com.google.common.base.Optional; //导入方法依赖的package包/类
public FraudFromIdpBuilder withPrincipalIpAddressSeenByIdp(String principalIpAddressAsSeenByIdp) {
    this.principalIpAddressAsSeenByIdp = Optional.fromNullable(principalIpAddressAsSeenByIdp);
    return this;
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:5,代码来源:FraudFromIdpBuilder.java

示例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());
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:54,代码来源:AbstractLeader.java


注:本文中的com.google.common.base.Optional.fromNullable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。