Example usage for java.util Objects isNull

List of usage examples for java.util Objects isNull

Introduction

In this page you can find the example usage for java.util Objects isNull.

Prototype

public static boolean isNull(Object obj) 

Source Link

Document

Returns true if the provided reference is null otherwise returns false .

Usage

From source file:com.mac.holdempoker.app.impl.util.HandMatrix.java

/**
 * FOUR OF A KIND/*from  w  w  w  .  j  a  va2  s  .  c  om*/
 *
 * @return
 */
private HandRank cHandRank() {
    Rank[] qRank = getRanksWithCount(4, 1);
    //        System.out.println("qRank: " + Arrays.toString(qRank));
    if (qRank.length != 1) {
        return null;
    }
    //        Rank r = null;//qRank[0];
    List<Card> cards = new ArrayList(5);
    int index = 0;
    for (Suit suit : Suit.values()) {
        cards.add(makeCard(suit, qRank[index]));
    }
    Rank r = getHighestRankNotEqualTo(qRank[0]);
    //        System.out.println("singleRank: " + r);
    if (Objects.isNull(r)) {
        return null;
    }
    List<Suit> suits = getSuitsForRank(r);
    cards.add(makeCard(suits.get(0), r));
    Collections.sort(cards, this);
    return new SimpleHandRank(HandType.FOUR_OF_A_KIND, cards.toArray(new Card[5]));
}

From source file:org.esa.s3tbx.olci.radiometry.rayleigh.RayleighAux.java

public Map<Integer, List<double[]>> getInterpolation() {
    if (Objects.isNull(interpolateMap)) {
        interpolateMap = getSpikeInterpolation();
    }/* w w  w  . j av a 2  s  .  c o  m*/
    return interpolateMap;
}

From source file:org.kitodo.production.helper.tasks.EmptyTask.java

/**
 * The function getDurationDead() returns the duration the task is dead. If
 * a time of death has not yet been recorded, null is returned.
 *
 * @return the duration since the task died
 *///from w  ww  .j  av a 2s.  com
Duration getDurationDead() {
    if (Objects.isNull(passedAway)) {
        return null;
    }
    long elapsed = System.nanoTime() - passedAway;
    return new Duration(TimeUnit.MILLISECONDS.convert(elapsed, TimeUnit.NANOSECONDS));
}

From source file:org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.FilesResource.java

@DELETE
@Path("/{fileName}")
public Response deleteFile(@PathParam("fileName") String fileName, @QueryParam("path") String path) {
    path = Objects.isNull(path) ? "" : path;
    RepositoryFileReference ref = this.fileName2fileRef(fileName, path, true);
    return RestUtils.delete(ref);
}

From source file:fr.brouillard.oss.jgitver.JGitverModelProcessor.java

