Example usage for java.util Objects nonNull

List of usage examples for java.util Objects nonNull

Introduction

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

Prototype

public static boolean nonNull(Object obj) 

Source Link

Document

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

Usage

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Get the {@link ClusterType} with targetNamespace of the modelVersion.
 *
 * @param modelVersion/*from w w  w. j av a2s  .  c  o m*/
 *            the model version.
 * @param targetNamespace
 *            the target namespace.
 * @return the {@link ClusterType} with targetNamespace of the modelVersion.
 * @since 3.5.1
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public ClusterType getClusterByTargetNamespace(final String modelVersion, final String targetNamespace) {
    ClusterType value = null;
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<ClusterType> q = cb.createQuery(ClusterType.class);
    final Root<ClusterType> f = q.from(ClusterType.class);
    q.where(cb.equal(f.<String>get(ClusterType_.modelVersion), modelVersion),
            cb.equal(f.<String>get(ClusterType_.name), targetNamespace));
    final TypedQuery<ClusterType> typedQuery = this.em.createQuery(q);
    final List<ClusterType> list = typedQuery.getResultList();
    if (Objects.nonNull(list) && list.size() != 1) {
        value = list.get(0);
        EagerLoader.load(value);
    }
    return value;
}

From source file:com.qpark.eip.core.sftp.SftpGatewayImpl.java

private void getTreeOfEmptyDirectories(final List<String> emptyDirectories, final String parent,
        final String currentDirectory) throws Exception {
    String remotePath = parent;/*from  ww w .  ja  va 2  s. c o  m*/
    if (Objects.nonNull(currentDirectory)) {
        remotePath = String.format("%s%s%s", parent, this.getRemoteFileSeparator(), currentDirectory);
    }
    this.logger.trace("getTreeOfEmptyDirectories {} {}", parent, currentDirectory);
    final LsClientCallback callback = new LsClientCallback(remotePath, null);
    final Vector<LsEntry> entries = this.template.executeWithClient(callback);
    if (callback.getSftpException() != null) {
        this.logger.error("ls {} {}", remotePath, callback.getSftpException().getMessage());
        throw callback.getSftpException();
    } else if (Objects.nonNull(entries)) {
        final List<LsEntry> content = entries.stream()
                .filter(lsEntry -> !lsEntry.getFilename().equals(".") && !lsEntry.getFilename().equals(".."))
                .collect(Collectors.toList());
        if (content.isEmpty()) {
            emptyDirectories.add(remotePath);
            this.logger.trace("getTreeOfEmptyDirectories {} {} added {}", parent, currentDirectory, remotePath);
        } else {
            final String rPath = remotePath;
            content.stream().filter(lsEntry -> lsEntry.getAttrs().isDir()).forEach(lsEntry -> {
                try {
                    this.getTreeOfEmptyDirectories(emptyDirectories, rPath, lsEntry.getFilename());
                } catch (final Exception e) {
                }
            });
        }
    }
}

From source file:de.speexx.jira.jan.command.transition.IssueTransitionFetcher.java

Optional<IssueInfo> handleChangeLog(final Iterable<ChangelogGroup> changeLogs, final Issue issue) {
    assert Objects.nonNull(issue);

    if (changeLogs != null) {
        final IssueInfo info = new IssueInfo();
        for (final ChangelogGroup changeLog : changeLogs) {
            for (final ChangelogItem item : changeLog.getItems()) {
                final String fieldName = item.getField();

                if (STATUS_CHANGELOG_ENTRY.equalsIgnoreCase(fieldName)) {
                    final StageInfo si = new StageInfo();

                    final String name = item.getToString();
                    if (name != null) {
                        si.stageName = name;
                        si.fromStageName = item.getFromString();
                        si.stageStart = extractChangeLogCreateDateToAsDateTime(changeLog);
                        info.stageInfos.add(si);
                    }/*from   w ww. j  a v  a 2 s . com*/
                }
            }
        }
        return Optional.of(info);
    } else {
        LOG.debug("No change log in issue {}", issue.getKey());
    }
    return Optional.empty();
}

From source file:org.kitodo.production.process.TitleGenerator.java

