Tabnine Logo
Optional.empty
Code IndexAdd Tabnine to your IDE (free)

How to use
empty
method
in
java.util.Optional

Best Java code snippets using java.util.Optional.empty (Showing top 20 results out of 38,961)

Refine searchRefine arrow

  • Optional.of
  • Optional.isPresent
  • Optional.get
  • List.size
  • Stream.collect
  • List.stream
  • Map.get
origin: prestodb/presto

public Optional<Scope> getOuterQueryParent()
{
  Scope scope = this;
  while (scope.parent.isPresent()) {
    if (scope.queryBoundary) {
      return scope.parent;
    }
    scope = scope.parent.get();
  }
  return Optional.empty();
}
origin: prestodb/presto

private static Optional<List<Symbol>> translateSymbols(Iterable<Symbol> partitioning, Function<Symbol, Optional<Symbol>> translator)
{
  ImmutableList.Builder<Symbol> newPartitioningColumns = ImmutableList.builder();
  for (Symbol partitioningColumn : partitioning) {
    Optional<Symbol> translated = translator.apply(partitioningColumn);
    if (!translated.isPresent()) {
      return Optional.empty();
    }
    newPartitioningColumns.add(translated.get());
  }
  return Optional.of(newPartitioningColumns.build());
}
origin: spring-projects/spring-framework

/**
 * Transform the given request into a request used for a nested route. For instance,
 * a path-based predicate can return a {@code ServerRequest} with a the path remaining
 * after a match.
 * <p>The default implementation returns an {@code Optional} wrapping the given path if
 * {@link #test(ServerRequest)} evaluates to {@code true}; or {@link Optional#empty()}
 * if it evaluates to {@code false}.
 * @param request the request to be nested
 * @return the nested request
 * @see RouterFunctions#nest(RequestPredicate, RouterFunction)
 */
default Optional<ServerRequest> nest(ServerRequest request) {
  return (test(request) ? Optional.of(request) : Optional.empty());
}
origin: SonarSource/sonarqube

private static Optional<String> getParameter(HttpServletRequest request, String parameterKey) {
 Optional<javax.servlet.http.Cookie> cookie = findCookie(AUTHENTICATION_COOKIE_NAME, request);
 if (!cookie.isPresent()) {
  return empty();
 }
 Map<String, String> parameters = fromJson(cookie.get().getValue());
 if (parameters.isEmpty()) {
  return empty();
 }
 return Optional.ofNullable(parameters.get(parameterKey));
}
origin: prestodb/presto

@Test
public void testCreateTableAsSelectDifferentCatalog()
    throws Exception
{
  handle.execute("CREATE TABLE \"my_test_table2\" (column1 BIGINT, column2 DOUBLE)");
  SqlParser parser = new SqlParser();
  Query query = new Query(CATALOG, SCHEMA, ImmutableList.of(), "CREATE TABLE public.my_test_table2 AS SELECT 1 column1, 2E0 column2", ImmutableList.of(), null, null, ImmutableMap.of());
  QueryRewriter rewriter = new QueryRewriter(parser, URL, QualifiedName.of("other_catalog", "other_schema", "tmp_"), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), 1, new Duration(10, SECONDS));
  Query rewrittenQuery = rewriter.shadowQuery(query);
  assertEquals(rewrittenQuery.getPreQueries().size(), 1);
  CreateTableAsSelect createTableAs = (CreateTableAsSelect) parser.createStatement(rewrittenQuery.getPreQueries().get(0));
  assertEquals(createTableAs.getName().getParts().size(), 3);
  assertEquals(createTableAs.getName().getPrefix().get(), QualifiedName.of("other_catalog", "other_schema"));
  assertTrue(createTableAs.getName().getSuffix().startsWith("tmp_"));
  assertFalse(createTableAs.getName().getSuffix().contains("my_test_table"));
}
origin: prestodb/presto

private static LdapObjectDefinition buildLdapGroupObject(String groupName, String userName, Optional<List<String>> childGroupNames)
{
  if (childGroupNames.isPresent()) {
    return buildLdapGroupObject(groupName, AMERICA_DISTINGUISHED_NAME, userName, ASIA_DISTINGUISHED_NAME, childGroupNames, Optional.of(AMERICA_DISTINGUISHED_NAME));
  }
  else {
    return buildLdapGroupObject(groupName, AMERICA_DISTINGUISHED_NAME, userName, ASIA_DISTINGUISHED_NAME,
        Optional.empty(), Optional.empty());
  }
}
origin: spring-projects/spring-framework

@Test
@SuppressWarnings("rawtypes")
public void resolveOptionalParamList() throws Exception {
  ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
  initializer.setConversionService(new DefaultConversionService());
  WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
  MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, List.class);
  Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
  assertEquals(Optional.empty(), result);
  request.addParameter("name", "123", "456");
  result = resolver.resolveArgument(param, null, webRequest, binderFactory);
  assertEquals(Optional.class, result.getClass());
  assertEquals(Arrays.asList("123", "456"), ((Optional) result).get());
}
origin: spring-projects/spring-framework

@Test
@SuppressWarnings("unchecked")
public void attributesAsOptionalEmpty() throws Exception {
  request.addParameter("name", "Patty");
  mavContainer.getModel().put("testBean1", Optional.empty());
  mavContainer.getModel().put("testBean2", Optional.empty());
  mavContainer.getModel().put("testBean3", Optional.empty());
  assertNull(processor.resolveArgument(
      testBeanModelAttr, mavContainer, webRequest, binderFactory));
  assertNull(processor.resolveArgument(
      testBeanWithoutStringConstructorModelAttr, mavContainer, webRequest, binderFactory));
  Optional<TestBean> testBean =(Optional<TestBean>) processor.resolveArgument(
      testBeanWithOptionalModelAttr, mavContainer, webRequest, binderFactory);
  assertFalse(testBean.isPresent());
}
origin: apache/incubator-dubbo

