com.google.common.base.Optional#fromNullable ( )源码实例Demo

下面列出了com.google.common.base.Optional#fromNullable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: elastic-rabbitmq   文件: CacheSearchServiceImpl.java
private Optional<QueryResp> queryFromES(String body) {
    logger.info("Call ES to query");
    try {


        ESQueryResponse restResponse = esService.query("searchindex", "product", null, body);
        if (restResponse == null) {
            return Optional.absent();
        }

        logger.info("search result total count " + restResponse.getHit().getTotal());
        return Optional.fromNullable(new QueryResp(restResponse));
    } catch (RestClientException e) {
        logger.error("search is " + e);
    }
    return Optional.absent();
}
 
/**
 * Parser for a bn_module_views notification. The function uses the moduleViewNotificationPattern
 * to parse the incoming {@link PGNotification} into a {@link ViewNotificationContainer}.
 *
 * @param notification The {@link PGNotification} to parse.
 * @param provider The {@link SQLProvider} to access the database.
 *
 * @return A {@link ViewNotificationContainer} with the parsed information.
 */
private ViewNotificationContainer parseModuleViewNotification(
    final PGNotification notification, final SQLProvider provider) {

  final Matcher matcher = moduleViewNotificationPattern.matcher(notification.getParameter());
  if (!matcher.find()) {
    throw new IllegalStateException("IE02743: compiled pattern: "
        + moduleViewNotificationPattern.toString() + " did not match notification: "
        + notification.getParameter());
  }

  final Integer viewId = Integer.parseInt(matcher.group(3));
  final Optional<INaviView> view =
      Optional.fromNullable(ViewManager.get(provider).getView(viewId));
  final Optional<Integer> moduleId = Optional.fromNullable(Integer.parseInt(matcher.group(4)));
  final Optional<INaviModule> module = Optional.fromNullable(provider.findModule(moduleId.get()));
  final String databaseOperation = matcher.group(2);

  return new ViewNotificationContainer(viewId,
      view,
      moduleId,
      module,
      Optional.<INaviProject>absent(),
      databaseOperation);
}
 
源代码3 项目: rya   文件: ParsedQueryUtil.java
/**
 * Finds the first {@link Projection} node within a {@link ParsedQuery}.
 *
 * @param query - The query that will be searched. (not null)
 * @return The first projection encountered if the query has one; otherwise absent.
 */
public Optional<Projection> findProjection(final ParsedQuery query) {
    checkNotNull(query);

    // When a projection is encountered for the requested index, store it in atomic reference and quit searching.
    final AtomicReference<Projection> projectionRef = new AtomicReference<>();

    query.getTupleExpr().visit(new AbstractQueryModelVisitor<RuntimeException>() {
        @Override
        public void meet(Projection projection) {
            projectionRef.set(projection);
        }
    });

    return Optional.fromNullable( projectionRef.get() );
}
 
@Test(expected = IllegalArgumentException.class)
public void testModuleViewInform2() throws CouldntLoadDataException {
  final INaviModule module = new MockModule(provider);
  final ViewNotificationContainer container =
      new ViewNotificationContainer(view.getConfiguration().getId(),
          Optional.fromNullable(view),
          Optional.of(module.getConfiguration().getId()),
          Optional.of(module),
          Optional.<INaviProject>absent(),
          "DELETE");
  final PostgreSQLViewNotificationParser parser = new PostgreSQLViewNotificationParser();
  parser.inform(Lists.<ViewNotificationContainer>newArrayList(container), provider);
}
 
public static Optional<Class> useType(Class beanType) {
    if (Proxy.class.isAssignableFrom(beanType)) {
        return Optional.absent();
    }
    if (Class.class.getName().equals(beanType.getName())) {
        return Optional.absent();
    }
    return Optional.fromNullable(beanType);
}
 
源代码6 项目: heat   文件: RestAssuredRequestMaker.java
private String getRequestDetails(Method httpMethod, String url) {
    Optional<String> requestDetails = Optional.absent();
    try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        requestDetails = Optional.fromNullable(RequestPrinter.print((FilterableRequestSpecification) requestSpecification, httpMethod.name(), url, LogDetail.ALL,
                new PrintStream(os), true));
    } catch (IOException e) {
        logUtils.error("Unable to log 'Request Details', error occured during retrieving the information");
    }
    return requestDetails.or("");
}
 
源代码7 项目: incubator-gobblin   文件: HivePartitionDataset.java
public Optional<String> getFileFormat() {
  String serdeLib = this.hivePartition.getTPartition().getSd().getSerdeInfo().getSerializationLib();
  for (HiveSerDeWrapper.BuiltInHiveSerDe hiveSerDe : HiveSerDeWrapper.BuiltInHiveSerDe.values()) {
    if (hiveSerDe.toString().equalsIgnoreCase(serdeLib)) {
      return Optional.fromNullable(hiveSerDe.name());
    }
  }
  return Optional.<String>absent();
}
 
