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

The following examples show how to use com.google.common.base.Optional#fromNullable() . 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
Source File: ParsedQueryUtil.java    From rya with 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 2
Source File: PostgreSQLViewNotificationParser.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * 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 File: CacheSearchServiceImpl.java    From elastic-rabbitmq with MIT License 6 votes vote down vote up
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 4
Source File: CompilationSupport.java    From bazel with 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 5
Source File: CreateTable.java    From Elasticsearch with 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 6
Source File: TerminalAddonRecipe.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@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 7
Source File: HivePartitionDataset.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
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 File: RestAssuredRequestMaker.java    From heat with 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 9
Source File: HandlerMethodResolverWrapper.java    From summerframework with Apache License 2.0 5 votes vote down vote up
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 10
Source File: PostgreSQLViewNotificationParserTest.java    From binnavi with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: MyriadConfiguration.java    From incubator-myriad with Apache License 2.0 4 votes vote down vote up
public Optional<MyriadContainerConfiguration> getContainerInfo() {
  return Optional.fromNullable(containerInfo);
}
 
Example 12
Source File: SchedulerState.java    From incubator-myriad with Apache License 2.0 4 votes vote down vote up
public synchronized Optional<Protos.FrameworkID> getFrameworkID() {
  return Optional.fromNullable(frameworkId);
}
 
Example 13
Source File: MesosNimbus.java    From storm with 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 14
Source File: SalesforceSource.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
SalesforceSource(LineageInfo lineageInfo) {
  this.lineageInfo = Optional.fromNullable(lineageInfo);
}
 
Example 15
Source File: WebRTCWrapper.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
Optional<VideoTrack> getRemoteVideoTrack() {
    return Optional.fromNullable(this.remoteVideoTrack);
}
 
Example 16
Source File: SettingsTmc.java    From tmc-intellij with MIT License 4 votes vote down vote up
@Override
public Optional<Organization> getOrganization() {
    logger.info("Getting organization <- {}", organization);
    return Optional.fromNullable(this.organization);
}
 
Example 17
Source File: ShardingConnection.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
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 18
Source File: ReIndexRequestBuilderImpl.java    From usergrid with Apache License 2.0 4 votes vote down vote up
/**
 * The cursor
 * @param cursor
 * @return
 */
@Override
public ReIndexRequestBuilder withCursor( final String cursor ) {
    this.cursor = Optional.fromNullable( cursor );
    return this;
}
 
Example 19
Source File: HttpClientConfiguratorLoader.java    From incubator-gobblin with Apache License 2.0 2 votes vote down vote up
/**
 * 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
Source File: HintManagerHolder.java    From sharding-jdbc-1.5.1 with Apache License 2.0 2 votes vote down vote up
/**
 * 获取分表分片键值.
 *
 * @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();
}