List of usage examples for java.util Optional orElse
public T orElse(T other)
From source file:net.sf.jabref.gui.desktop.JabRefDesktop.java
public static boolean openExternalFileUnknown(JabRefFrame frame, BibEntry entry, BibDatabaseContext databaseContext, String link, UnknownExternalFileType fileType) throws IOException { String cancelMessage = Localization.lang("Unable to open file."); String[] options = new String[] { Localization.lang("Define '%0'", fileType.getName()), Localization.lang("Change file type"), Localization.lang("Cancel") }; String defOption = options[0]; int answer = JOptionPane.showOptionDialog(frame, Localization.lang(//from w w w .ja v a 2 s .co m "This external link is of the type '%0', which is undefined. What do you want to do?", fileType.getName()), Localization.lang("Undefined file type"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, defOption); if (answer == JOptionPane.CANCEL_OPTION) { frame.output(cancelMessage); return false; } else if (answer == JOptionPane.YES_OPTION) { // User wants to define the new file type. Show the dialog: ExternalFileType newType = new ExternalFileType(fileType.getName(), "", "", "", "new", IconTheme.JabRefIcon.FILE.getSmallIcon()); ExternalFileTypeEntryEditor editor = new ExternalFileTypeEntryEditor(frame, newType); editor.setVisible(true); if (editor.okPressed()) { // Get the old list of types, add this one, and update the list in prefs: List<ExternalFileType> fileTypes = new ArrayList<>( ExternalFileTypes.getInstance().getExternalFileTypeSelection()); fileTypes.add(newType); Collections.sort(fileTypes); ExternalFileTypes.getInstance().setExternalFileTypes(fileTypes); // Finally, open the file: return openExternalFileAnyFormat(databaseContext, link, Optional.of(newType)); } else { // Canceled: frame.output(cancelMessage); return false; } } else { // User wants to change the type of this link. // First get a model of all file links for this entry: FileListTableModel tModel = new FileListTableModel(); Optional<String> oldValue = entry.getFieldOptional(FieldName.FILE); oldValue.ifPresent(tModel::setContent); FileListEntry flEntry = null; // Then find which one we are looking at: for (int i = 0; i < tModel.getRowCount(); i++) { FileListEntry iEntry = tModel.getEntry(i); if (iEntry.link.equals(link)) { flEntry = iEntry; break; } } if (flEntry == null) { // This shouldn't happen, so I'm not sure what to put in here: throw new RuntimeException("Could not find the file list entry " + link + " in " + entry); } FileListEntryEditor editor = new FileListEntryEditor(frame, flEntry, false, true, databaseContext); editor.setVisible(true, false); if (editor.okPressed()) { // Store the changes and add an undo edit: String newValue = tModel.getStringRepresentation(); UndoableFieldChange ce = new UndoableFieldChange(entry, FieldName.FILE, oldValue.orElse(null), newValue); entry.setField(FieldName.FILE, newValue); frame.getCurrentBasePanel().getUndoManager().addEdit(ce); frame.getCurrentBasePanel().markBaseChanged(); // Finally, open the link: return openExternalFileAnyFormat(databaseContext, flEntry.link, flEntry.type); } else { // Canceled: frame.output(cancelMessage); return false; } } }
From source file:net.wouterdanes.docker.maven.AbstractDockerMojo.java
protected void enqueueForPushingToRegistry(final String imageId, final Optional<String> nameAndTag, final String registry) throws MojoFailureException, MojoExecutionException { requireNonNull(nameAndTag.orElse(null), "When pushing to an explicit registry, name-and-tag must be set."); // build extended tag by prepending registry to name and tag String newNameAndTag = registry + "/" + nameAndTag.get(); // apply extended tag attachTag(imageId, newNameAndTag);/*from ww w . j av a 2s.c o m*/ // now enqueue for pushing enqueueForPushing(imageId, of(newNameAndTag)); }
From source file:net.wouterdanes.docker.maven.AbstractDockerMojo.java
protected void enqueueForPushing(final String imageId, final Optional<String> nameAndTag) { getLog().info(String.format("Enqueuing image '%s' to be pushed with tag '%s'..", imageId, nameAndTag.orElse("<none>"))); List<PushableImage> images = obtainListFromPluginContext(PUSHABLE_IMAGES_KEY); PushableImage newImage = new PushableImage(imageId, nameAndTag); if (!images.contains(newImage)) { images.add(newImage);/*from ww w. j a v a 2s .c o m*/ } }
From source file:org.obiba.mica.dataset.service.KeyStoreService.java
private String validateNameAndOrganizationInfo(String cn, String ou, String o) { Optional<String> hostname = Optional.empty(); if (Strings.isNullOrEmpty(cn) || Strings.isNullOrEmpty(o)) { try {/*w w w.java2 s. c o m*/ hostname = Optional.of(new URL(micaConfigService.getConfig().getPublicUrl()).getHost()); } catch (MalformedURLException e) { //ignore } } return String.format("CN=%s, OU=%s, O=%s", Strings.isNullOrEmpty(cn) ? hostname.orElse("") : cn, Strings.isNullOrEmpty(ou) ? "mica" : ou, ofNullable(o).orElse("")); }
From source file:org.trustedanalytics.servicebroker.yarn.config.ServiceInstanceBindingServiceConfig.java
private Map<String, Object> getCredentials() throws IOException { Optional<Map<String, String>> hadoopConf = HadoopConfigurationHelper .getHadoopConfFromJson(configuration.getYarnProvidedParams()); return ImmutableMap.of("kerberos", ImmutableMap.of("kerberos", ImmutableMap.of("kdc", configuration.getKerberosKdc(), "krealm", configuration.getKerberosRealm()), ConfigConstants.HADOOP_CONFIG_KEY_VALUE, ImmutableMap.copyOf(hadoopConf.orElse(Collections.emptyMap())))); }
From source file:org.jboss.tools.openshift.internal.core.preferences.OCBinaryVersionValidator.java
/** * Returns the version of the OC binary by running the version command. * //from w w w . ja v a 2 s . c o m * @param monitor the progress monitor * * @return the OSGi version of the binary */ public Version getVersion(IProgressMonitor monitor) { Optional<Version> version = Optional.empty(); if (path != null) { try { ProcessBuilder builder = new ProcessBuilder(path, "version"); Process process = builder.start(); version = parseVersion(process, monitor); } catch (IOException e) { OpenShiftCoreActivator.logError(e.getLocalizedMessage(), e); } } return version.orElse(Version.emptyVersion); }
From source file:com.idrene.emefana.repositories.RepositoriesTest.java
public void updateDescriptionsTest() { venuesDescr.stream().map(s -> s.split(":")).forEach(s -> { venuesDescrMap.put(s[0], s[1]);/*from w w w .j av a2s . com*/ }); List<Provider> prvs = providerRepository.findAll(); updateProvidersLambda(prvs, provider -> StringUtils.isEmpty(provider.getDescription()), provider -> { Optional<String> description = Optional.ofNullable(provider.getDescription()); provider.setDescription(description.orElse(venuesDescrMap.get(provider.getName()))); }); }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.security.KubernetesV2Credentials.java
public String lookupDefaultNamespace() { String namespace = defaultNamespace; try {//from ww w. ja va2 s. com Optional<String> serviceAccountNamespace = Files .lines(serviceAccountNamespacePath, StandardCharsets.UTF_8).findFirst(); namespace = serviceAccountNamespace.orElse(""); } catch (IOException e) { try { namespace = jobExecutor.defaultNamespace(this); } catch (KubectlException ke) { log.debug("Failure looking up desired namespace, defaulting to {}", defaultNamespace, ke); } } catch (Exception e) { log.debug("Error encountered looking up default namespace, defaulting to {}", defaultNamespace, e); } if (StringUtils.isEmpty(namespace)) { namespace = defaultNamespace; } return namespace; }
From source file:com.spotify.heroic.metric.astyanax.AstyanaxMetricModule.java
@JsonCreator public AstyanaxMetricModule(@JsonProperty("id") Optional<String> id, @JsonProperty("seeds") Optional<Set<String>> seeds, @JsonProperty("keyspace") Optional<String> keyspace, @JsonProperty("maxConnectionsPerHost") Optional<Integer> maxConnectionsPerHost, @JsonProperty("groups") Optional<Groups> groups, @JsonProperty("pools") Optional<ReadWriteThreadPools.Config> pools) { this.id = id; this.groups = groups.orElseGet(Groups::empty).or(DEFAULT_GROUP); this.keyspace = keyspace.orElse(DEFAULT_KEYSPACE); this.seeds = seeds.orElse(DEFAULT_SEEDS); this.maxConnectionsPerHost = maxConnectionsPerHost.orElse(DEFAULT_MAX_CONNECTIONS_PER_HOST); this.pools = pools.orElseGet(ReadWriteThreadPools.Config::buildDefault); }
From source file:org.cyberjos.jcconf2016.node.HazelcastHelper.java
/** * Registers the given node to the active node set. * * @param cloudNode the node to be registered * @throws NullPointerException if the given node is {@code null} *///from ww w . j av a2s . c o m public void registerNode(final CloudNode cloudNode) { Objects.requireNonNull(cloudNode, "The given cloud node must not be null."); final String nodeName = cloudNode.getName(); final NodeRecord record = new NodeRecord(nodeName, hazelcastHolder.getMemberId()); HazelcastHelper.getMap(ACTIVE_NODES).put(nodeName, record); HazelcastHelper.<CloudNodeMessage>getTopic(nodeName).addMessageListener(cloudNode); hazelcastHolder.getInstance().getCluster().addMembershipListener(cloudNode); logger.info("[{}] The given node registered: {}", nodeName, record); final Optional<NodeRecord> optional = this.getMasterNodeRecord(); logger.info("[{}] Found the master node: {}", nodeName, optional.orElse(null)); if (!optional.isPresent()) { this.setMaster(cloudNode); return; } logger.info("[{}] Found the master node: {}", nodeName, optional.get()); if (WORKING_MODE) { this.runConsumer(cloudNode); } }