源代码8 项目: bazel   文件: CompilationSupport.java
private Optional<Artifact> getPchFile() {
  if (!usePch) {
    return Optional.absent();
  }
  Artifact pchHdr = null;
  if (ruleContext.attributes().has("pch", BuildType.LABEL)) {
    pchHdr = ruleContext.getPrerequisiteArtifact("pch", TransitionMode.TARGET);
  }
  return Optional.fromNullable(pchHdr);
}
 
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
	ItemStack targetStack = null;
	ItemStack glassesStack = null;

	for (ItemStack itemStack : InventoryUtils.asIterable(inv)) {
		if (itemStack != null) {
			if (itemStack.getItem() instanceof ItemGlasses) {
				if (glassesStack != null) return null;
				glassesStack = itemStack;
			} else if (isSuitableItem(itemStack)) {
				if (targetStack != null) return null;
				targetStack = itemStack;
			} else return null;
		}
	}

	if (glassesStack == null || targetStack == null) return null;

	final ItemGlasses glassesItem = (ItemGlasses)glassesStack.getItem();
	Optional<Long> guid = Optional.fromNullable(glassesItem.getTerminalGuid(glassesStack));

	final ItemStack result = targetStack.copy();
	NbtGuidProviders.setTerminalGuid(result, guid);

	return result;
}
 
源代码10 项目: Elasticsearch   文件: CreateTable.java
public CreateTable(Table name,
                   List<TableElement> tableElements,
                   @Nullable List<CrateTableOption> crateTableOptions,
                   @Nullable GenericProperties genericProperties,
                   boolean ifNotExists)
{
    this.name = name;
    this.tableElements = tableElements;
    this.ifNotExists = ifNotExists;
    this.crateTableOptions = crateTableOptions != null ? crateTableOptions : ImmutableList.<CrateTableOption>of();
    this.properties = Optional.fromNullable(genericProperties);
}
 
源代码11 项目: incubator-myriad   文件: SchedulerState.java
public synchronized Optional<Protos.FrameworkID> getFrameworkID() {
  return Optional.fromNullable(frameworkId);
}
 
源代码12 项目: usergrid   文件: ReIndexRequestBuilderImpl.java
/**
 * The cursor
 * @param cursor
 * @return
 */
@Override
public ReIndexRequestBuilder withCursor( final String cursor ) {
    this.cursor = Optional.fromNullable( cursor );
    return this;
}
 
源代码13 项目: tmc-intellij   文件: SettingsTmc.java
@Override
public Optional<Organization> getOrganization() {
    logger.info("Getting organization <- {}", organization);
    return Optional.fromNullable(this.organization);
}
 
源代码14 项目: storm   文件: MesosNimbus.java
private void createLocalServerPort() {
  Integer port = (Integer) mesosStormConf.get(CONF_MESOS_LOCAL_FILE_SERVER_PORT);
  LOG.debug("LocalFileServer configured to listen on port: {}", port);
  _localFileServerPort = Optional.fromNullable(port);
}
 
源代码15 项目: incubator-myriad   文件: MyriadConfiguration.java
public Optional<MyriadContainerConfiguration> getContainerInfo() {
  return Optional.fromNullable(containerInfo);
}
 
源代码16 项目: incubator-gobblin   文件: SalesforceSource.java
@VisibleForTesting
SalesforceSource(LineageInfo lineageInfo) {
  this.lineageInfo = Optional.fromNullable(lineageInfo);
}
 
源代码17 项目: Conversations   文件: WebRTCWrapper.java
Optional<VideoTrack> getRemoteVideoTrack() {
    return Optional.fromNullable(this.remoteVideoTrack);
}
 
源代码18 项目: sharding-jdbc-1.5.1   文件: ShardingConnection.java
private Optional<Connection> getCachedConnection(final String dataSourceName, final SQLType sqlType) {
    String key = connectionMap.containsKey(dataSourceName) ? dataSourceName : MasterSlaveDataSource.getDataSourceName(dataSourceName, sqlType);
    return Optional.fromNullable(connectionMap.get(key));
}
 
/**
 * Loads a HttpClientConfigurator using the value of the {@link #HTTP_CLIENT_CONFIGURATOR_TYPE_FULL_KEY}
 * property in the state.
 */
public HttpClientConfiguratorLoader(State state) {
  this(Optional.<String>fromNullable(state.getProp(HTTP_CLIENT_CONFIGURATOR_TYPE_FULL_KEY)));
}
 
源代码20 项目: sharding-jdbc-1.5.1   文件: HintManagerHolder.java
/**
 * 获取分表分片键值.
 *
 * @param shardingKey 分片键
 * @return 分表分片键值
 */
public static Optional<ShardingValue<?>> getTableShardingValue(final ShardingKey shardingKey) {
    return isUseShardingHint() ? Optional.<ShardingValue<?>>fromNullable(HINT_MANAGER_HOLDER.get().getTableShardingValue(shardingKey)) : Optional.<ShardingValue<?>>absent();
}