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.epam.dlab.backendapi.service.impl.SchedulerJobServiceImpl.java

/**
 * Enriches existing scheduler job with the following data:
 * - sets current date as 'beginDate' if this parameter wasn't defined;
 * - sets current system time zone offset as 'timeZoneOffset' if this parameter wasn't defined.
 *
 * @param dto current scheduler job//from w w w. j av a 2s. c om
 */
private void enrichSchedulerJobIfNecessary(SchedulerJobDTO dto) {
    if (Objects.isNull(dto.getBeginDate()) || StringUtils.isBlank(dto.getBeginDate().toString())) {
        dto.setBeginDate(LocalDate.now());
    }
    if (Objects.isNull(dto.getTimeZoneOffset()) || StringUtils.isBlank(dto.getTimeZoneOffset().toString())) {
        dto.setTimeZoneOffset(OffsetDateTime.now(ZoneId.systemDefault()).getOffset());
    }
}

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

/**
 * The method addToBatches() adds a given process to the allover and the
 * annual batch. If the break mark changes, the logistics batch will be
 * flushed and the process will be added to a new logistics batch.
 *
 * @param process/*from w ww.  j a v  a  2  s  .  co m*/
 *            process to add
 * @param issues
 *            list of individual issues in the process
 * @param processTitle
 *            the title of the process
 */
private void addToBatches(Process process, List<IndividualIssue> issues, String processTitle)
        throws DataException {
    if (Objects.nonNull(createBatches)) {
        int lastIndex = issues.size() - 1;
        int breakMark = issues.get(lastIndex).getBreakMark(createBatches);
        if (Objects.nonNull(currentBreakMark) && breakMark != currentBreakMark) {
            flushLogisticsBatch(processTitle);
        }
        if (Objects.isNull(batchLabel)) {
            batchLabel = createBatches.format(issues.get(lastIndex).getDate());
        }
        logisticsBatch.getProcesses().add(process);
        currentBreakMark = breakMark;
    }
    fullBatch.getProcesses().add(process);
}

From source file:org.schemaspy.SchemaAnalyzer.java

/**
 * This method is responsible to copy layout folder to destination directory and not copy template .html files
 *
 * @param outputDir File//w  w  w .  j av  a2  s. c o m
 * @throws IOException when not possible to copy layout files to outputDir
 */
private void prepareLayoutFiles(File outputDir) throws IOException {
    URL url = null;
    Enumeration<URL> possibleResources = getClass().getClassLoader().getResources("layout");
    while (possibleResources.hasMoreElements() && Objects.isNull(url)) {
        URL possibleResource = possibleResources.nextElement();
        if (!possibleResource.getPath().contains("test-classes")) {
            url = possibleResource;
        }
    }

    IOFileFilter notHtmlFilter = FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(".html"));
    FileFilter filter = FileFilterUtils.and(notHtmlFilter);
    ResourceWriter.copyResources(url, outputDir, filter);
}

From source file:org.openecomp.sdc.validation.impl.util.ResourceValidationHeatValidator.java

private static void getResourceNamesListFromSpecificResource(String filename, List<String> resourcesNames,
        HeatResourcesTypes heatResourcesType, Map<String, Resource> resourcesMap,
        Set<String> sharedResourcesFromOutputMap, GlobalValidationContext globalContext) {

    for (Map.Entry<String, Resource> resourceEntry : resourcesMap.entrySet()) {
        String resourceType = resourceEntry.getValue().getType();
        if (Objects.isNull(resourceType)) {
            globalContext.addMessage(filename, ErrorLevel.WARNING,
                    ErrorMessagesFormatBuilder.getErrorWithParameters(
                            Messages.INVALID_RESOURCE_TYPE.getErrorMessage(), null, resourceEntry.getKey()));
        } else {/*from   ww  w  . j  av  a 2s.c  o m*/
            if (resourceType.equals(heatResourcesType.getHeatResource())
                    && !isSharedResource(resourceEntry.getKey(), sharedResourcesFromOutputMap)) {
                resourcesNames.add(resourceEntry.getKey());
            }
        }
    }
}

From source file:org.schemaspy.SchemaAnalyzer.java

private Connection getConnection(Config config) throws IOException {

    Properties properties = config.getDbProperties();

    ConnectionURLBuilder urlBuilder = new ConnectionURLBuilder(config, properties);
    if (config.getDb() == null)
        config.setDb(urlBuilder.build());

    String driverClass = properties.getProperty("driver");
    String driverPath = properties.getProperty("driverPath");
    if (Objects.isNull(driverPath))
        driverPath = "";

    if (Objects.nonNull(config.getDriverPath()))
        driverPath = config.getDriverPath();

    DbDriverLoader driverLoader = new DbDriverLoader();
    return driverLoader.getConnection(config, urlBuilder.build(), driverClass, driverPath);
}

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

private boolean isConsecutive(Card[] cards) {
    if (Objects.isNull(cards)) {
        return false;
    }//from   w  w  w .  j a  v  a 2 s  .  co  m
    boolean isConsec = true;
    int i, j;
    for (i = 0, j = i + 1; j < cards.length; i++, j++) {
        if (Math.abs(cards[j].getRank().value() - cards[i].getRank().value()) != 1) {
            isConsec = false;
            break;
        }
    }
    return isConsec;
}

