List of usage examples for java.util Optional isPresent
public boolean isPresent()
From source file:io.github.jeddict.jpa.spec.OrderBy.java
public static OrderBy load(MemberExplorer member) { Optional<AnnotationExplorer> orderByOpt = member.getAnnotation(javax.persistence.OrderBy.class); if (orderByOpt.isPresent()) { OrderBy orderBy = new OrderBy(); orderByOpt.get().getString("value") .ifPresent(value -> orderBy.getAttributes().addAll(OrderbyItem.process(value))); return orderBy; }// w w w.j av a 2s.c o m return null; }
From source file:net.fabricmc.installer.installer.LocalVersionInstaller.java
public static void install(File mcDir, IInstallerProgress progress) throws Exception { JFileChooser fc = new JFileChooser(); fc.setDialogTitle(Translator.getString("install.client.selectCustomJar")); fc.setFileFilter(new FileNameExtensionFilter("Jar Files", "jar")); if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File inputFile = fc.getSelectedFile(); JarFile jarFile = new JarFile(inputFile); Attributes attributes = jarFile.getManifest().getMainAttributes(); String mcVersion = attributes.getValue("MinecraftVersion"); Optional<String> stringOptional = ClientInstaller.isValidInstallLocation(mcDir, mcVersion); jarFile.close();/* w w w . j a v a2 s.com*/ if (stringOptional.isPresent()) { throw new Exception(stringOptional.get()); } ClientInstaller.install(mcDir, mcVersion, progress, inputFile); } else { throw new Exception("Failed to find jar"); } }
From source file:com.liferay.blade.cli.util.Prompter.java
public static boolean confirm(String question, InputStream in, PrintStream out, Optional<Boolean> defaultAnswer) { String questionWithPrompt = _buildQuestionWithPrompt(question, defaultAnswer); Optional<Boolean> answer = _getBooleanAnswer(questionWithPrompt, in, out, defaultAnswer); if (answer.isPresent()) { return answer.get(); } else {//from w ww. j a v a 2 s . c om throw new NoSuchElementException("Unable to acquire an answer"); } }
From source file:com.github.blindpirate.gogradle.crossplatform.Os.java
private static Os detectOs() { Optional<Map.Entry<Os, Boolean>> result = OS_DETECTION_MAP.entrySet().stream().filter(Map.Entry::getValue) .findFirst();//from ww w . j av a 2 s. c om if (result.isPresent()) { return result.get().getKey(); } throw new IllegalStateException("Unrecognized operation system:" + System.getProperty("os.name")); }
From source file:org.elasticsearch.plugin.readonlyrest.utils.containers.ESWithReadonlyRestContainer.java
public static ESWithReadonlyRestContainer create(String elasticsearchConfig, ESInitalizer initalizer) { File config = ContainerUtils.getResourceFile(elasticsearchConfig); Optional<File> pluginFileOpt = GradleProjectUtils.assemble(); if (!pluginFileOpt.isPresent()) { throw new ContainerCreationException("Plugin file assembly failed"); }/* w w w . jav a 2 s . com*/ File pluginFile = pluginFileOpt.get(); logger.info("Creating ES container ..."); String elasticsearchConfigName = "elasticsearch.yml"; ESWithReadonlyRestContainer container = new ESWithReadonlyRestContainer( new ImageFromDockerfile().withFileFromFile(pluginFile.getName(), pluginFile) .withFileFromFile(elasticsearchConfigName, config) .withDockerfileFromBuilder(builder -> builder .from("docker.elastic.co/elasticsearch/elasticsearch:" + properties.getProperty("esVersion")) .copy(pluginFile.getName(), "/tmp/") .copy(elasticsearchConfigName, "/usr/share/elasticsearch/config/") .run("yes | /usr/share/elasticsearch/bin/elasticsearch-plugin install " + "file:/tmp/" + pluginFile.getName()) .build())); return container.withExposedPorts(ES_PORT) .waitingFor(container.waitStrategy(initalizer).withStartupTimeout(CONTAINER_STARTUP_TIMEOUT)); }
From source file:com.ejisto.util.ContainerUtils.java
public static String extractAgentJar(String classPath) { String systemProperty = System.getProperty("ejisto.agent.jar.path"); if (StringUtils.isNotBlank(systemProperty)) { return systemProperty; }/*from ww w .j av a 2s . c om*/ final Optional<String> agentPath = Arrays.stream(classPath.split(Pattern.quote(File.pathSeparator))) .filter(e -> AGENT_JAR.matcher(e).matches()).findFirst(); if (agentPath.isPresent()) { return Paths.get(System.getProperty("user.dir"), agentPath.get()).toString(); } throw new IllegalStateException("unable to find agent jar"); }
From source file:de.mas.wiiu.jnus.utils.FSTUtils.java
public static Optional<FSTEntry> getEntryByFullPath(FSTEntry root, String filePath) { for (FSTEntry cur : root.getFileChildren()) { if (cur.getFullPath().equals(filePath)) { return Optional.of(cur); }//from w w w. ja v a 2s .c om } for (FSTEntry cur : root.getDirChildren()) { Optional<FSTEntry> res = getEntryByFullPath(cur, filePath); if (res.isPresent()) { return res; } } return Optional.empty(); }
From source file:com.liferay.blade.cli.util.Prompter.java
private static String _buildQuestionWithPrompt(String question, Optional<Boolean> defaultAnswer) { String yesDefault = "y"; String noDefault = "n"; if (defaultAnswer.isPresent()) { if (defaultAnswer.get()) { yesDefault = "Y"; } else {/*from w w w . j a v a 2 s. c om*/ noDefault = "N"; } } return question + " (" + yesDefault + "/" + noDefault + ")"; }
From source file:io.github.lxgaming.teleportbow.managers.CommandManager.java
public static boolean registerCommand(Class<? extends AbstractCommand> commandClass) { if (getCommandClasses().contains(commandClass)) { TeleportBow.getInstance().getLogger().warn("{} has already been registered", commandClass.getSimpleName()); return false; }// w w w .ja v a 2 s . c o m getCommandClasses().add(commandClass); Optional<AbstractCommand> command = Toolbox.newInstance(commandClass); if (!command.isPresent()) { TeleportBow.getInstance().getLogger().error("{} failed to initialize", commandClass.getSimpleName()); return false; } getCommands().add(command.get()); Sponge.getCommandManager().register(TeleportBow.getInstance().getPluginContainer(), command.get(), command.get().getAliases().toArray(new String[0])); TeleportBow.getInstance().getLogger().debug("{} registered", commandClass.getSimpleName()); return true; }
From source file:com.hortonworks.registries.storage.util.StorageUtils.java
public static void ensureUnique(Storable storable, Function<List<QueryParam>, Collection<? extends Storable>> listFn, List<QueryParam> queryParams) { Collection<? extends Storable> storables = listFn.apply(queryParams); Optional<Long> entities = storables.stream().map(Storable::getId).filter(x -> !x.equals(storable.getId())) .findAny();// w w w . ja va2 s. c o m if (entities.isPresent()) { throw new DuplicateEntityException("Entity with '" + queryParams + "' already exists"); } }