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

How to use
get
method
in
java.util.Optional

Best Java code snippets using java.util.Optional.get (Showing top 20 results out of 49,374)

Refine searchRefine arrow

  • Optional.isPresent
  • Optional.empty
  • Stream.filter
  • Optional.of
  • List.stream
  • Test.<init>
  • Stream.findFirst
origin: stackoverflow.com

 void foo(String a, Optional<Integer> bOpt) {
  Integer b = bOpt.isPresent() ? bOpt.get() : 0;
  //...
}

foo("a", Optional.of(2));
foo("a", Optional.<Integer>absent());
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: prestodb/presto

public long getTotalPartitionsCount(String keyspace, String table, Optional<Long> sessionSplitsPerNode)
{
  if (sessionSplitsPerNode.isPresent()) {
    return sessionSplitsPerNode.get();
  }
  else if (configSplitsPerNode.isPresent()) {
    return configSplitsPerNode.get();
  }
  List<SizeEstimate> estimates = session.getSizeEstimates(keyspace, table);
  return estimates.stream()
      .mapToLong(SizeEstimate::getPartitionsCount)
      .sum();
}
origin: spring-projects/spring-framework

@Test
public void getMediaType() {
  assertEquals(MediaType.APPLICATION_XML, MediaTypeFactory.getMediaType("file.xml").get());
  assertEquals(MediaType.parseMediaType("application/javascript"), MediaTypeFactory.getMediaType("file.js").get());
  assertEquals(MediaType.parseMediaType("text/css"), MediaTypeFactory.getMediaType("file.css").get());
  assertFalse(MediaTypeFactory.getMediaType("file.foobar").isPresent());
}
origin: spring-projects/spring-framework

@Test
@SuppressWarnings("unchecked")
public void createAttributeUriTemplateVarWithOptional() throws Exception {
  Map<String, String> uriTemplateVars = new HashMap<>();
  uriTemplateVars.put("testBean3", "Patty");
  request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
  // Type conversion from "Patty" to TestBean via TestBean(String) constructor
  Optional<TestBean> testBean = (Optional<TestBean>) processor.resolveArgument(
      testBeanWithOptionalModelAttr, mavContainer, webRequest, binderFactory);
  assertEquals("Patty", testBean.get().getName());
}
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: prestodb/presto

private static Optional<Domain> getDomain(OptionalInt timestampOrdinalPosition, TupleDomain<LocalFileColumnHandle> predicate)
{
  Optional<Map<LocalFileColumnHandle, Domain>> domains = predicate.getDomains();
  Domain domain = null;
  if (domains.isPresent() && timestampOrdinalPosition.isPresent()) {
    Map<LocalFileColumnHandle, Domain> domainMap = domains.get();
    Set<Domain> timestampDomain = domainMap.entrySet().stream()
        .filter(entry -> entry.getKey().getOrdinalPosition() == timestampOrdinalPosition.getAsInt())
        .map(Map.Entry::getValue)
        .collect(toSet());
    if (!timestampDomain.isEmpty()) {
      domain = Iterables.getOnlyElement(timestampDomain);
    }
  }
  return Optional.ofNullable(domain);
}
origin: spring-projects/spring-framework

@Test
public void resolveOptionalParamValue() {
  ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
  MethodParameter param = this.testMethod.arg(forClassWithGenerics(Optional.class, Integer.class));
  Object result = resolve(param, exchange);
  assertEquals(Optional.empty(), result);
  exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123"));
  result = resolve(param, exchange);
  assertEquals(Optional.class, result.getClass());
  Optional<?> value = (Optional<?>) result;
  assertTrue(value.isPresent());
  assertEquals(123, value.get());
}
origin: prestodb/presto

public List<SchemaTableName> listTables(Optional<String> schemaName)
{
  return tableDescriptions.getAllSchemaTableNames()
      .stream()
      .filter(schemaTableName -> !schemaName.isPresent() || schemaTableName.getSchemaName().equals(schemaName.get()))
      .collect(toImmutableList());
}
origin: apache/storm

