当前位置: 首页>>代码示例>>Java>>正文


Java Optional.ofNullable方法代码示例

本文整理汇总了Java中java.util.Optional.ofNullable方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.ofNullable方法的具体用法?Java Optional.ofNullable怎么用?Java Optional.ofNullable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Optional的用法示例。


在下文中一共展示了Optional.ofNullable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: listen

import java.util.Optional; //导入方法依赖的package包/类
@KafkaListener(topics = {"test-topic"})
public void listen(ConsumerRecord<?, ?> record) {
    logger.debug("listen1 ");
    Optional<?> kafkaMessage = Optional.ofNullable(record.value());
    if (kafkaMessage.isPresent()) {
        Object message = kafkaMessage.get();
        logger.debug("listen1 : {}", message);
    }
}
 
开发者ID:ctodb,项目名称:push,代码行数:10,代码来源:KafkaConsumer.java

示例2: get

import java.util.Optional; //导入方法依赖的package包/类
public Optional<User> get(final String userId)
{
    String url = remoteConfig.getDoubanUserGetUrl() + userId;
    ResponseEntity<User> response = restTemplate.getForEntity(url, User.class);
    if (response.getStatusCode().equals(HttpStatus.OK)) {
        return Optional.ofNullable(response.getBody());
    }
    return Optional.empty();
}
 
开发者ID:wenhao,项目名称:ci-hands-on,代码行数:10,代码来源:UserRemoteService.java

示例3: findIssuerById

import java.util.Optional; //导入方法依赖的package包/类
@Override
public Optional<IssuerEntity> findIssuerById(long id) {
    try {
        return Optional.ofNullable(issuerRepository.findOne(id));
    } catch (EmptyResultDataAccessException e) {
        return Optional.empty();
    }
}
 
开发者ID:amvnetworks,项目名称:amv-access-api-poc,代码行数:9,代码来源:IssuerServiceImpl.java

示例4: parseUserFromToken

import java.util.Optional; //导入方法依赖的package包/类
Optional<UserDetails> parseUserFromToken(String token) {
    String username = Jwts.parser()
            .setSigningKey(secret)
            .parseClaimsJws(token)
            .getBody()
            .getSubject();
    return Optional.ofNullable(userService.loadUserByUsername(username));
}
 
开发者ID:HoodyMac,项目名称:SA-starter-kit,代码行数:9,代码来源:TokenHandler.java

示例5: getHaving

