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


Java OptionalInt.isPresent方法代碼示例

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


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

示例1: execute

import java.util.OptionalInt; //導入方法依賴的package包/類
@Override
protected void execute(HVSession session, CommandArgSet args) throws CommandException {
    EnumFacing facing;
    if (args.hasValue(DIRECTION)) {
        facing = args.value(DIRECTION);
    } else if (session.owner.getCommandSenderEntity() != null) {
        Entity e = session.owner.getCommandSenderEntity();
        facing = VecBridge.facingFromLook(e);
    } else {
        throw new CommandException("A direction must be provided, since the command was not excuted by an entity.");
    }
    OptionalInt amt = args.value(AMOUNT);
    if (amt.isPresent()) {
        session.performFullRegionCommand(sel -> sel.expandRegion(facing, amt.getAsInt()));
    } else {
        session.performFullRegionCommand(RegionSelector::expandRegionVertically);
    }
}
 
開發者ID:kenzierocks,項目名稱:HardVox,代碼行數:19,代碼來源:ExpandCommand.java

示例2: messageReceived

import java.util.OptionalInt; //導入方法依賴的package包/類
private void messageReceived(ChannelHandlerContext context, ByteBuf response)
{
    try {
        OptionalInt sequenceId = messageEncoding.extractResponseSequenceId(response);
        if (!sequenceId.isPresent()) {
            throw new TTransportException("Could not find sequenceId in Thrift message");
        }

        RequestHandler requestHandler = pendingRequests.remove(sequenceId.getAsInt());
        if (requestHandler == null) {
            throw new TTransportException("Unknown sequence id in response: " + sequenceId.getAsInt());
        }

        requestHandler.onResponseReceived(response);
    }
    catch (Throwable t) {
        onError(context, t);
    }
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:20,代碼來源:ThriftClientHandler.java

示例3: findAffinityArg

import java.util.OptionalInt; //導入方法依賴的package包/類
private static OptionalInt findAffinityArg(Method meth) {
    OptionalInt affinityArg = OptionalInt.empty();

    if (meth.getParameterCount() > 0) {
        for (int i = 0; i < meth.getParameterCount() && !affinityArg.isPresent(); i++) {
            Annotation[] annotations = meth.getParameterAnnotations()[i];

            for (int j = 0; j < annotations.length; j++) {
                if (RpcAffinityKey.class.isAssignableFrom(annotations[j].annotationType())) {
                    affinityArg = OptionalInt.of(i);

                    break;
                }
            }
        }
    }

    return affinityArg;
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:20,代碼來源:RpcMethodInfo.java

示例4: getWinners

import java.util.OptionalInt; //導入方法依賴的package包/類
public List<CeremonyOfChaosMember> getWinners()
{
	final List<CeremonyOfChaosMember> winners = new ArrayList<>();
	//@formatter:off
	final OptionalInt winnerLifeTime = getMembers().values().stream()
		.mapToInt(CeremonyOfChaosMember::getLifeTime)
		.max();
	
	if(winnerLifeTime.isPresent())
	{
		getMembers().values().stream()
			.sorted(Comparator.comparingLong(CeremonyOfChaosMember::getLifeTime)
				.reversed()
				.thenComparingInt(CeremonyOfChaosMember::getScore)
				.reversed())
			.filter(member -> member.getLifeTime() == winnerLifeTime.getAsInt())
			.collect(Collectors.toCollection(() -> winners));
	}
	
	//@formatter:on
	return winners;
}
 
開發者ID:rubenswagner,項目名稱:L2J-Global,代碼行數:23,代碼來源:CeremonyOfChaosEvent.java

示例5: execute

import java.util.OptionalInt; //導入方法依賴的package包/類
@Override
protected void execute() {
    IntentExtensionService service = get(IntentExtensionService.class);
    OptionalInt length = service.getCompilers().keySet().stream()
            .mapToInt(s -> s.getName().length())
            .max();
    if (length.isPresent()) {
        service.getCompilers().entrySet().forEach(e -> {
            print("%-" + length.getAsInt() + "s\t%s",
                  e.getKey().getName(),
                  e.getValue().getClass().getName());
        });
    } else {
        print("There are no compilers registered.");
    }

}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:18,代碼來源:IntentListCompilers.java

示例6: StreamingMkvReader

import java.util.OptionalInt; //導入方法依賴的package包/類
StreamingMkvReader(boolean requirePath,
        Collection<EBMLTypeInfo> typeInfosToRead,
        ParserByteSource byteSource,
        OptionalInt maxContentBytesAtOnce) {
    this.requirePath = requirePath;
    typeInfosToRead.stream().forEach(t -> Validate.isTrue(t.getType() != EBMLTypeInfo.TYPE.MASTER));
    this.typeInfosToRead = new HashSet(typeInfosToRead);

    this.byteSource = byteSource;
    this.mkvStreamReaderCallback = new MkvStreamReaderCallback(this.requirePath, elementFilter());
    this.previousDataElement = Optional.empty();
    MkvTypeInfoProvider typeInfoProvider = new MkvTypeInfoProvider();
    try {
        typeInfoProvider.load();
    } catch (IllegalAccessException e) {
        //TODO: fix this
        throw new RuntimeException("Could not load mkv info", e);
    }
    if (maxContentBytesAtOnce.isPresent()) {
        this.parser = new EBMLParser(typeInfoProvider, mkvStreamReaderCallback, maxContentBytesAtOnce.getAsInt());
    } else {
        this.parser = new EBMLParser(typeInfoProvider, mkvStreamReaderCallback);
    }
}
 
開發者ID:aws,項目名稱:amazon-kinesis-video-streams-parser-library,代碼行數:25,代碼來源:StreamingMkvReader.java

示例7: initFrom

import java.util.OptionalInt; //導入方法依賴的package包/類
@Encoding.Of
static int initFrom(OptionalInt optional) {
  if (optional.isPresent()) {
    return safeValue(optional.getAsInt());
  }
  return SENTINEL_VALUE;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:OptionalIntWithSentinel.java

示例8: setFrom

import java.util.OptionalInt; //導入方法依賴的package包/類
@Encoding.Init
@Encoding.Copy
void setFrom(OptionalInt optional) {
  if (optional.isPresent()) {
    setFromInt(optional.getAsInt());
  } else {
    value = SENTINEL_VALUE;
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:OptionalIntWithSentinel.java

示例9: run

import java.util.OptionalInt; //導入方法依賴的package包/類
@Override
public void run(L2GameClient client)
{
	final L2PcInstance activeChar = client.getActiveChar();
	if ((activeChar == null) || (activeChar.getClan() == null))
	{
		return;
	}
	
	final OptionalInt clanId = ClanEntryManager.getInstance().getClanIdForPlayerApplication(activeChar.getObjectId());
	if (clanId.isPresent())
	{
		activeChar.sendPacket(new ExPledgeWaitingListApplied(clanId.getAsInt(), activeChar.getObjectId()));
	}
}
 
開發者ID:rubenswagner,項目名稱:L2J-Global,代碼行數:16,代碼來源:RequestPledgeWaitingApplied.java

示例10: checkMessageSize

import java.util.OptionalInt; //導入方法依賴的package包/類
private void checkMessageSize(OptionalInt size) {
  if (!ehloResponse.getMaxMessageSize().isPresent() || !size.isPresent()) {
    return;
  }

  long maximumSize = ehloResponse.getMaxMessageSize().get();
  if (maximumSize < size.getAsInt()) {
    throw new MessageTooLargeException(config.getConnectionId(), maximumSize);
  }
}
 
開發者ID:HubSpot,項目名稱:NioSmtpClient,代碼行數:11,代碼來源:SmtpSession.java

示例11: parse

import java.util.OptionalInt; //導入方法依賴的package包/類
static Optional<Result> parse(final String line) {
	final String[] parts = line.split(quote("|"));

	if (parts.length == 6) {
		final String name = parts[0].trim();
		final OptionalInt ntup = toOptionalInt(parts[1].trim());
		final OptionalInt tsamples = toOptionalInt(parts[2].trim());
		final OptionalInt psamples = toOptionalInt(parts[3].trim());
		final OptionalDouble pvalue = toOptionalDouble(parts[4].trim());
		final Optional<Assessment> assessment = Assessment.of(parts[5].trim());

		if (ntup.isPresent() &&
			tsamples.isPresent() &&
			psamples.isPresent() &&
			pvalue.isPresent() &&
			assessment.isPresent())
		{
			return Optional.of(new Result(
				name,
				ntup.getAsInt(),
				tsamples.getAsInt(),
				psamples.getAsInt(),
				pvalue.getAsDouble(),
				assessment.get()
			));
		}
	}

	return Optional.empty();
}
 
開發者ID:jenetics,項目名稱:prngine,代碼行數:31,代碼來源:DieHarder.java

示例12: mention

import java.util.OptionalInt; //導入方法依賴的package包/類
@Override
public String mention(boolean includeArticle, boolean plural, OptionalInt amount) {
	return (amount.isPresent() ? amount.orElse(0) : includeArticle ? "a " : "") + "stack" + (plural || (amount.orElse(1) != 1) ? "s" : "") + " of " + item.mention(this, false, amount.orElse(1) != 1, OptionalInt.of(this.amount));
}
 
開發者ID:Mantaro,項目名稱:MantaroRPG,代碼行數:5,代碼來源:ItemStack.java

示例13: findSplitArg

import java.util.OptionalInt; //導入方法依賴的package包/類
private static OptionalInt findSplitArg(Method meth) {
    OptionalInt splitIdx = OptionalInt.empty();

    Annotation[][] parameters = meth.getParameterAnnotations();

    for (int i = 0; i < parameters.length; i++) {
        Annotation[] annotations = parameters[i];

        for (int j = 0; j < annotations.length; j++) {
            if (annotations[j].annotationType().equals(RpcSplit.class)) {
                if (splitIdx.isPresent()) {
                    throw new IllegalArgumentException("Only one argument can be annotated with @" + RpcSplit.class.getSimpleName()
                        + " [method=" + meth + ']');
                }

                splitIdx = OptionalInt.of(i);
            }
        }
    }

    if (splitIdx.isPresent()) {
        Class<?> splitType = meth.getParameterTypes()[splitIdx.getAsInt()];

        // Verify parameter type.
        if (!Collection.class.equals(splitType)
            && !Set.class.equals(splitType)
            && !List.class.equals(splitType)
            && !Map.class.equals(splitType)) {
            // Allowed types info for the error message.
            String col = Collection.class.getSimpleName();
            String lst = List.class.getSimpleName();
            String set = Set.class.getSimpleName();
            String map = Map.class.getSimpleName();

            throw new IllegalArgumentException("Parameter annotated with @" + RpcSplit.class.getSimpleName() + " has unsupported "
                + "type [supported-types={" + col + ", " + lst + ", " + set + ", " + map + "}, method=" + meth + ']');
        }
    }

    return splitIdx;
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:42,代碼來源:RpcMethodInfo.java

示例14: toJdbc

import java.util.OptionalInt; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 *
 * @see jp.co.future.uroborosql.parameter.mapper.BindParameterMapper#toJdbc(java.lang.Object, java.sql.Connection, jp.co.future.uroborosql.parameter.mapper.BindParameterMapperManager)
 */
@Override
public Object toJdbc(final OptionalInt original, final Connection connection,
		final BindParameterMapperManager parameterMapperManager) {
	return original.isPresent() ? original.getAsInt() : null;
}
 
開發者ID:future-architect,項目名稱:uroborosql,代碼行數:11,代碼來源:OptionalIntParameterMapper.java

示例15: stream

import java.util.OptionalInt; //導入方法依賴的package包/類
/**
 * If a value is present in {@code optional}, returns a stream containing only that element,
 * otherwise returns an empty stream.
 *
 * <p><b>Java 9 users:</b> use {@code optional.stream()} instead.
 */
public static IntStream stream(OptionalInt optional) {
  return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty();
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:10,代碼來源:Streams.java


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