private Model provisionModel(Model model, Map<String, ?> options) throws IOException {
    try {//from   w  ww .jav a  2s  . c  om
        calculateVersionIfNecessary();
    } catch (Exception ex) {
        throw new IOException("cannot build a Model object using jgitver", ex);
    }

    Source source = (Source) options.get(ModelProcessor.SOURCE);
    //logger.debug( "JGitverModelProcessor.provisionModel source="+source );
    if (source == null) {
        return model;
    }

    File location = new File(source.getLocation());
    //logger.debug( "JGitverModelProcessor.provisionModel location="+location );
    if (!location.isFile()) {
        // their JavaDoc says Source.getLocation "could be a local file path, a URI or just an empty string."
        // if it doesn't resolve to a file then calling .getParentFile will throw an exception,
        // but if it doesn't resolve to a file then it isn't under getMultiModuleProjectDirectory,
        return model; // therefore the model shouldn't be modified.
    }

    File relativePath = location.getParentFile().getCanonicalFile();

    if (StringUtils.containsIgnoreCase(relativePath.getCanonicalPath(),
            workingConfiguration.getMultiModuleProjectDirectory().getCanonicalPath())) {

        workingConfiguration.getNewProjectVersions().put(GAV.from(model.clone()),
                workingConfiguration.getCalculatedVersion());

        if (Objects.nonNull(model.getVersion())) {
            // TODO evaluate how to set the version only when it was originally set in the pom file
            model.setVersion(workingConfiguration.getCalculatedVersion());
        }

        if (Objects.nonNull(model.getParent())) {
            // if the parent is part of the multi module project, let's update the parent version 
            File relativePathParent = new File(
                    relativePath.getCanonicalPath() + File.separator + model.getParent().getRelativePath())
                            .getParentFile().getCanonicalFile();
            if (StringUtils.containsIgnoreCase(relativePathParent.getCanonicalPath(),
                    workingConfiguration.getMultiModuleProjectDirectory().getCanonicalPath())) {
                model.getParent().setVersion(workingConfiguration.getCalculatedVersion());
            }
        }

        // we should only register the plugin once, on the main project
        if (relativePath.getCanonicalPath()
                .equals(workingConfiguration.getMultiModuleProjectDirectory().getCanonicalPath())) {
            if (Objects.isNull(model.getBuild())) {
                model.setBuild(new Build());
            }

            if (Objects.isNull(model.getBuild().getPlugins())) {
                model.getBuild().setPlugins(new ArrayList<>());
            }

            Optional<Plugin> pluginOptional = model.getBuild().getPlugins().stream()
                    .filter(x -> JGitverUtils.EXTENSION_GROUP_ID.equalsIgnoreCase(x.getGroupId())
                            && JGitverUtils.EXTENSION_ARTIFACT_ID.equalsIgnoreCase(x.getArtifactId()))
                    .findFirst();

            StringBuilder pluginVersion = new StringBuilder();

            try (InputStream inputStream = getClass()
                    .getResourceAsStream("/META-INF/maven/" + JGitverUtils.EXTENSION_GROUP_ID + "/"
                            + JGitverUtils.EXTENSION_ARTIFACT_ID + "/pom" + ".properties")) {
                Properties properties = new Properties();
                properties.load(inputStream);
                pluginVersion.append(properties.getProperty("version"));
            } catch (IOException ignored) {
                // TODO we should not ignore in case we have to reuse it
                logger.warn(ignored.getMessage(), ignored);
            }

            Plugin plugin = pluginOptional.orElseGet(() -> {
                Plugin plugin2 = new Plugin();
                plugin2.setGroupId(JGitverUtils.EXTENSION_GROUP_ID);
                plugin2.setArtifactId(JGitverUtils.EXTENSION_ARTIFACT_ID);
                plugin2.setVersion(pluginVersion.toString());

                model.getBuild().getPlugins().add(plugin2);
                return plugin2;
            });

            if (Objects.isNull(plugin.getExecutions())) {
                plugin.setExecutions(new ArrayList<>());
            }

            Optional<PluginExecution> pluginExecutionOptional = plugin.getExecutions().stream()
                    .filter(x -> "verify".equalsIgnoreCase(x.getPhase())).findFirst();

            PluginExecution pluginExecution = pluginExecutionOptional.orElseGet(() -> {
                PluginExecution pluginExecution2 = new PluginExecution();
                pluginExecution2.setPhase("verify");

                plugin.getExecutions().add(pluginExecution2);
                return pluginExecution2;
            });

            if (Objects.isNull(pluginExecution.getGoals())) {
                pluginExecution.setGoals(new ArrayList<>());
            }

            if (!pluginExecution.getGoals().contains(JGitverAttachModifiedPomsMojo.GOAL_ATTACH_MODIFIED_POMS)) {
                pluginExecution.getGoals().add(JGitverAttachModifiedPomsMojo.GOAL_ATTACH_MODIFIED_POMS);
            }

            if (Objects.isNull(plugin.getDependencies())) {
                plugin.setDependencies(new ArrayList<>());
            }

            Optional<Dependency> dependencyOptional = plugin.getDependencies().stream()
                    .filter(x -> JGitverUtils.EXTENSION_GROUP_ID.equalsIgnoreCase(x.getGroupId())
                            && JGitverUtils.EXTENSION_ARTIFACT_ID.equalsIgnoreCase(x.getArtifactId()))
                    .findFirst();

            dependencyOptional.orElseGet(() -> {
                Dependency dependency = new Dependency();
                dependency.setGroupId(JGitverUtils.EXTENSION_GROUP_ID);
                dependency.setArtifactId(JGitverUtils.EXTENSION_ARTIFACT_ID);
                dependency.setVersion(pluginVersion.toString());

                plugin.getDependencies().add(dependency);
                return dependency;
            });
        }

        try {
            legacySupport.getSession().getUserProperties().put(
                    JGitverModelProcessorWorkingConfiguration.class.getName(),
                    JGitverModelProcessorWorkingConfiguration.serializeTo(workingConfiguration));
        } catch (JAXBException ex) {
            throw new IOException("unexpected Model serialization issue", ex);
        }
    }

    return model;
}

