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


Java Optional.equals方法代码示例

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


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

示例1: append

import java.util.Optional; //导入方法依赖的package包/类
private static boolean append(final List<Violation> violations, final ProcessingMessage message, final Optional<String> requiredLevel) {
    if (requiredLevel.isPresent()) {
        final Optional<String> level = ofNullable(message.asJson()).flatMap(node -> ofNullable(node.get("level")))
            .flatMap(node -> ofNullable(node.textValue()));

        if (!level.equals(requiredLevel)) {
            return false; // skip
        }
    }

    final Optional<String> property = ofNullable(message.asJson()).flatMap(node -> ofNullable(node.get("instance")))
        .flatMap(node -> ofNullable(node.get("pointer"))).flatMap(node -> ofNullable(node.textValue()));

    final Optional<String> error = ofNullable(message.asJson()).flatMap(node -> ofNullable(node.get("domain")))
        .flatMap(node -> ofNullable(node.textValue()));

    violations.add(new Violation.Builder().error(error.orElse("")).message(message.getMessage()).property(property.orElse("")).build());

    return true;
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:21,代码来源:SwaggerHelper.java

示例2: checkIntegrationStatus

import java.util.Optional; //导入方法依赖的package包/类
private void checkIntegrationStatus(Integration integration) {
    if (integration == null) {
        return;
    }
    Optional<Integration.Status> desired = integration.getDesiredStatus();
    Optional<Integration.Status> current = integration.getCurrentStatus();
    if (!current.equals(desired)) {
        desired.ifPresent(desiredStatus ->
            integration.getId().ifPresent(integrationId -> {
                StatusChangeHandlerProvider.StatusChangeHandler statusChangeHandler = handlers.get(desiredStatus);
                if (statusChangeHandler != null) {
                    LOG.info("Integration {} : Desired status \"{}\" != current status \"{}\" --> calling status change handler",
                                           integrationId, desiredStatus.toString(), current.map(Object::toString).orElse("[none]"));
                    callStatusChangeHandler(statusChangeHandler, integrationId);
                }
            }));
    } else {
        // When the desired state is reached remove the marker so that a next change trigger a check again
        // Doesn't harm when no such key exists
        desired.ifPresent(d -> scheduledChecks.remove(getIntegrationMarkerKey(integration)));
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:23,代码来源:IntegrationController.java

示例3: fieldToBean

import java.util.Optional; //导入方法依赖的package包/类
protected boolean fieldToBean(EasyBinding<BEAN, ?, ?> binding) {
	Optional<String> currentError = binding.getError();

	binding.read(getBean());
	if (!binding.hasConversionError()) {
		Optional<String> currentValidationError = binding.getValidationError();
		validate();
		if (!currentValidationError.equals(binding.getValidationError())) {
			// TODO: only fire if global change
			fireStatusChangeEvent();
		}
	}

	if (!currentError.equals(binding.getError())) {
		binding.validate(true);
	}
	fireStatusChangeEvent();

	return !binding.hasConversionError();
}
 
开发者ID:ljessendk,项目名称:easybinder,代码行数:21,代码来源:BasicBinder.java

示例4: stale

import java.util.Optional; //导入方法依赖的package包/类
private boolean stale(StatusChangeHandlerProvider.StatusChangeHandler handler, Integration integration) {
    if (integration == null || handler == null) {
        return true;
    }

    Optional<Integration.Status> desiredStatus = integration.getDesiredStatus();
    return !desiredStatus.isPresent()
           || desiredStatus.equals(integration.getCurrentStatus())
           || !handler.getTriggerStatuses().contains(desiredStatus.get());
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:11,代码来源:IntegrationController.java

示例5: verifyLeases

import java.util.Optional; //导入方法依赖的package包/类
public boolean verifyLeases(Collection<String> leaseKeys, String leaseOwnerKey) {
    String query = "select count(*) from lease where lease_key in ("
            + Strings.repeat(",?", leaseKeys.size()).substring(1) + ") "
            + "and owner_key = ? and expiration_date > current_timestamp";
    List<Object> params = new ArrayList<>(leaseKeys);
    params.add(leaseOwnerKey);
    Optional<Long> activeLeases = queries.queryForOptionalObject(query, Long.class, params.toArray());
    return activeLeases.equals(Optional.of((long) leaseKeys.size()));
}
 
开发者ID:OasisDigital,项目名称:nges,代码行数:10,代码来源:LeaseDao.java

示例6: validate

import java.util.Optional; //导入方法依赖的package包/类
@Override
public void validate(Object target, Errors errors) {
    final T typedObject = (T) target;

    // Controleer op datumAanvangGeldigheid/datumEindeGeldigheid.
    final Optional<Integer> datumAanvangGeldigheid = Optional.ofNullable(typedObject.getDatumAanvangGeldigheid());
    final Optional<Integer> datumEindeGeldigheid = Optional.ofNullable(typedObject.getDatumEindeGeldigheid());
    validateDatumvelden(datumAanvangGeldigheid.orElse(null), datumEindeGeldigheid.orElse(null), errors);
    if (!errors.hasErrors() && typedObject.getId() != null) {
        final T oudeEntiteit = stamgegevenRepository.findOne((U) typedObject.getId());
        final Optional<Integer> oudeDatumAanvangGeldigheid = Optional.ofNullable(oudeEntiteit.getDatumAanvangGeldigheid());
        if (!oudeDatumAanvangGeldigheid.equals(datumAanvangGeldigheid)) {
            ValidatieUtils.valideerDatumLigtNaHuidigeDatum(errors, oudeDatumAanvangGeldigheid.orElse(null), VELD_DATUM_AANVANG_GELDIGHEID,
                    VELD_HUIDIGE_DATUM_AANVANG_GELDIGHEID);
            ValidatieUtils.valideerDatumLigtOpOfNaHuidigeDatum(errors, datumAanvangGeldigheid.orElse(null), VELD_DATUM_AANVANG_GELDIGHEID);
        }
        final Optional<Integer> oudeDatumEindeGeldigheid = Optional.ofNullable(oudeEntiteit.getDatumEindeGeldigheid());
        if (!oudeDatumEindeGeldigheid.equals(datumEindeGeldigheid)) {
            ValidatieUtils.valideerDatumLigtNaHuidigeDatum(errors, oudeDatumEindeGeldigheid.orElse(null), VELD_DATUM_EINDE_GELDIGHEID,
                    VELD_HUIDIGE_DATUM_EINDE_GELDIGHEID);
            ValidatieUtils.valideerDatumLigtOpOfNaHuidigeDatum(errors, datumEindeGeldigheid.orElse(null), VELD_DATUM_EINDE_GELDIGHEID);
        }
    } else {
        ValidatieUtils.valideerDatumLigtOpOfNaHuidigeDatum(errors, datumAanvangGeldigheid.orElse(null), VELD_DATUM_AANVANG_GELDIGHEID);
        ValidatieUtils.valideerDatumLigtOpOfNaHuidigeDatum(errors, datumEindeGeldigheid.orElse(null), VELD_DATUM_EINDE_GELDIGHEID);
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:28,代码来源:GenericGeldigheidStamgegevenValidator.java

示例7: testVersion

import java.util.Optional; //导入方法依赖的package包/类
private static void testVersion() {
    Version current = Runtime.version();
    String javaVer = System.getProperty("java.runtime.version");

    // java.runtime.version == $VNUM(\-$PRE)?(\+$BUILD)?(-$OPT)?
    String [] jv  = javaVer.split("\\+");
    String [] ver = jv[0].split("-");
    List<Integer> javaVerVNum
        = Arrays.stream(ver[0].split("\\."))
        .map(Integer::parseInt)
        .collect(Collectors.toList());
    if (!javaVerVNum.equals(current.version())) {
        fail("Runtime.version()", javaVerVNum.toString(),
             current.version().toString());
    } else {
        pass();
    }

    Optional<String> javaVerPre
        = (ver.length == 2)
        ? Optional.ofNullable(ver[1])
        : Optional.empty();
    if (!javaVerPre.equals(current.pre())) {
        fail("testCurrent() pre()", javaVerPre.toString(),
             current.pre().toString());
    } else {
        pass();
    }

    testEHC(current.toString(), javaVer, true, true, 0, 0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:Basic.java

示例8: forwardToAppActorIfAdressChanged

import java.util.Optional; //导入方法依赖的package包/类
protected Optional<ServerAddress> forwardToAppActorIfAdressChanged(ActorContext ctx, ToDeviceActorMsg toForward,
    Optional<ServerAddress> oldAddress) {
  Optional<ServerAddress> newAddress = systemContext.getRoutingService().resolveById(toForward.getDeviceId());
  if (!newAddress.equals(oldAddress)) {
    if (newAddress.isPresent()) {
      systemContext.getRpcService().tell(newAddress.get(),
          toForward.toOtherAddress(systemContext.getRoutingService().getCurrentServer()));
    } else {
      getAppActor().tell(toForward, ctx.self());
    }
  }
  return newAddress;
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:14,代码来源:AbstractSessionActorMsgProcessor.java

示例9: queryJoin

import java.util.Optional; //导入方法依赖的package包/类
private JoinResult queryJoin(MatchPlayer joining, JoinRequest request, boolean queued) {
    final Optional<Team> lastTeam = lastTeam(joining.getPlayerId());
    final Optional<Team> chosenTeam = getInstanceOf(request.competitor(), Team.class);

    if(request.method() == JoinMethod.REMOTE) {
        // If remote joining, force the player onto a team
        return JoinAllowed.force(queryAutoJoin(joining, true));

    } else if(!request.competitor().isPresent()) {
        // If autojoining, and the player is already on a team, the request is satisfied
        if(Optionals.isInstance(joining.partyMaybe(), Competitor.class)) {
            return JoinDenied.error("command.gameplay.join.alreadyOnTeam", joining.getParty().getComponentName());
        }

        // If team choosing is disabled, and the match has not started yet, defer the join.
        // Note that this can only happen with autojoin. Choosing a team always fails if
        // the condition below is true.
        if(!queued && !config.allowChoose() && !getMatch().hasStarted()) {
            return new JoinQueued();
        }

        if(lastTeam.isPresent()) {
            // If the player was previously on a team, try to join that team first
            final JoinResult rejoin = lastTeam.get().queryJoin(joining, true, true);
            if(rejoin.isAllowed() || !canSwitchTeams(joining)) return rejoin;
            // If the join fails, and the player is allowed to switch teams, fall through to the auto-join
        }

        // Try to find a team for the player to join
        final JoinResult auto = queryAutoJoin(joining, true);
        if(auto.isAllowed()) return auto;

        if(jmm.canJoinFull(joining) || !joinConfiguration.overfill()) {
            return JoinDenied.unavailable("autoJoin.teamsFull");
        } else {
            // If the player is not premium, and overfill is enabled, plug the shop
            return JoinDenied.unavailable("autoJoin.teamsFull")
                .also(Links.shopPlug("shop.plug.joinFull"));
        }

    } else if(chosenTeam.isPresent()) {
        // If the player is already on the chosen team, there is nothing to do
        if(joining.hasParty() && contains(chosenTeam, joining.getParty())) {
            return JoinDenied.error("command.gameplay.join.alreadyOnTeam", joining.getParty().getComponentName());
        }

        // If team switching is disabled and the player is choosing to re-join their
        // last team, don't consider it a "choice" since that's the only team they can
        // join anyway. In any other case, check that they are allowed to choose their team.
        if(config.allowSwitch() || !chosenTeam.equals(lastTeam)) {
            // Team choosing is disabled
            if(!config.allowChoose()) {
                return JoinDenied.error("command.gameplay.join.choiceDisabled");
            }

            // Player is not allowed to choose their team
            if(!canChooseTeam(joining)) {
                return JoinDenied.unavailable("command.gameplay.join.choiceDenied")
                    .also(Links.shopPlug("shop.plug.chooseTeam"));
            }
        }

        // If team switching is disabled, check if the player is rejoining their former team
        if(!canSwitchTeams(joining) && lastTeam.isPresent()) {
            if(chosenTeam.equals(lastTeam)) {
                return chosenTeam.get().queryJoin(joining, true, true);
            } else {
                return JoinDenied.error("command.gameplay.join.switchDisabled", lastTeam.get().getComponentName());
            }
        }

        return chosenTeam.get().queryJoin(joining, true, false);
    }

    return null;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:77,代码来源:TeamMatchModule.java

示例10: shouldSendNotification

import java.util.Optional; //导入方法依赖的package包/类
static boolean shouldSendNotification(Instant jobStart, Instant deviceOffline, Instant lastNotification, List<Duration> thresholds) {
    Optional<Duration> lastPassedThreshold = calculateLastPassedThreshold(deviceOffline, jobStart, thresholds);

    return lastPassedThreshold.isPresent() && (lastNotification.isBefore(deviceOffline) || !lastPassedThreshold.equals(calculateLastPassedThreshold(deviceOffline, lastNotification, thresholds)));
}
 
开发者ID:pietvandongen,项目名称:pure-bliss-with-pure-java-functions,代码行数:6,代码来源:OfflineDevicesJobImpl.java

示例11: updateRemoteBuckets

import java.util.Optional; //导入方法依赖的package包/类
/**
 * Update local copy of remote buckets where local copy's version is older.
 *
 * @param receivedBuckets buckets sent by remote
 *                        {@link org.opendaylight.controller.remote.rpc.registry.gossip.Gossiper}
 */
@VisibleForTesting
void updateRemoteBuckets(final Map<Address, Bucket<?>> receivedBuckets) {
    LOG.debug("{}: receiveUpdateRemoteBuckets: {}", selfAddress, receivedBuckets);
    if (receivedBuckets == null || receivedBuckets.isEmpty()) {
        //nothing to do
        return;
    }

    final Map<Address, Bucket<T>> newBuckets = new HashMap<>(receivedBuckets.size());
    for (Entry<Address, Bucket<?>> entry : receivedBuckets.entrySet()) {
        final Address addr = entry.getKey();

        if (selfAddress.equals(addr)) {
            // Remote cannot update our bucket
            continue;
        }

        @SuppressWarnings("unchecked")
        final Bucket<T> receivedBucket = (Bucket<T>) entry.getValue();
        if (receivedBucket == null) {
            LOG.debug("Ignoring null bucket from {}", addr);
            continue;
        }

        // update only if remote version is newer
        final long remoteVersion = receivedBucket.getVersion();
        final Long localVersion = versions.get(addr);
        if (localVersion != null && remoteVersion <= localVersion.longValue()) {
            LOG.debug("Ignoring down-versioned bucket from {} ({} local {} remote)", addr, localVersion,
                remoteVersion);
            continue;
        }
        newBuckets.put(addr, receivedBucket);
        versions.put(addr, remoteVersion);
        final Bucket<T> prevBucket = remoteBuckets.put(addr, receivedBucket);

        // Deal with DeathWatch subscriptions
        final Optional<ActorRef> prevRef = prevBucket != null ? prevBucket.getWatchActor() : Optional.empty();
        final Optional<ActorRef> curRef = receivedBucket.getWatchActor();
        if (!curRef.equals(prevRef)) {
            prevRef.ifPresent(ref -> removeWatch(addr, ref));
            curRef.ifPresent(ref -> addWatch(addr, ref));
        }

        LOG.debug("Updating bucket from {} to version {}", entry.getKey(), remoteVersion);
    }

    LOG.debug("State after update - Local Bucket [{}], Remote Buckets [{}]", localBucket, remoteBuckets);

    onBucketsUpdated(newBuckets);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:58,代码来源:BucketStoreActor.java

示例12: shouldSendNotification

import java.util.Optional; //导入方法依赖的package包/类
/**
 * Checks whether a notification should be sent by determining which threshold has been passed last for the
 * calculated amount of time passed between the device going offline and the job running, taking the last sent
 * notification info account.
 *
 * @param jobStart         The instant the job calling this function was started.
 * @param deviceOffline    The instant the device went offline.
 * @param lastNotification The instant the last notification was sent.
 * @param thresholds       The list of notification thresholds.
 * @return True if the notification should be sent, false if not.
 */
static boolean shouldSendNotification(Instant jobStart, Instant deviceOffline, Instant lastNotification, List<Duration> thresholds) {
    Optional<Duration> lastPassedThreshold = calculateLastPassedThreshold(deviceOffline, jobStart, thresholds);

    return lastPassedThreshold.isPresent() && (lastNotification.isBefore(deviceOffline) || !lastPassedThreshold.equals(calculateLastPassedThreshold(deviceOffline, lastNotification, thresholds)));
}
 
开发者ID:pietvandongen,项目名称:pure-bliss-with-pure-java-functions,代码行数:17,代码来源:OfflineDevicesJobImpl.java


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