From source file:com.epam.dlab.backendapi.dao.ComputationalDAO.java

public UpdateResult updateSchedulerDataForComputationalResource(String user, String exploratoryName,
        String computationalName, SchedulerJobDTO dto) {
    return updateComputationalField(user, exploratoryName, computationalName, SCHEDULER_DATA,
            Objects.isNull(dto) ? null : convertToBson(dto));
}

From source file:com.epam.dlab.backendapi.service.impl.SchedulerJobServiceImpl.java

private void checkResourceStatusOrElseThrowException(String resourceStatus) {
    final UserInstanceStatus status = UserInstanceStatus.of(resourceStatus);
    if (Objects.isNull(status) || status.in(UserInstanceStatus.TERMINATED, UserInstanceStatus.TERMINATING,
            UserInstanceStatus.FAILED)) {
        throw new ResourceInappropriateStateException(String
                .format("Can not create/update scheduler for user " + "instance with status: %s", status));
    }/*from  w ww  .j  a  v  a  2 s  . co  m*/
}

From source file:org.kitodo.production.services.data.LdapServerService.java

private boolean isPasswordCorrectForAuthWithoutTLS(Hashtable<String, String> env, User user, String password) {
    if (ConfigCore.getBooleanParameter(ParameterCore.LDAP_USE_SIMPLE_AUTH, false)) {
        env.put(Context.SECURITY_AUTHENTICATION, "none");
        // TODO: test for password
    } else {// w w w  .  jav a 2 s.c  o m
        env.put(Context.SECURITY_PRINCIPAL, buildUserDN(user));
        env.put(Context.SECURITY_CREDENTIALS, password);
    }
    logger.debug("ldap environment set");

    try {
        logger.debug("start classic ldap authentication");
        logger.debug("user DN is {}", buildUserDN(user));

        if (Objects.isNull(ConfigCore.getParameter(ParameterCore.LDAP_ATTRIBUTE_TO_TEST))) {
            logger.debug("ldap attribute to test is null");
            DirContext ctx = new InitialDirContext(env);
            ctx.close();
            return true;
        } else {
            logger.debug("ldap attribute to test is not null");
            DirContext ctx = new InitialDirContext(env);

            Attributes attrs = ctx.getAttributes(buildUserDN(user));
            Attribute la = attrs.get(ConfigCore.getParameter(ParameterCore.LDAP_ATTRIBUTE_TO_TEST));
            logger.debug("ldap attributes set");
            String test = (String) la.get(0);
            if (test.equals(ConfigCore.getParameter(ParameterCore.LDAP_VALUE_OF_ATTRIBUTE))) {
                logger.debug("ldap ok");
                ctx.close();
                return true;
            } else {
                logger.debug("ldap not ok");
                ctx.close();
                return false;
            }
        }
    } catch (NamingException e) {
        logger.debug("login not allowed for {}. Exception: {}", user.getLogin(), e);
        return false;
    }
}

From source file:org.schemaspy.SchemaAnalyzer.java

/**
 * dumpNoDataMessage//w ww. j  a v a  2 s .c  o  m
 *
 * @param schema String
 * @param user   String
 * @param meta   DatabaseMetaData
 */
private static void dumpNoTablesMessage(String schema, String user, DatabaseMetaData meta,
        boolean specifiedInclusions) throws SQLException {
    LOGGER.warn("No tables or views were found in schema '{}'.", schema);
    List<String> schemas;
    try {
        schemas = DbAnalyzer.getSchemas(meta);
    } catch (SQLException | RuntimeException exc) {
        LOGGER.error("The user you specified '{}' might not have rights to read the database metadata.", user,
                exc);
        return;
    }

    if (Objects.isNull(schemas)) {
        LOGGER.error("Failed to retrieve any schemas");
        return;
    } else if (schemas.contains(schema)) {
        LOGGER.error("The schema exists in the database, but the user you specified '{}'"
                + "might not have rights to read its contents.", user);
        if (specifiedInclusions) {
            LOGGER.error("Another possibility is that the regular expression that you specified "
                    + "for what to include (via -i) didn't match any tables.");
        }
    } else {
        LOGGER.error("The schema '{}' could not be read/found, schema is specified using the -s option."
                + "Make sure user '{}' has the correct privileges to read the schema."
                + "Also not that schema names are usually case sensitive.", schema, user);
        LOGGER.info("Available schemas(Some of these may be user or system schemas):" + System.lineSeparator()
                + "{}", schemas.stream().collect(Collectors.joining(System.lineSeparator())));
        List<String> populatedSchemas = DbAnalyzer.getPopulatedSchemas(meta);
        if (populatedSchemas.isEmpty()) {
            LOGGER.error("Unable to determine if any of the schemas contain tables/views");
        } else {
            LOGGER.info("Schemas with tables/views visible to '{}':" + System.lineSeparator() + "{}",
                    populatedSchemas.stream().collect(Collectors.joining(System.lineSeparator())));
        }
    }
}