import java.util.Optional; //导入方法依赖的package包/类
@Override
public Optional<Predicate> getHaving() {
	return Optional.ofNullable(having);
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jpa-querydsl,代码行数:5,代码来源:DefaultQueryDslAggregation.java

示例6: findConfiguration

import java.util.Optional; //导入方法依赖的package包/类
public Optional<Configuration> findConfiguration(String path) {
    return Optional.ofNullable(hazelcastRepository.find(path));
}
 
开发者ID:xm-online,项目名称:xm-ms-config,代码行数:4,代码来源:ConfigurationService.java

示例7: onTryPickupItem

import java.util.Optional; //导入方法依赖的package包/类
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onTryPickupItem(EntityItemPickupEvent event)
{
       if (!SettingsFlags.instance.enableCustomInventory)
       {
           return;
       }

	if (event.getItem() != null && !event.getItem().getItem().isEmpty() && !event.getItem().isDead && !event.getEntityPlayer().world.isRemote)
	{
		int i = PlayerInventoryHelper.findFirstAvailableSlotFor(event.getItem().getItem(), Optional.empty(), event.getEntityPlayer());
		if (i == -1)
		{
			event.setCanceled(true);
		}
		else
		{
			if (i < Short.MAX_VALUE)
			{
				event.getEntityPlayer().inventory.setInventorySlotContents(i, event.getItem().getItem().copy());
				net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerItemPickupEvent(event.getEntityPlayer(), event.getItem());
				event.getEntityPlayer().onItemPickup(event.getItem(), event.getItem().getItem().getCount());
				event.getEntityPlayer().addStat(StatList.getObjectsPickedUpStats(event.getItem().getItem().getItem()), event.getItem().getItem().getCount());
				event.getItem().setDead();
				event.setCanceled(true);
			}
			else
			{
				int slotID = i - Short.MAX_VALUE;
				ItemStack toIncrement = event.getEntityPlayer().inventory.getStackInSlot(slotID);
				Optional<Slot> s = Optional.ofNullable(event.getEntityPlayer().openContainer != null ? event.getEntityPlayer().openContainer.getSlot(slotID) : null);
				int max = Math.min(toIncrement.getMaxStackSize(), s.map(slot -> slot.getItemStackLimit(toIncrement)).orElseGet(() -> event.getEntityPlayer().inventory.getInventoryStackLimit()));
				int current = toIncrement.getCount();
				final int added = Math.min(event.getItem().getItem().getCount(), max - current);
				net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerItemPickupEvent(event.getEntityPlayer(), event.getItem());
				event.getEntityPlayer().addStat(StatList.getObjectsPickedUpStats(event.getItem().getItem().getItem()), added);
				event.getItem().getItem().shrink(added);
				toIncrement.grow(added);
				event.getEntityPlayer().world.playSound(null, event.getEntityPlayer().getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, (event.getEntityPlayer().world.rand.nextFloat() - event.getEntityPlayer().world.rand.nextFloat()) * 1.4F + 2.0F);
				if (toIncrement.isEmpty())
				{
					event.getItem().setDead();
				}
				
				event.setCanceled(true);
			}
		}
	}
}
 
开发者ID:V0idWa1k3r,项目名称:ExPetrum,代码行数:50,代码来源:ExPHandlerServer.java

示例8: getSequence

import java.util.Optional; //导入方法依赖的package包/类
@Override
public Optional<Integer> getSequence() {
	return Optional.ofNullable(sequence);
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:5,代码来源:DefaultBeanProperty.java

示例9: getFootprintRadius

import java.util.Optional; //导入方法依赖的package包/类
public Optional<Float> getFootprintRadius() {
    return Optional.ofNullable(footprintRadius);
}
 
开发者ID:ocraft,项目名称:ocraft-s2client,代码行数:4,代码来源:AbilityData.java

示例10: getAccuracy

import java.util.Optional; //导入方法依赖的package包/类
@Nonnull
@Override
public Optional<Integer> getAccuracy() {
    return Optional.ofNullable(accuracy);
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:6,代码来源:QueryImpl.java

示例11: getMandate

import java.util.Optional; //导入方法依赖的package包/类
public Optional<byte[]> getMandate() {
    return Optional.ofNullable(mandate);
}
 
开发者ID:TulevaEE,项目名称:onboarding-service,代码行数:4,代码来源:Mandate.java

示例12: put

import java.util.Optional; //导入方法依赖的package包/类
@Override
public <T> Optional<T> put(String resourceKey, T value) throws UnsupportedOperationException {
	return Optional.ofNullable(resources.put(resourceKey, value));
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:5,代码来源:TestContext.java

示例13: getCurrent

import java.util.Optional; //导入方法依赖的package包/类
/**
 * Get the current {@link ViewNavigator}, if available as {@link Context} resource or from current UI.
 * @return Current ViewNavigator, or an empty Optinal if not available
 */
static Optional<ViewNavigator> getCurrent() {
	return Optional.ofNullable(Context.get().resource(ViewNavigator.CONTEXT_KEY, ViewNavigator.class)
			.orElse(ViewNavigationUtils.getCurrentUIViewNavigator()));
}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:9,代码来源:ViewNavigator.java

示例14: search

import java.util.Optional; //导入方法依赖的package包/类
public Optional<Point> search(String query) {
	return Optional.ofNullable(geoDataCache.computeIfAbsent(query, key -> searchInt(query).orElse(null)));
}
 
开发者ID:xabgesagtx,项目名称:mensa-api,代码行数:4,代码来源:GeodataProvider.java

示例15: tryTribute

import java.util.Optional; //导入方法依赖的package包/类
protected Optional<Tribute> tryTribute(MatchPlayer player) {
    return Optional.ofNullable(tributes.get(player.getPlayerId()));
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:4,代码来源:FreeForAllMatchModule.java


注:本文中的java.util.Optional.ofNullable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。