private static int getMaxTaskId(Map<String, List<Integer>> componentToSortedTasks) {
  int maxTaskId = -1;
  for (List<Integer> integers : componentToSortedTasks.values()) {
    if (!integers.isEmpty()) {
      int tempMax = integers.stream().max(Integer::compareTo).get();
      if (tempMax > maxTaskId) {
        maxTaskId = tempMax;
      }
    }
  }
  return maxTaskId;
}
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

@JsonCreator
// Available for Jackson deserialization only!
public static <T> TupleDomain<T> fromColumnDomains(@JsonProperty("columnDomains") Optional<List<ColumnDomain<T>>> columnDomains)
{
  if (!columnDomains.isPresent()) {
    return none();
  }
  return withColumnDomains(columnDomains.get().stream()
      .collect(toMap(ColumnDomain::getColumn, ColumnDomain::getDomain)));
}
origin: spring-projects/spring-framework

@Test
public void testOptionalListMethodInjectionWithBeanAvailable() {
  bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalListMethodInjectionBean.class));
  bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
  OptionalListMethodInjectionBean bean = (OptionalListMethodInjectionBean) bf.getBean("annotatedBean");
  assertTrue(bean.getTestBean().isPresent());
  assertSame(bf.getBean("testBean"), bean.getTestBean().get().get(0));
}
origin: spring-projects/spring-framework

@Test
@SuppressWarnings("unchecked")
public void createAttributeRequestParameterWithOptional() throws Exception {
  request.addParameter("testBean3", "Patty");
  Optional<TestBean> testBean = (Optional<TestBean>) processor.resolveArgument(
      testBeanWithOptionalModelAttr, mavContainer, webRequest, binderFactory);
  assertEquals("Patty", testBean.get().getName());
}
origin: spring-projects/spring-framework

@Test
@SuppressWarnings("rawtypes")
public void resolveOptionalParamValue() 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);
  request.addParameter("name", "123");
  result = resolver.resolveArgument(param, null, webRequest, binderFactory);
  assertEquals(Optional.class, result.getClass());
  assertEquals(123, ((Optional) result).get());
}
origin: google/guava

/**
 * If a value is present in {@code optional}, returns a stream containing only that element,
 * otherwise returns an empty stream.
 *
 * <p><b>Java 9 users:</b> use {@code optional.stream()} instead.
 */
public static <T> Stream<T> stream(java.util.Optional<T> optional) {
 return optional.isPresent() ? Stream.of(optional.get()) : Stream.of();
}
origin: prestodb/presto

private Set<NullableValue> filterValues(Set<NullableValue> nullableValues, TpchColumn<?> column, Constraint<ColumnHandle> constraint)
{
  return nullableValues.stream()
      .filter(convertToPredicate(constraint.getSummary(), toColumnHandle(column)))
      .filter(value -> !constraint.predicate().isPresent() || constraint.predicate().get().test(ImmutableMap.of(toColumnHandle(column), value)))
      .collect(toSet());
}
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 boolean hasAllOutputs(TableScanNode node)
{
  if (!layout.getColumns().isPresent()) {
    return true;
  }
  Set<ColumnHandle> columns = ImmutableSet.copyOf(layout.getColumns().get());
  List<ColumnHandle> nodeColumnHandles = node.getOutputSymbols().stream()
      .map(node.getAssignments()::get)
      .collect(toImmutableList());
  return columns.containsAll(nodeColumnHandles);
}
origin: spring-projects/spring-framework

@Test
public void testOptionalListFieldInjectionWithBeanAvailable() {
  bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalListFieldInjectionBean.class));
  bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
  OptionalListFieldInjectionBean bean = (OptionalListFieldInjectionBean) bf.getBean("annotatedBean");
  assertTrue(bean.getTestBean().isPresent());
  assertSame(bf.getBean("testBean"), bean.getTestBean().get().get(0));
}
java.utilOptionalget

Javadoc

If a value is present in this Optional, returns the value, otherwise throws NoSuchElementException.

Popular methods of Optional

  • orElse
  • isPresent
  • ofNullable
  • empty
  • 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
  • getContentResolver (Context)
  • notifyDataSetChanged (ArrayAdapter)
  • scheduleAtFixedRate (Timer)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • Top plugins for WebStorm
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