當前位置: 首頁>>代碼示例>>Java>>正文


Java Optional.get方法代碼示例

本文整理匯總了Java中com.google.common.base.Optional.get方法的典型用法代碼示例。如果您正苦於以下問題:Java Optional.get方法的具體用法?Java Optional.get怎麽用?Java Optional.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.base.Optional的用法示例。


在下文中一共展示了Optional.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: apply

import com.google.common.base.Optional; //導入方法依賴的package包/類
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
{
    // TODO make more use of Optional
    if(!part.isPresent())
    {
        if(parent != null)
        {
            return parent.apply(part);
        }
        return Optional.absent();
    }
    if(!(part.get() instanceof NodeJoint))
    {
        return Optional.absent();
    }
    Node<?> node = ((NodeJoint)part.get()).getNode();
    TRSRTransformation nodeTransform;
    if(progress < 1e-5 || frame == nextFrame)
    {
        nodeTransform = getNodeMatrix(node, frame);
    }
    else if(progress > 1 - 1e-5)
    {
        nodeTransform = getNodeMatrix(node, nextFrame);
    }
    else
    {
        nodeTransform = getNodeMatrix(node, frame);
        nodeTransform = nodeTransform.slerp(getNodeMatrix(node, nextFrame), progress);
    }
    if(parent != null && node.getParent() == null)
    {
        return Optional.of(parent.apply(part).or(TRSRTransformation.identity()).compose(nodeTransform));
    }
    return Optional.of(nodeTransform);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:37,代碼來源:B3DLoader.java

示例2: create

import com.google.common.base.Optional; //導入方法依賴的package包/類
/**
 * Wraps the given parent scope to enable project imports (see {@link ProjectImportEnablingScope} for details).
 * <p>
 * To support tests that use multiple projects without properly setting up IN4JSCore, we simply return 'parent' in
 * such cases; however, project imports will not be available in such tests.
 *
 * @param importDecl
 *            if an import declaration is provided, imported error reporting will be activated (i.e. an
 *            {@link IEObjectDescriptionWithError} will be returned instead of <code>null</code> in case of
 *            unresolvable references).
 */
public static IScope create(IN4JSCore n4jsCore, Resource resource, Optional<ImportDeclaration> importDecl,
		IScope parent, IScope delegate) {
	if (n4jsCore == null || resource == null || importDecl == null || parent == null) {
		throw new IllegalArgumentException("none of the arguments may be null");
	}
	if (importDecl.isPresent() && importDecl.get().eResource() != resource) {
		throw new IllegalArgumentException("given import declaration must be contained in the given resource");
	}
	final Optional<? extends IN4JSProject> contextProject = n4jsCore.findProject(resource.getURI());
	if (!contextProject.isPresent()) {
		// we failed to obtain an IN4JSProject for the project containing 'importDecl'
		// -> it would be best to throw an exception in this case, but we have many tests that use multiple projects
		// without properly setting up the IN4JSCore; to not break those tests, we return 'parent' here
		return parent;
	}
	return new ProjectImportEnablingScope(n4jsCore, contextProject.get(), importDecl, parent, delegate);
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:29,代碼來源:ProjectImportEnablingScope.java

示例3: list

import com.google.common.base.Optional; //導入方法依賴的package包/類
private Map<?, ?> list(String stoken, Handler handler) throws BadResumptionTokenException, OAIInternalServerError
{
	Optional<ResumptionToken> maybeToken = resumptionTokens.get(stoken);
	if( !maybeToken.isPresent() )
	{
		throw new BadResumptionTokenException();
	}

	try
	{
		// Token is only valid for one use
		resumptionTokens.invalidate(stoken);

		ResumptionToken token = maybeToken.get();
		return list(token.request, token.format, token.start + MAX_RESULTS, handler);
	}
	catch( NoRecordsMatchException e )
	{
		LOGGER.error("No records match", e);
		throw new BadResumptionTokenException();
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:23,代碼來源:OAICatalog.java

示例4: onFactionLeave

import com.google.common.base.Optional; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onFactionLeave(PlayerLeaveFactionEvent event) {
    if (event.isForce() || event.isKick()) {
        return;
    }

    Faction faction = event.getFaction();
    if (faction instanceof PlayerFaction) {
        Optional<Player> optional = event.getPlayer();
        if (optional.isPresent()) {
            Player player = optional.get();
            if (plugin.getFactionManager().getFactionAt(player.getLocation()) == faction) {
                event.setCancelled(true);
                player.sendMessage(ChatColor.RED + "You may not leave a faction whilist in its territory!");
            }
        }
    }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:19,代碼來源:FactionListener.java

示例5: isEmpty

import com.google.common.base.Optional; //導入方法依賴的package包/類
/**
 * Returns whether the source has zero bytes. The default implementation returns true if
 * {@link #sizeIfKnown} returns zero, falling back to opening a stream and checking for EOF if the
 * size is not known.
 *
 * <p>Note that, in cases where {@code sizeIfKnown} returns zero, it is <i>possible</i> that bytes
 * are actually available for reading. (For example, some special files may return a size of 0
 * despite actually having content when read.) This means that a source may return {@code true}
 * from {@code isEmpty()} despite having readable content.
 *
 * @throws IOException if an I/O error occurs
 * @since 15.0
 */
public boolean isEmpty() throws IOException {
  Optional<Long> sizeIfKnown = sizeIfKnown();
  if (sizeIfKnown.isPresent() && sizeIfKnown.get() == 0L) {
    return true;
  }
  Closer closer = Closer.create();
  try {
    InputStream in = closer.register(openStream());
    return in.read() == -1;
  } catch (Throwable e) {
    throw closer.rethrow(e);
  } finally {
    closer.close();
  }
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:29,代碼來源:ByteSource.java

示例6: list

import com.google.common.base.Optional; //導入方法依賴的package包/類
private Map<?, ?> list(String stoken, Handler handler) throws BadResumptionTokenException, OAIInternalServerError
{
	Optional<ResumptionToken> maybeToken = resumptionTokens.get(stoken);
	if( !maybeToken.isPresent() )
	{
		throw new BadResumptionTokenException();
	}

	try
	{
		// Token is only valid for one use
		resumptionTokens.invalidate(stoken);

		ResumptionToken token = maybeToken.get();
		return list(token.request, token.format, token.start + MAX_RESULTS, handler);
	}
	catch( NoRecordsMatchException e )
	{
		LOGGER.error("No records match", e); //$NON-NLS-1$
		throw new BadResumptionTokenException();
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:23,代碼來源:OAICatalog.java

示例7: getJobConfiguration

import com.google.common.base.Optional; //導入方法依賴的package包/類
private CloudJobConfiguration getJobConfiguration(final TaskContext taskContext) throws LackConfigException {
    Optional<CloudJobConfiguration> jobConfigOptional = facadeService.load(taskContext.getMetaInfo().getJobName());
    if (!jobConfigOptional.isPresent()) {
        throw new LackConfigException("JOB", taskContext.getMetaInfo().getJobName());
    }
    return jobConfigOptional.get();
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:8,代碼來源:AppConstraintEvaluator.java

示例8: maybeAddComment

import com.google.common.base.Optional; //導入方法依賴的package包/類
private static String maybeAddComment(Optional<String> comment, boolean isJavadoc) {
    if (comment.isPresent()) {
        String input = comment.get();
        return StringUtil.writeComment(input, isJavadoc);
    } else {
        return "";
    }
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:9,代碼來源:GeneratedObjectBuilder.java

示例9: onPlayerLeftFaction

import com.google.common.base.Optional; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled=true, priority=EventPriority.MONITOR)
public void onPlayerLeftFaction(PlayerLeftFactionEvent event)
{
  Optional<Player> optional = event.getPlayer();
  if (optional.isPresent())
  {
    Player player = (Player)optional.get();
    Collection<Player> players = event.getFaction().getOnlinePlayers();
    getPlayerBoard(event.getUniqueID()).addUpdates(players);
    for (Player target : players) {
      getPlayerBoard(target.getUniqueId()).addUpdate(player);
    }
  }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:15,代碼來源:ScoreboardHandler.java

示例10: get

import com.google.common.base.Optional; //導入方法依賴的package包/類
@Override
public BeadledomClientBuilder get() {
  Optional<BeadledomClientConfiguration> beadledomClientConfigOpt = beadledomConfigProvider.get(
      clientBindingAnnotation);
  BeadledomClientBuilder clientBuilder =
      clientBuilderFactoryProvider.get(clientBindingAnnotation).create();
  clientBuilder.setCorrelationIdName(correlationIdHeader);
  if (beadledomClientConfigOpt.isPresent()) {
    // When there is custom client config
    BeadledomClientConfiguration config = beadledomClientConfigOpt.get();

    if (config.correlationIdName() != null) {
      clientBuilder.setCorrelationIdName(config.correlationIdName());
    }

    clientBuilder.setConnectionPoolSize(config.connectionPoolSize());
    clientBuilder.setMaxPooledPerRouteSize(config.maxPooledPerRouteSize());
    clientBuilder.setSocketTimeout(config.socketTimeoutMillis(), TimeUnit.SECONDS);
    clientBuilder.setConnectionTimeout(config.connectionTimeoutMillis(), TimeUnit.SECONDS);
    clientBuilder.setTtl(config.ttlMillis(), TimeUnit.SECONDS);

    if (config.sslContext() != null) {
      clientBuilder.sslContext(config.sslContext());
    }
    if (config.trustStore() != null) {
      clientBuilder.trustStore(config.trustStore());
    }
  }

  Injector tempInjector = getInjector();
  processInjector(tempInjector, clientBuilder);
  while (tempInjector.getParent() != null) {
    tempInjector = tempInjector.getParent();
    processInjector(tempInjector, clientBuilder);
  }
  return clientBuilder;
}
 
開發者ID:cerner,項目名稱:beadledom,代碼行數:38,代碼來源:BeadledomClientBuilderProvider.java

示例11: map

import com.google.common.base.Optional; //導入方法依賴的package包/類
protected <T> Optional<SimpleMdsValueDto<T>> map(Optional<SimpleMdsValue<T>> simpleMdsValueOptional) {
    if (!simpleMdsValueOptional.isPresent()) {
        return absent();
    }

    SimpleMdsValue<T> simpleMdsValue = simpleMdsValueOptional.get();
    return Optional.fromNullable(new SimpleMdsValueDto<>(simpleMdsValue.getValue(), simpleMdsValue.getFrom(), simpleMdsValue.getTo(), simpleMdsValue.isVerified()));
}
 
開發者ID:alphagov,項目名稱:verify-matching-service-adapter,代碼行數:9,代碼來源:MatchingDatasetToMatchingDatasetDtoMapper.java

示例12: addDevice

import com.google.common.base.Optional; //導入方法依賴的package包/類
public Response addDevice(DeviceDTO deviceDTO) {
    validate(deviceDTO);

    String deviceName = deviceDTO.getDeviceName();

    Optional<User> dbUser = userDAO.find(deviceDTO.getUserID());
    if (!dbUser.isPresent()) {
        throw new WebApplicationException(UserErrorMessage.DEVICE_ADD_FAIL_USER_NOT_FOUND, Response.Status.BAD_REQUEST);
    }

    Device device = deviceDAO.findByDeviceName(deviceName);
    if(device == null) {
        device = new Device(deviceName, deviceDTO.getPublicKey());
        deviceDAO.save(device);
    }

    List<Device> devicesForUser = deviceDAO.getDevicesForUser(deviceDTO.getUserID());
    if (devicesForUser == null || !devicesForUser.contains(device)) {
        //adding the device for the user
        User user = dbUser.get();
        user.addDevice(device);
        userDAO.save(user);
        LOG.info("New device added for user");
        return Response.status(Response.Status.CREATED).entity(device.getId()).build();
    }

    throw new WebApplicationException(UserErrorMessage.DEVICE_ADD_FAIL_DEVICE_EXISTS, Response.Status.BAD_REQUEST);
}
 
開發者ID:tosinoni,項目名稱:SECP,代碼行數:29,代碼來源:UserController.java

示例13: getJobEventBus

import com.google.common.base.Optional; //導入方法依賴的package包/類
private JobEventBus getJobEventBus() {
    Optional<JobEventRdbConfiguration> rdbConfig = env.getJobEventRdbConfiguration();
    if (rdbConfig.isPresent()) {
        return new JobEventBus(rdbConfig.get());
    }
    return new JobEventBus();
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:8,代碼來源:SchedulerService.java

示例14: findCorrectMaximizedPosition

import com.google.common.base.Optional; //導入方法依賴的package包/類
private Point<Integer> findCorrectMaximizedPosition(ContainerDimensions stickieDimensions, ContainerDimensions parentDimensions) {
    Point<Integer> newPosition;
    Optional<StickieSize> optionalStickieSize = maximizedStickieSizeStorage.getSizeOfMaximizedStickie(stickieProperties.getColorIndex());
    if (optionalStickieSize.isPresent()) {
        StickieSize maximizedStickieSize = optionalStickieSize.get();
        ContainerDimensions maximizedStickieDimensions = getMaximizedStickieDimensions(stickieDimensions, maximizedStickieSize);
        newPosition = positionFinder.refinePosition(stickieProperties.getPosition(), maximizedStickieDimensions, parentDimensions);
    } else {
        newPosition = positionFinder.refinePosition(stickieProperties.getPosition(), stickieDimensions, parentDimensions);
    }

    return newPosition;
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:14,代碼來源:StickieMinimizeMaximizeController.java

示例15: commitTransaction

import com.google.common.base.Optional; //導入方法依賴的package包/類
/**
 * Commit and notification send must be atomic.
 */
public synchronized CommitStatus commitTransaction(final ConfigRegistryClient configRegistryClient)
        throws ValidationException, ConflictingVersionException {
    if (!getTransaction().isPresent()) {
        // making empty commit without prior opened transaction, just return commit
        // status with empty lists
        LOG.debug("Making commit without open candidate transaction for session {}", sessionIdForReporting);
        return new CommitStatus(Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    }
    final Optional<ObjectName> maybeTaON = getTransaction();
    ObjectName taON = maybeTaON.get();
    try {
        CommitStatus status = configRegistryClient.commitConfig(taON);
        // clean up
        allOpenedTransactions.remove(candidateTx);
        candidateTx = null;
        return status;
    } catch (final ValidationException validationException) {
        // no clean up: user can reconfigure and recover this transaction
        LOG.warn("Transaction {} failed on {}", taON, validationException.toString());
        throw validationException;
    } catch (final ConflictingVersionException e) {
        LOG.debug("Exception while commit of {}, aborting transaction", taON, e);
        // clean up
        abortTransaction();
        throw e;
    }
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:31,代碼來源:TransactionProvider.java


注:本文中的com.google.common.base.Optional.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。