private String evaluateAdditionalFields(String currentTitle, String currentAuthors, String token)
        throws ProcessGenerationException {
    StringBuilder newTitle = new StringBuilder();

    for (AdditionalField additionalField : this.additionalFields) {
        String title = additionalField.getTitle();
        String value = additionalField.getValue();
        boolean showDependingOnDoctype = additionalField.showDependingOnDoctype();
        /*/*from   ww  w  .  ja  va 2 s .  c o m*/
         * if it is the ATS or TSL field, then use the calculated atstsl if it does not
         * already exist
         */
        if (("ATS".equals(title) || "TSL".equals(title)) && showDependingOnDoctype
                && StringUtils.isEmpty(value)) {
            if (StringUtils.isEmpty(this.atstsl)) {
                this.atstsl = createAtstsl(currentTitle, currentAuthors);
            }
            additionalField.setValue(this.atstsl);
            value = additionalField.getValue();
        }

        // add the content to the title
        if (title.equals(token) && showDependingOnDoctype && Objects.nonNull(value)) {
            newTitle.append(calculateProcessTitleCheck(title, value));
        }
    }
    return newTitle.toString();
}

From source file:com.mac.halendpoint.endpoints.ProtocolRouter.java

@ProtocolMapping(routeTo = "view", respondTo = "route", numParams = 1)
private String router(String viewName) throws Exception {
    if (Objects.nonNull(viewName)) {
        return viewName;
    }/*www .  j a  v a2  s. c  om*/
    return Status.NOT_MODIFIED.name();
}

From source file:com.mac.abstractrepository.entities.budget.Payment.java

@Override
public void generateId() {
    if (Objects.isNull(paymentId) || paymentId.isEmpty()) {
        if (Objects.nonNull(paymentBillId) && Objects.nonNull(paymentUserId)) {
            try {
                normalize(this, getClass().getDeclaredFields());
                Field idField = getClass().getDeclaredField("paymentId");
                generateId(idField, paymentBillId.getBillId(), paymentUserId.getUserId(),
                        String.valueOf(paymentDueDate.getTime()), String.valueOf(paymentFilingDate.getTime()));
            } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException
                    | SecurityException ex) {
                Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex);
            }//from w w w .  ja  v a  2  s  .c om
        }
    }
}

From source file:org.goobi.production.cli.helper.CopyProcess.java

/**
 * die Eingabefelder fr die Eigenschaften mit Inhalten aus der RDF-Datei
 * fllen./*ww  w  . j a  v a 2 s . c  om*/
 */
private void fillFieldsFromMetadataFile(LegacyMetsModsDigitalDocumentHelper myRdf) {
    if (Objects.nonNull(myRdf)) {
        for (AdditionalField field : this.additionalFields) {
            if (field.isUghBinding() && field.showDependingOnDoctype()) {
                LegacyDocStructHelperInterface myTempStruct = getDocstructForMetadataFile(myRdf, field);
                try {
                    setMetadataForMetadataFile(field, myTempStruct);
                } catch (IllegalArgumentException e) {
                    Helper.setErrorMessage(e.getMessage(), logger, e);
                }
            }
        }
    }
}

From source file:com.mac.halendpoint.endpoints.ProtocolRouter.java

private String formUri(String base, String... paths) {
    if (Objects.nonNull(base)) {
        StringBuilder sb = new StringBuilder(base);
        if (Objects.nonNull(paths)) {
            int count = paths.length - 1;
            for (String path : paths) {
                sb.append(path);/*from   www.  j  a v  a2 s. c o  m*/
                if (count > 0) {
                    sb.append("/");
                    count--;
                }
            }
            return sb.toString();
        }
    }
    return base;
}

From source file:com.fantasy.stataggregator.workers.GameDataRetrieverTask.java

/**
 * Determines if a game has already been played, No current game data<br>
 * will be pulled, since the statistics aren't final.
 *
 * @param sched/*  ww w  .  ja  va 2  s  .c  o m*/
 * @return
 */
private boolean hasBeenPlayed(GameSchedule sched) throws ParseException {
    Date gameDate = sched.getGamedate();
    if (Objects.nonNull(gameDate)) {
        LocalDate dateOnly = LocalDateTime.ofInstant(gameDate.toInstant(), ZoneId.systemDefault())
                .toLocalDate();

        return dateOnly.isBefore(LocalDate.now());
    }
    return false;
}

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

private Model provisionModel(Model model, Map<String, ?> options) throws IOException {
    try {/*from w w w  .j av  a2s .  com*/
        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;
}