From source file:org.kitodo.production.ldap.LdapUser.java

/**
 * Replace Variables with current user details.
 *
 * @param inString//from  www . ja  v  a2s.  c o m
 *            String
 * @param inUser
 *            User object
 * @param inUidNumber
 *            String
 * @return String with replaced variables
 */
private String replaceVariables(String inString, User inUser, String inUidNumber) {
    if (Objects.isNull(inString)) {
        return "";
    }
    String result = inString.replaceAll("\\{login\\}", inUser.getLogin());
    result = result.replaceAll("\\{user full name\\}", inUser.getName() + " " + inUser.getSurname());
    result = result.replaceAll("\\{uidnumber\\*2\\+1000\\}",
            String.valueOf(Integer.parseInt(inUidNumber) * 2 + 1000));
    result = result.replaceAll("\\{uidnumber\\*2\\+1001\\}",
            String.valueOf(Integer.parseInt(inUidNumber) * 2 + 1001));
    logger.debug("Replace instring: {} - {} - {}", inString, inUser, inUidNumber);
    logger.debug("Replace outstring: {}", result);
    return result;
}

From source file:org.kitodo.production.forms.dataeditor.StructurePanel.java

private static MediaUnit preservePhysicalRecursive(TreeNode treeNode) {
    StructureTreeNode structureTreeNode = (StructureTreeNode) treeNode.getData();
    if (Objects.isNull(structureTreeNode) || !(structureTreeNode.getDataObject() instanceof MediaUnit)) {
        return null;
    }/*ww w.  ja  v  a  2s  .com*/
    MediaUnit mediaUnit = (MediaUnit) structureTreeNode.getDataObject();

    List<MediaUnit> childrenLive = mediaUnit.getChildren();
    childrenLive.clear();
    for (TreeNode child : treeNode.getChildren()) {
        MediaUnit possibleChildMediaUnit = preservePhysicalRecursive(child);
        if (Objects.nonNull(possibleChildMediaUnit)) {
            childrenLive.add(possibleChildMediaUnit);
        }
    }
    return mediaUnit;
}

From source file:org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl.java

private Set<String> createAnalyzedImportFilesSet(Set<String> analyzedImportFiles) {
    if (Objects.isNull(analyzedImportFiles)) {
        analyzedImportFiles = new HashSet<>();
    }/*w  w  w  .j a v  a  2s  .c o m*/
    return analyzedImportFiles;
}

From source file:de.speexx.jira.jan.command.issuequery.CsvCreator.java

List<String> fetchCurrentFieldEntries(final IssueData issueData, final List<FieldNamePath> currentFieldNames) {
    assert !Objects.isNull(issueData);
    assert !Objects.isNull(currentFieldNames);

    final List<String> retval = new ArrayList<>();

    currentFieldNames.stream().map(path -> issueData.getCurrentIssueData(path)).forEach(value -> {
        retval.add(objectToString(value));
    });//from   ww  w. java 2s  .c o m

    return Collections.unmodifiableList(retval);
}

From source file:com.caricah.iotracah.core.worker.DumbWorker.java

