List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:org.sonar.server.ws.WsUtils.java
public static <T> T checkFoundWithOptional(java.util.Optional<T> value, String message, Object... messageArguments) { if (!value.isPresent()) { throw new NotFoundException(format(message, messageArguments)); }//from ww w. j a v a 2 s . com return value.get(); }
From source file:io.mesosphere.mesos.util.ProtoUtils.java
@NotNull public static Optional<String> resourceValueRole(@NotNull final Optional<Resource> resource) { if (resource.isPresent()) { return Optional.of(resource.get().getRole()); } else {/*from w w w. j av a 2 s. c om*/ return Optional.absent(); } }
From source file:org.bin01.db.verifier.DbVerifier.java
public static <T> T loadConfig(Class<T> clazz, Optional<String> path) throws IOException { ImmutableMap.Builder<String, String> map = ImmutableMap.builder(); ConfigurationLoader loader = new ConfigurationLoader(); if (path.isPresent()) { map.putAll(loader.loadPropertiesFrom(path.get())); }//w w w . j a v a 2 s .c o m map.putAll(loader.getSystemProperties()); return new ConfigurationFactory(map.build()).build(clazz); }
From source file:org.locationtech.geogig.cli.app.Logging.java
static void tryConfigureLogging(Platform platform, @Nullable final String repoURI) { System.setProperty("hsqldb.reconfig_logging", "false"); // stop hsql from reseting logging // instantiate and call ResolveGeogigDir directly to avoid calling getGeogig() and hence get // some logging events before having configured logging Hints hints = new Hints(); try {/*from w w w . j a v a 2 s .c o m*/ if (repoURI != null) { URI uri = new URI(repoURI); hints.set(Hints.REPOSITORY_URL, uri); } } catch (URISyntaxException ignore) { // not our call to do anything with a wrong URI here } final Optional<URI> geogigDirUrl = new ResolveGeogigURI(platform, hints).call(); if (!geogigDirUrl.isPresent() || !"file".equalsIgnoreCase(geogigDirUrl.get().getScheme())) { // redirect java.util.logging to SLF4J anyways SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); return; } final File geogigDir = new File(geogigDirUrl.get()); if (repoURI == null && geogigDir.equals(geogigDirLoggingConfiguration)) { return; } if (!geogigDir.exists() || !geogigDir.isDirectory()) { return; } final URL loggingFile = getOrCreateLoggingConfigFile(geogigDir); if (loggingFile == null) { return; } try { LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); loggerContext.reset(); /* * Set the geogigdir variable for the config file can resolve the default location * ${geogigdir}/log/geogig.log */ loggerContext.putProperty("geogigdir", geogigDir.getAbsolutePath()); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(loggingFile); // redirect java.util.logging to SLF4J SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); geogigDirLoggingConfiguration = geogigDir; } catch (JoranException e) { LOGGER.error("Error configuring logging from file {}. '{}'", loggingFile, e.getMessage(), e); } }
From source file:extrabiomes.handlers.BiomeHandler.java
public static void enableBiomes() { final Set<WorldType> worldTypes = BiomeHelper.discoverWorldTypes(); for (final BiomeSettings setting : BiomeSettings.values()) { final Optional<? extends BiomeGenBase> biome = setting.getBiome(); if (!setting.isVanilla()) { if (setting.isEnabled() && biome.isPresent()) { BiomeHelper.enableBiome(worldTypes, biome.get()); } else { LogHelper.fine("Custom biome %s disabled.", setting.toString()); }/*from w ww . j av a2 s . c om*/ } else if (!setting.isEnabled()) { Extrabiomes.proxy.removeBiome(BiomeHelper.settingToBiomeGenBase(setting)); LogHelper.fine("Vanilla biome %s disabled.", biome.toString()); } if (setting.allowVillages() && biome.isPresent()) { BiomeManager.addVillageBiome(biome.get(), true); LogHelper.fine("Village spawning enabled for custom biome %s.", setting.toString()); } } }
From source file:gobblin.compliance.utils.DatasetUtils.java
public static String getProperty(HivePartitionDataset dataset, String property, long defaultValue) { Optional<String> propertyValueOptional = Optional.fromNullable(dataset.getParams().get(property)); if (!propertyValueOptional.isPresent()) { return Long.toString(defaultValue); }// w w w . j a v a 2 s.co m try { long propertyVal = Long.parseLong(propertyValueOptional.get()); if (propertyVal < 0) { return Long.toString(defaultValue); } else { return Long.toString(propertyVal); } } catch (NumberFormatException e) { return Long.toString(defaultValue); } }
From source file:ninja.utils.NinjaModeHelper.java
/** * returns NinjaMode.dev if no mode is set. Or the valid mode * set via a System Property called "ninja.mode". * //w w w .java 2 s.c o m * E.g. under mvn you can use mvn ... -Dninja.mode=prod or so. Valid values * for ninja.mode are "prod", "dev", "test". * * @return The valid mode set via a System Property called "ninja.mode" * or NinjaMode.dev if it is not set. */ public static NinjaMode determineModeFromSystemPropertiesOrProdIfNotSet() { Optional<NinjaMode> ninjaModeOptional = determineModeFromSystemProperties(); NinjaMode ninjaMode; if (!ninjaModeOptional.isPresent()) { ninjaMode = NinjaMode.prod; } else { ninjaMode = ninjaModeOptional.get(); } logger.info("Ninja is running in mode {}", ninjaMode.toString()); return ninjaMode; }
From source file:com.vmware.photon.controller.apife.utils.PaginationUtils.java
/** * Determine the page size to be used.//from ww w. j a va 2 s. c o m * * 1. If origPageSize is empty, then the one defined in paginationConfig is to be used. * 2. If origPageSize is larger than the maxPageSize defined in paginationConfig, throw exception. * * @param paginationConfig * @param origPageSize * @return */ public static Optional<Integer> determinePageSize(PaginationConfig paginationConfig, Optional<Integer> origPageSize) throws InvalidPageSizeException { if (!origPageSize.isPresent()) { return Optional.of(paginationConfig.getDefaultPageSize()); } else if (origPageSize.get() < 1 || origPageSize.get() > paginationConfig.getMaxPageSize()) { throw new InvalidPageSizeException(origPageSize.get(), 1, paginationConfig.getMaxPageSize()); } else { return origPageSize; } }
From source file:org.eclipse.buildship.ui.view.task.TaskNodeSelectionUtils.java
private static Optional<FixedRequestAttributes> getFixedRequestAttributes(ProjectNode projectNode) { Optional<IProject> workspaceProject = projectNode.getWorkspaceProject(); if (workspaceProject.isPresent() && GradleProjectNature.isPresentOn(workspaceProject.get())) { ProjectConfiguration projectConfiguration = CorePlugin.projectConfigurationManager() .readProjectConfiguration(workspaceProject.get()); return Optional .of(projectConfiguration.toRequestAttributes(ConversionStrategy.IGNORE_WORKSPACE_SETTINGS)); } else {/*from w w w. j a v a 2 s . com*/ return Optional.absent(); } }
From source file:org.geogit.rest.repository.GeogitResourceUtils.java
public static Optional<GeoGIT> getGeogit(Request request) { Optional<String> repositoryName = getRepositoryName(request); if (!repositoryName.isPresent()) { return Optional.absent(); }/* w ww. j a va 2 s. c o m*/ Optional<GeoGitDataStore> dataStore = findDataStore(request, repositoryName.get()); if (!dataStore.isPresent()) { return Optional.absent(); } return Optional.of(dataStore.get().getGeogit()); }