Java Code Examples for com.google.common.base.Optional#fromNullable()

The following examples show how to use com.google.common.base.Optional#fromNullable() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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();
}
 
Example 2
/**
 * 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);
}
 
Example 3
Source Project: rya   File: ParsedQueryUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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() );
}
 
Example 4
@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);
}
 
Example 5
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);
}
 
Example 6
Source Project: heat   File: RestAssuredRequestMaker.java    License: Apache License 2.0 5 votes vote down vote up
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("");
}
 
Example 7
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();
}
 
Example 8
Source Project: bazel   File: CompilationSupport.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
@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;
}
 
Example 10
Source Project: Elasticsearch   File: CreateTable.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 11
Source Project: incubator-myriad   File: SchedulerState.java    License: Apache License 2.0 4 votes vote down vote up
public synchronized Optional<Protos.FrameworkID> getFrameworkID() {
  return Optional.fromNullable(frameworkId);
}
 
Example 12
/**
 * The cursor
 * @param cursor
 * @return
 */
@Override
public ReIndexRequestBuilder withCursor( final String cursor ) {
    this.cursor = Optional.fromNullable( cursor );
    return this;
}
 
Example 13
Source Project: tmc-intellij   File: SettingsTmc.java    License: MIT License 4 votes vote down vote up
@Override
public Optional<Organization> getOrganization() {
    logger.info("Getting organization <- {}", organization);
    return Optional.fromNullable(this.organization);
}
 
Example 14
Source Project: storm   File: MesosNimbus.java    License: Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 15
public Optional<MyriadContainerConfiguration> getContainerInfo() {
  return Optional.fromNullable(containerInfo);
}
 
Example 16
@VisibleForTesting
SalesforceSource(LineageInfo lineageInfo) {
  this.lineageInfo = Optional.fromNullable(lineageInfo);
}
 
Example 17
Optional<VideoTrack> getRemoteVideoTrack() {
    return Optional.fromNullable(this.remoteVideoTrack);
}
 
Example 18
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));
}
 
Example 19
/**
 * 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)));
}
 
Example 20
/**
 * 获取分表分片键值.
 *
 * @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();
}