/**
 * Provides the Observer with a new item to observe.
 * <p>/* w  w  w.  ja  v a  2s  . com*/
 * The {@link com.caricah.iotracah.core.modules.Server} may call this method 0 or more times.
 * <p>
 * The {@code Observable} will not call this method again after it calls either {@link #onCompleted} or
 * {@link #onError}.
 *
 * @param iotMessage the item emitted by the Observable
 */
@Override
public void onNext(IOTMessage iotMessage) {

    getExecutorService().submit(() -> {
        log.info(" onNext : received {}", iotMessage);
        try {

            IOTMessage response = null;

            switch (iotMessage.getMessageType()) {
            case ConnectMessage.MESSAGE_TYPE:
                ConnectMessage connectMessage = (ConnectMessage) iotMessage;
                response = ConnectAcknowledgeMessage.from(connectMessage.isDup(), connectMessage.getQos(),
                        connectMessage.isRetain(), connectMessage.getKeepAliveTime(),
                        MqttConnectReturnCode.CONNECTION_ACCEPTED);

                break;
            case SubscribeMessage.MESSAGE_TYPE:

                SubscribeMessage subscribeMessage = (SubscribeMessage) iotMessage;

                List<Integer> grantedQos = new ArrayList<>();
                subscribeMessage.getTopicFilterList().forEach(topic -> {

                    String topicKey = quickCheckIdKey("",
                            Arrays.asList(topic.getKey().split(Constant.PATH_SEPARATOR)));

                    Set<String> channelIds = subscriptions.get(topicKey);

                    if (Objects.isNull(channelIds)) {
                        channelIds = new HashSet<>();
                    }

                    channelIds.add(subscribeMessage.getConnectionId());
                    subscriptions.put(topicKey, channelIds);

                    grantedQos.add(topic.getValue());

                });

                response = SubscribeAcknowledgeMessage.from(subscribeMessage.getMessageId(), grantedQos);

                break;
            case UnSubscribeMessage.MESSAGE_TYPE:
                UnSubscribeMessage unSubscribeMessage = (UnSubscribeMessage) iotMessage;
                response = UnSubscribeAcknowledgeMessage.from(unSubscribeMessage.getMessageId());

                break;
            case Ping.MESSAGE_TYPE:
                response = iotMessage;
                break;
            case PublishMessage.MESSAGE_TYPE:

                PublishMessage publishMessage = (PublishMessage) iotMessage;

                Set<String> matchingTopics = getMatchingSubscriptions("", publishMessage.getTopic());

                for (String match : matchingTopics) {
                    Set<String> channelIds = subscriptions.get(match);

                    if (Objects.nonNull(channelIds)) {

                        channelIds.forEach(id -> {

                            PublishMessage clonePublishMessage = publishMessage.cloneMessage();
                            clonePublishMessage.copyTransmissionData(iotMessage);
                            clonePublishMessage.setConnectionId(id);
                            pushToServer(clonePublishMessage);
                        });

                    }

                }

                if (MqttQoS.AT_MOST_ONCE.value() == publishMessage.getQos()) {

                    break;

                } else if (MqttQoS.AT_LEAST_ONCE.value() == publishMessage.getQos()) {

                    response = AcknowledgeMessage.from(publishMessage.getMessageId());
                    break;

                }

            case PublishReceivedMessage.MESSAGE_TYPE:
            case ReleaseMessage.MESSAGE_TYPE:
            case CompleteMessage.MESSAGE_TYPE:
            case DisconnectMessage.MESSAGE_TYPE:
            case AcknowledgeMessage.MESSAGE_TYPE:
            default:
                DisconnectMessage disconnectMessage = DisconnectMessage.from(true);
                disconnectMessage.copyTransmissionData(iotMessage);

                throw new ShutdownException(disconnectMessage);

            }

            if (Objects.nonNull(response)) {

                response.copyTransmissionData(iotMessage);
                pushToServer(response);
            }

        } catch (ShutdownException e) {

            IOTMessage response = e.getResponse();
            if (Objects.nonNull(response)) {
                pushToServer(response);
            }

        } catch (Exception e) {
            log.error(" onNext : Serious error that requires attention ", e);
        }

    });
}