private static Optional<InetAddress> toValidAddress(InetAddress address) {
  if (address instanceof Inet6Address) {
    Inet6Address v6Address = (Inet6Address) address;
    if (isValidV6Address(v6Address)) {
      return Optional.ofNullable(normalizeV6Address(v6Address));
    }
  }
  if (isValidV4Address(address)) {
    return Optional.of(address);
  }
  return Optional.empty();
}
origin: neo4j/neo4j

@Test
void handlesDeprecationAndReplacement()
{
  ConfigValue value = new ConfigValue( "old_name", Optional.empty(), Optional.empty(), Optional.of( 1 ),
      "description", false, false, true, Optional.of( "new_name" ), false );
  assertEquals( Optional.of( 1 ), value.value() );
  assertEquals( "1", value.toString() );
  assertTrue( value.deprecated() );
  assertEquals( "new_name", value.replacement().get() );
  assertFalse( value.internal() );
  assertFalse( value.secret() );
}
origin: prestodb/presto

public Optional<WithQuery> getNamedQuery(String name)
{
  if (namedQueries.containsKey(name)) {
    return Optional.of(namedQueries.get(name));
  }
  if (parent.isPresent()) {
    return parent.get().getNamedQuery(name);
  }
  return Optional.empty();
}
origin: prestodb/presto

@Override
public void finishMemoryRevoke()
{
  checkState(finishMemoryRevoke.isPresent(), "Cannot finish unknown revoking");
  finishMemoryRevoke.get().run();
  finishMemoryRevoke = Optional.empty();
}
origin: iluwatar/java-design-patterns

/**
 * Can be used to collect objects from the Iterable. Is a terminating operation.
 * 
 * @return an option of the first object of the Iterable
 */
@Override
public final Optional<E> first() {
 Iterator<E> resultIterator = first(1).iterator();
 return resultIterator.hasNext() ? Optional.of(resultIterator.next()) : Optional.empty();
}
origin: prestodb/presto

private static LdapObjectDefinition buildLdapUserObject(String userName, Optional<List<String>> groupNames, String password)
{
  if (groupNames.isPresent()) {
    return buildLdapUserObject(userName, ASIA_DISTINGUISHED_NAME,
        groupNames, Optional.of(AMERICA_DISTINGUISHED_NAME), password);
  }
  else {
    return buildLdapUserObject(userName, ASIA_DISTINGUISHED_NAME,
        Optional.empty(), Optional.empty(), password);
  }
}
origin: prestodb/presto

  private Session getSession(String user)
  {
    return testSessionBuilder()
        .setCatalog(queryRunner.getDefaultSession().getCatalog().get())
        .setSchema(queryRunner.getDefaultSession().getSchema().get())
        .setIdentity(new Identity(user, Optional.empty())).build();
  }
}
origin: spring-projects/spring-framework

@Test
@SuppressWarnings("rawtypes")
public void missingOptionalParamValue() throws Exception {
  ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
  initializer.setConversionService(new DefaultConversionService());
  WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
  MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, Integer.class);
  Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
  assertEquals(Optional.empty(), result);
  result = resolver.resolveArgument(param, null, webRequest, binderFactory);
  assertEquals(Optional.class, result.getClass());
  assertFalse(((Optional) result).isPresent());
}
origin: apache/incubator-dubbo

private static Optional<InetAddress> toValidAddress(InetAddress address) {
  if (address instanceof Inet6Address) {
    Inet6Address v6Address = (Inet6Address) address;
    if (isValidV6Address(v6Address)) {
      return Optional.ofNullable(normalizeV6Address(v6Address));
    }
  }
  if (isValidV4Address(address)) {
    return Optional.of(address);
  }
  return Optional.empty();
}
origin: prestodb/presto

private Optional<Symbol> canonicalize(Optional<Symbol> symbol)
{
  if (symbol.isPresent()) {
    return Optional.of(canonicalize(symbol.get()));
  }
  return Optional.empty();
}
origin: prestodb/presto

public Optional<HashComputation> translate(Function<Symbol, Optional<Symbol>> translator)
{
  ImmutableList.Builder<Symbol> newSymbols = ImmutableList.builder();
  for (Symbol field : fields) {
    Optional<Symbol> newSymbol = translator.apply(field);
    if (!newSymbol.isPresent()) {
      return Optional.empty();
    }
    newSymbols.add(newSymbol.get());
  }
  return computeHash(newSymbols.build());
}
origin: iluwatar/java-design-patterns

/**
 * Can be used to collect objects from the Iterable. Is a terminating operation.
 * 
 * @return an option of the last object of the Iterable
 */
@Override
public final Optional<E> last() {
 List<E> list = last(1).asList();
 if (list.isEmpty()) {
  return Optional.empty();
 }
 return Optional.of(list.get(0));
}
java.utilOptionalempty

Popular methods of Optional

  • get
  • orElse
  • isPresent
  • ofNullable
  • of
  • map
  • ifPresent
  • orElseThrow
  • orElseGet
  • filter
  • flatMap
  • equals
  • flatMap,
  • equals,
  • hashCode,
  • toString,
  • isEmpty,
  • <init>,
  • ifPresentOrElse,
  • or,
  • stream

Popular in Java

  • Parsing JSON documents to java classes using gson
  • setScale (BigDecimal)
  • startActivity (Activity)
  • setRequestProperty (URLConnection)
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • JButton (javax.swing)
  • Join (org.hibernate.mapping)
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now