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

How to use
ifPresentOrElse
method
in
java.util.Optional

Best Java code snippets using java.util.Optional.ifPresentOrElse (Showing top 2 results out of 315)

origin: torakiki/pdfsam

public void saveWorkspace() {
  RememberingLatestFileChooserWrapper fileChooser = FileChoosers.getFileChooser(FileType.JSON,
      DefaultI18nContext.getInstance().i18n("Select the workspace file to save"));
  latestWorkspace.ifPresentOrElse(f -> {
    fileChooser.setInitialDirectory(f.getParentFile());
    fileChooser.setInitialFileName(f.getName());
  }, () -> fileChooser.setInitialFileName("PDFsam_workspace.json"));
  File chosenFile = fileChooser.showDialog(OpenType.SAVE);
  if (chosenFile != null) {
    latestWorkspace = Optional.of(chosenFile);
    eventStudio().broadcast(new SaveWorkspaceEvent(chosenFile));
  }
}
origin: de.hilling.lang.annotations/processor

private void generateAttributeAndAccessor(String attribute) {
  final TypeName typeName = TypeName.get(classDescription.getMirrorWithDocumentation(attribute)
                              .getMirror());
  classBuilder.addField(FieldSpec.builder(typeName, attribute, Modifier.PRIVATE, Modifier.FINAL)
                  .build());
  constructorBuilder.addParameter(typeName, attribute)
           .addStatement("this.$1L = $1L", attribute);
  classDescription.getMirrorWithDocumentation(attribute)
          .getJavadoc()
          .filter(s -> !s.isEmpty())
          .ifPresentOrElse(s -> constructorBuilder.addJavadoc("@param $L $L\n", attribute, s),
              () -> constructorBuilder.addJavadoc(MISSING_DOC, attribute));
  classBuilder.addMethod(createAccessor(attribute, typeName));
}
java.utilOptionalifPresentOrElse

Popular methods of Optional

  • get
  • orElse
  • isPresent
  • ofNullable
  • empty
  • of
  • map
  • ifPresent
  • orElseThrow
  • orElseGet
  • filter
  • flatMap
  • filter,
  • flatMap,
  • equals,
  • hashCode,
  • toString,
  • isEmpty,
  • <init>,
  • 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
  • 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