Java Code Examples for com.google.common.base.Optional#get()
The following examples show how to use
com.google.common.base.Optional#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrecomputedJoinUpdaterSupplier.java From rya with Apache License 2.0 | 6 votes |
@Override public PrecomputedJoinUpdater get() { // Ensure a configuration has been set. final Configuration config = configSupplier.get(); checkNotNull(config, "Can not build the PrecomputedJoinUpdater until the PrecomputedJoinIndexer has been configured."); final PrecomputedJoinIndexerConfig indexerConfig = new PrecomputedJoinIndexerConfig(config); // Ensure an updater type has been set. final Optional<PrecomputedJoinUpdaterType> updaterType = indexerConfig.getPcjUpdaterType(); checkArgument(updaterType.isPresent(), "The '" + PrecomputedJoinIndexerConfig.PCJ_UPDATER_TYPE + "' property must have one of the following values: " + PrecomputedJoinUpdaterType.values()); // Create and return the configured updater. switch(updaterType.get()) { case FLUO: return fluoSupplier.get(); default: throw new IllegalArgumentException("Unsupported PrecomputedJoinUpdaterType: " + updaterType.get()); } }
Example 2
Source File: PrecomputedJoinStorageSupplier.java From rya with Apache License 2.0 | 6 votes |
@Override public PrecomputedJoinStorage get() { // Ensure a configuration has been set. final Configuration config = configSupplier.get(); checkNotNull(config, "Could not build the PrecomputedJoinStorage until the PrecomputedJoinIndexer has been configured."); final PrecomputedJoinIndexerConfig indexerConfig = new PrecomputedJoinIndexerConfig(config); // Ensure the storage type has been set. final Optional<PrecomputedJoinStorageType> storageType = indexerConfig.getPcjStorageType(); checkArgument(storageType.isPresent(), "The '" + PrecomputedJoinIndexerConfig.PCJ_STORAGE_TYPE + "' property must have one of the following values: " + Arrays.toString(PrecomputedJoinStorageType.values())); // Create and return the configured storage. switch(storageType.get()) { case ACCUMULO: return accumuloSupplier.get(); default: throw new IllegalArgumentException("Unsupported PrecomputedJoinStorageType: " + storageType.get()); } }
Example 3
Source File: ValueAttribute.java From immutables with Apache License 2.0 | 6 votes |
private void initBuilderParamsIfApplicable() { if (!protoclass().environment().hasBuilderModule()) { return; } isBuilderParameter = FParameterMirror.isPresent(element); Optional<SwitchMirror> switcher = SwitchMirror.find(element); if (switcher.isPresent()) { if (isBuilderParameter) { report().annotationNamed(FParameterMirror.simpleName()) .error("@%s and @%s annotations cannot be used on a same factory parameter", FParameterMirror.simpleName(), SwitchMirror.simpleName()); isBuilderParameter = false; } if (!isEnumType()) { report().annotationNamed(SwitchMirror.simpleName()) .error("@%s annotation applicable only to enum parameters", SwitchMirror.simpleName()); } else { builderSwitcherModel = new SwitcherModel(switcher.get(), names, containedTypeElement); } } }
Example 4
Source File: HierarchicalAllocator.java From incubator-gobblin with Apache License 2.0 | 6 votes |
@Override public boolean hasNext() { while (this.currentIterator == null || !this.currentIterator.hasNext()) { if (this.currentIterator != null) { this.currentRequirement.add(this.currentIterator.totalResourcesUsed()); } if (this.resourcePool.exceedsSoftBound(this.currentRequirement, true)) { return false; } Optional<SingleTierIterator> tmp = this.singleTierIterator.nextTier(); if (!tmp.isPresent()) { return false; } this.singleTierIterator = tmp.get(); ResourcePool contractedPool = this.resourcePool.contractPool(this.currentRequirement); this.currentIterator = HierarchicalAllocator.this.underlying.allocateRequests(this.singleTierIterator, contractedPool); } return true; }
Example 5
Source File: InstallPrompt.java From rya with Apache License 2.0 | 6 votes |
@Override public InstallConfiguration promptInstallConfiguration(final String instanceName) throws IOException { final Optional<StorageType> storageType = sharedShellState.getShellState().getStorageType(); checkState(storageType.isPresent(), "The shell must be connected to a storage to use the install prompt."); switch(sharedShellState.getShellState().getStorageType().get()) { case ACCUMULO: return promptAccumuloConfig(instanceName); case MONGO: return promptMongoConfig(instanceName); default: throw new IllegalStateException("Unsupported storage type: " + storageType.get()); } }
Example 6
Source File: StreamManagerImpl.java From distributedlog with Apache License 2.0 | 5 votes |
private DynamicDistributedLogConfiguration getDynConf(String streamName) { Optional<DynamicDistributedLogConfiguration> dynDlConf = streamConfigProvider.getDynamicStreamConfig(streamName); if (dynDlConf.isPresent()) { return dynDlConf.get(); } else { return ConfUtils.getConstDynConf(dlConfig); } }
Example 7
Source File: TimeBasedWriterPartitioner.java From incubator-gobblin with Apache License 2.0 | 5 votes |
private static DatePartitionType getGranularity(State state, int numBranches, int branchId) { String propName = ForkOperatorUtils.getPropertyNameForBranch(WRITER_PARTITION_GRANULARITY, numBranches, branchId); String granularityValue = state.getProp(propName, DEFAULT_WRITER_PARTITION_GRANULARITY.toString()); Optional<DatePartitionType> granularity = Enums.getIfPresent(DatePartitionType.class, granularityValue.toUpperCase()); Preconditions.checkState(granularity.isPresent(), granularityValue + " is not a valid writer partition granularity"); return granularity.get(); }
Example 8
Source File: ApiParamReader.java From swagger-more with Apache License 2.0 | 5 votes |
private Optional<ApiParam> readApiParam(ParameterContext context) { Optional<ApiMethod> optional = context.getOperationContext().findAnnotation(ApiMethod.class); if (optional.isPresent()) { ApiMethod apiMethod = optional.get(); ResolvedMethodParameter parameter = context.resolvedMethodParameter(); if (parameter.getParameterIndex() > apiMethod.params().length - 1) { throw new SwaggerMoreException("The number of parameters in method " + context.getOperationContext().getName() + " does not match the number of @ApiParam."); } return Optional.of(apiMethod.params()[parameter.getParameterIndex()]); } return Optional.absent(); }
Example 9
Source File: PhoneOrFaxNumberRepository.java From estatio with Apache License 2.0 | 5 votes |
@Programmatic public PhoneOrFaxNumber findByPhoneOrFaxNumber( final CommunicationChannelOwner owner, final String phoneNumber) { final Optional<PhoneOrFaxNumber> phoneNumberIfFound = findByPhoneOrFaxNumber(owner, phoneNumber, CommunicationChannelType.PHONE_NUMBER); if(phoneNumberIfFound.isPresent()) { return phoneNumberIfFound.get(); } final Optional<PhoneOrFaxNumber> faxNumberIfFound = findByPhoneOrFaxNumber(owner, phoneNumber, CommunicationChannelType.FAX_NUMBER); return faxNumberIfFound.orNull(); }
Example 10
Source File: ValidateOptimisticAccountLock.java From sfs with Apache License 2.0 | 5 votes |
@Override public PersistentAccount call(Optional<PersistentAccount> subInput) { if (!subInput.isPresent()) { JsonObject jsonObject = new JsonObject() .put("message", format("Account was modified concurrently. Please retry the request.")); throw new HttpRequestValidationException(HTTP_CONFLICT, jsonObject); } return subInput.get(); }
Example 11
Source File: ZipCodesCsvParser.java From arcusplatform with Apache License 2.0 | 5 votes |
@Override protected void processLine(String[] nextLine, Map<String, PlaceLocation> result, int lineNumber) { String zipCode = trim(nextLine[0]); String latitude = trim(nextLine[1]); String longitude = trim(nextLine[2]); String primaryCity = trim(nextLine[3]); String state = trim(nextLine[4]); String county = trim(nextLine[5]); String timeZoneId = trim(nextLine[6]); if (result.containsKey(zipCode)) { throw new IllegalStateException( format("Duplicate zipcode in record {zipcode:[%s] latitude:[%s] longitude:[%s] tzid:[%s]} on line %d", zipCode, latitude, longitude, timeZoneId, lineNumber)); } if (isAnyEmpty(zipCode, latitude, longitude, timeZoneId)) { throw new IllegalStateException( format("Empty field(s) in record {zipcode:[%s] latitude:[%s] longitude:[%s] tzid:[%s]} on line %d", zipCode, latitude, longitude, timeZoneId, lineNumber)); } Optional<TimeZone> timeZone = TimeZones.getTimeZoneById(timeZoneId); if (!timeZone.isPresent()) { throw new IllegalStateException( format("Unknown tzid in record {zipcode:[%s] latitude:[%s] longitude:[%s] tzid:[%s]} on line %d", zipCode, latitude, longitude, timeZoneId, lineNumber)); } PlaceLocation placeLocation = new PlaceLocation(zipCode, GeoLocation.fromCoordinates(latitude, longitude), primaryCity, state, county, timeZone.get()); placeLocation.setGeoPrecision(Place.GEOPRECISION_ZIP5); result.put(zipCode, placeLocation); }
Example 12
Source File: SpongePlayer.java From PlotMe-Core with GNU General Public License v3.0 | 5 votes |
@Override public IItemStack getItemInHand() { Optional<ItemStack> itemInHand = player.getItemInHand(); if (itemInHand.isPresent()) { return new SpongeItemStack(itemInHand.get()); } else { return null; } }
Example 13
Source File: WeightedBoomerang.java From SPDS with Eclipse Public License 2.0 | 5 votes |
protected Optional<AllocVal> isAllocationNode(Statement s, Val fact) { Optional<Stmt> optUnit = s.getUnit(); if (optUnit.isPresent()) { Stmt stmt = optUnit.get(); return options.getAllocationVal(s.getMethod(), stmt, fact, icfg()); } return Optional.absent(); }
Example 14
Source File: HiveConfFactory.java From incubator-gobblin with Apache License 2.0 | 5 votes |
/** * * @param hcatURI User specified hcatURI. * @param broker A shared resource broker * @return a {@link HiveConf} with specified hcatURI if any. * @throws IOException */ public static <S extends ScopeType<S>> HiveConf get(Optional<String> hcatURI, SharedResourcesBroker<S> broker) throws IOException { try { SharedHiveConfKey confKey = hcatURI.isPresent() && StringUtils.isNotBlank(hcatURI.get()) ? new SharedHiveConfKey(hcatURI.get()) : SharedHiveConfKey.INSTANCE; return broker.getSharedResource(new HiveConfFactory<>(), confKey); } catch (NotConfiguredException nce) { throw new IOException(nce); } }
Example 15
Source File: LoadMaterializationHandler.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public List<SimpleCommandResult> toResult(String sql, SqlNode sqlNode) throws Exception { final SqlLoadMaterialization load = SqlNodeUtil.unwrap(sqlNode, SqlLoadMaterialization.class); if(!SystemUser.SYSTEM_USERNAME.equals(context.getQueryUserName())) { throw SqlExceptionHelper.parseError("$LOAD MATERIALIZATION not supported.", sql, load.getParserPosition()).build(logger); } final ReflectionService service = Preconditions.checkNotNull(context.getAccelerationManager().unwrap(ReflectionService.class), "Couldn't unwrap ReflectionService"); final List<String> components = normalizeComponents(load.getMaterializationPath()); if (components == null) { throw SqlExceptionHelper.parseError("Invalid materialization path.", sql, load.getParserPosition()).build(logger); } final ReflectionId reflectionId = new ReflectionId(components.get(0)); final Optional<ReflectionGoal> goalOptional = service.getGoal(reflectionId); if (!goalOptional.isPresent()) { throw SqlExceptionHelper.parseError("Unknown reflection id.", sql, load.getParserPosition()).build(logger); } final ReflectionGoal goal = goalOptional.get(); final MaterializationId materializationId = new MaterializationId(components.get(1)); final Optional<Materialization> materializationOpt = service.getMaterialization(materializationId); if (!materializationOpt.isPresent()) { throw SqlExceptionHelper.parseError("Unknown materialization id.", sql, load.getParserPosition()).build(logger); } final Materialization materialization = materializationOpt.get(); // if the user already made changes to the reflection goal, let's stop right here Preconditions.checkState(ReflectionGoalsStore.checkGoalVersion(goal, materialization.getReflectionGoalVersion()), "materialization no longer matches its goal"); refreshMetadata(goal, materialization); return Collections.singletonList(SimpleCommandResult.successful("Materialization metadata loaded.")); }
Example 16
Source File: ReferenceResolutionFinder.java From n4js with Eclipse Public License 1.0 | 5 votes |
private IEObjectDescription getCorrectCandidateViaScope(Optional<IScope> scopeForCollisionCheck) { try (Measurement m = contentAssistDataCollectors.dcDetectProposalConflicts().getMeasurement()) { if (scopeForCollisionCheck.isPresent()) { IScope scope = scopeForCollisionCheck.get(); IEObjectDescription candidateViaScope = getCandidateViaScope(scope); candidateViaScope = specialcaseNamespaceShadowsOwnElement(scope, candidateViaScope); return candidateViaScope; } return null; } }
Example 17
Source File: HivePurgerQueryTemplate.java From incubator-gobblin with Apache License 2.0 | 5 votes |
public static String getAddPartitionQuery(String tableName, String partitionSpec, Optional<String> fileFormat, Optional<String> location) { String query = "ALTER TABLE " + tableName + " ADD IF NOT EXISTS" + " PARTITION (" + partitionSpec + ")"; if (fileFormat.isPresent()) { query = query + " FILEFORMAT " + fileFormat.get(); } if (location.isPresent()) { query = query + " LOCATION " + PartitionUtils.getQuotedString(location.get()); } return query; }
Example 18
Source File: StarlarkRepositoryContext.java From bazel with Apache License 2.0 | 5 votes |
private Checksum calculateChecksum(Optional<Checksum> originalChecksum, Path path) throws IOException, InterruptedException { if (originalChecksum.isPresent()) { // The checksum is checked on download, so if we got here, the user provided checksum is good return originalChecksum.get(); } return Checksum.fromString(KeyType.SHA256, RepositoryCache.getChecksum(KeyType.SHA256, path)); }
Example 19
Source File: RepoRelativePath.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Creates the RepoRelativePath from a given resource. Returns null, if resource is not contained in a repository. * If a repository is found, the simple name of the origin is used. */ public static RepoRelativePath compute(FileURI uriOfResource, IN4JSCore n4jsCore) { Optional<? extends IN4JSProject> optProj = n4jsCore.findProject(uriOfResource.toURI()); if (!optProj.isPresent()) { return null; } IN4JSProject project = optProj.get(); Path pathOfResource = uriOfResource.toFileSystemPath(); Path pathOfProject = project.getLocation().toFileSystemPath(); String fileOfResourceInsideProject = pathOfProject.relativize(pathOfResource).toString(); // strip anchor part if present, i.e. path to type within the resource int anchorIndex = fileOfResourceInsideProject.indexOf("#"); if (anchorIndex >= 0) fileOfResourceInsideProject = fileOfResourceInsideProject.substring(0, anchorIndex); File absolutePathOfResource = pathOfProject.toAbsolutePath().resolve(fileOfResourceInsideProject).toFile(); if (!absolutePathOfResource.exists()) { return null; } // note: for retrieving the repo relative folder name, we must not rely on single path segments as they // may appear more than once. E.g. "n4js" maybe the folder of the oomph installation, the simple name of the // repository folder and a folder representing the package n4js. File repoFolder = getRepoFolder(absolutePathOfResource); // for resolving the repo relative path, // we only care about the repo folder name, since the folder may be named differently String pathOfProjectInRepo = getRepoPath(repoFolder, pathOfProject.getParent().toFile()); if (pathOfProjectInRepo == null) { return null; } String pathOfResourceInProject = '/' + fileOfResourceInsideProject; // ensure slashes if (File.separatorChar != '/') { pathOfResourceInProject = pathOfResourceInProject.replace(File.separatorChar, '/'); pathOfProjectInRepo = pathOfProjectInRepo.replace(File.separatorChar, '/'); } N4JSProjectName projName = project.getProjectName(); String repoName = getRepoName(repoFolder); return new RepoRelativePath(repoName, pathOfProjectInRepo, // repo relative projName, pathOfResourceInProject, // project relative -1); }
Example 20
Source File: BukkitPlugin.java From ServerListPlus with GNU General Public License v3.0 | 4 votes |
public CachedServerIcon getFavicon(FaviconSource source) { Optional<CachedServerIcon> result = faviconCache.getUnchecked(source); return result.isPresent() ? result.get() : null; }