本文整理汇总了Java中com.google.common.base.Optional.equals方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.equals方法的具体用法?Java Optional.equals怎么用?Java Optional.equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.base.Optional
的用法示例。
在下文中一共展示了Optional.equals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPosition
import com.google.common.base.Optional; //导入方法依赖的package包/类
/**
* Sets the x,y,z of the entity from the given parameters. Also seems to set up a bounding box.
*/
public void setPosition(double x, double y, double z)
{
super.setPosition(x, y, z);
if (this.dataManager != null && this.ticksExisted != 0)
{
Optional<BlockPos> optional = (Optional)this.dataManager.get(ATTACHED_BLOCK_POS);
Optional<BlockPos> optional1 = Optional.<BlockPos>of(new BlockPos(x, y, z));
if (!optional1.equals(optional))
{
this.dataManager.set(ATTACHED_BLOCK_POS, optional1);
this.dataManager.set(PEEK_TICK, Byte.valueOf((byte)0));
this.isAirBorne = true;
}
}
}
示例2: shouldVoteFor
import com.google.common.base.Optional; //导入方法依赖的package包/类
@VisibleForTesting
boolean shouldVoteFor(@Nonnull RaftLog log, @Nonnull RequestVote request) {
Optional<Replica> lastVotedFor = log.lastVotedFor();
Replica candidate = Replica.fromString(request.getCandidateId());
boolean hasAtLeastTerm = request.getLastLogTerm() >= log.lastLogTerm();
boolean hasAtLeastIndex = request.getLastLogIndex() >= log.lastLogIndex();
boolean logAsComplete = (hasAtLeastTerm && hasAtLeastIndex);
boolean alreadyVotedForCandidate = lastVotedFor.equals(Optional.of(candidate));
boolean notYetVoted = !lastVotedFor.isPresent();
return (alreadyVotedForCandidate && logAsComplete) || (notYetVoted && logAsComplete) || (request.getLastLogTerm() > log.lastLogTerm()) || (hasAtLeastTerm && (request.getLastLogIndex() > log.lastLogIndex())) || logAsComplete;
}