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.caricah.iotracah.datastore.ignitecache.internal.impl.PartitionHandler.java

@Override
public void initiate(Class<IotPartition> t, Ignite ignite) {
    super.initiate(t, ignite);

    //Make sure the default partition is available.
    IotPartition partition = new IotPartition();
    partition.setName(getDefaultPartitionName());
    partition.setDescription("Default partition auto created by iotracah for ");
    partition.setIsActive(true);/*from   w  w  w . j av a  2s .  c  o  m*/
    partition.setLocked(false);

    IotPartitionKey partitionKey = keyFromModel(partition);

    Observable<IotPartition> partitionObservable = getByKeyWithDefault(partitionKey, null);

    partitionObservable.subscribe(iotPartition -> {

        if (Objects.isNull(iotPartition)) {
            save(partition);
        }
    });

}

From source file:org.eclipse.winery.repository.backend.filebased.ConfigurationBasedNamespaceManager.java

@Override
public void setNamespaceProperties(String namespace, NamespaceProperties properties) {
    if (Objects.isNull(namespace) || namespace.isEmpty() || Objects.isNull(properties)
            || Objects.isNull(properties.getPrefix()) || properties.getPrefix().isEmpty()) {
        return;// w w  w . ja v  a 2s . c  o  m
    }

    if (!this.getAllPermanentPrefixes().contains(properties.getPrefix())) {
        this.configuration.setProperty(namespace, properties.getPrefix());
        // ensure that in-memory mapping does not have the key any more
        this.namespaceToPrefixMap.remove(namespace);
    }
}

From source file:org.kitodo.production.helper.VariableReplacer.java

/**
 * Variablen innerhalb eines Strings ersetzen. Dabei vergleichbar zu Ant die
 * Variablen durchlaufen und aus dem Digital Document holen
 *
 * @param inString/*from w w w .  j  a va2  s . c o m*/
 *            to replacement
 * @return replaced String
 */
public String replace(String inString) {
    if (Objects.isNull(inString)) {
        return "";
    }
    inString = replaceMetadata(inString);

    // replace paths and files
    try {
        // TIFF writer scripts will have a path without an end slash
        String tifPath = replaceSlashAndSeparator(processService.getImagesTifDirectory(false,
                this.process.getId(), this.process.getTitle(), this.process.getProcessBaseUri()));
        String imagePath = replaceSlashAndSeparator(fileService.getImagesDirectory(this.process));
        String origPath = replaceSlashAndSeparator(
                processService.getImagesOriginDirectory(false, this.process));
        String processPath = replaceSlashAndSeparator(processService.getProcessDataDirectory(this.process));
        String metaFile = replaceSlash(fileService.getMetadataFilePath(this.process, false));
        String ocrBasisPath = replaceSlashAndSeparator(fileService.getOcrDirectory(this.process));
        String ocrPlaintextPath = replaceSlashAndSeparator(fileService.getTxtDirectory(this.process));
        String sourcePath = replaceSlashAndSeparator(fileService.getSourceDirectory(this.process));
        String importPath = replaceSlashAndSeparator(fileService.getImportDirectory(this.process));
        String prefs = ConfigCore.getParameter(ParameterCore.DIR_RULESETS)
                + this.process.getRuleset().getFile();

        inString = replaceStringAccordingToOS(inString, "(tifurl)", tifPath);
        inString = replaceStringAccordingToOS(inString, "(origurl)", origPath);
        inString = replaceStringAccordingToOS(inString, "(imageurl)", imagePath);

        inString = replaceString(inString, "(tifpath)", tifPath);
        inString = replaceString(inString, "(origpath)", origPath);
        inString = replaceString(inString, "(imagepath)", imagePath);
        inString = replaceString(inString, "(processpath)", processPath);
        inString = replaceString(inString, "(importpath)", importPath);
        inString = replaceString(inString, "(sourcepath)", sourcePath);
        inString = replaceString(inString, "(ocrbasispath)", ocrBasisPath);
        inString = replaceString(inString, "(ocrplaintextpath)", ocrPlaintextPath);
        inString = replaceString(inString, "(processtitle)", this.process.getTitle());
        inString = replaceString(inString, "(processid)", String.valueOf(this.process.getId().intValue()));
        inString = replaceString(inString, "(metaFile)", metaFile);
        inString = replaceString(inString, "(prefs)", prefs);

        inString = replaceStringForTask(inString);

        inString = replaceForWorkpieceProperty(inString);
        inString = replaceForTemplateProperty(inString);
        inString = replaceForProcessProperty(inString);

    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }

    return inString;
}

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

/**
 * configure LdapUser with User data./*from   ww w.j a  v  a 2s  .co m*/
 *
 * @param user
 *            User object
 * @param inPassword
 *            String
 * @param inUidNumber
 *            String
 */
public void configure(User user, String inPassword, String inUidNumber)
        throws NamingException, NoSuchAlgorithmException {
    MD4 digester = new MD4();
    if (!user.getLdapGroup().getLdapServer().isReadOnly()) {

        if (Objects.nonNull(user.getLdapLogin())) {
            this.ldapLogin = user.getLdapLogin();

        } else {
            this.ldapLogin = user.getLogin();
        }

        LdapGroup ldapGroup = user.getLdapGroup();
        if (Objects.isNull(ldapGroup.getObjectClasses())) {
            throw new NamingException("no objectclass defined");
        }

        prepareAttributes(ldapGroup, user, inUidNumber);

        /*
         * Samba passwords
         */
        /* LanMgr */
        try {
            this.attributes.put("sambaLMPassword", toHexString(lmHash(inPassword)));
        } catch (InvalidKeyException | NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException
                | RuntimeException e) {
            logger.error(e.getMessage(), e);
        }
        /* NTLM */
        byte[] hmm = digester.digest(inPassword.getBytes(StandardCharsets.UTF_16LE));
        this.attributes.put("sambaNTPassword", toHexString(hmm));

        /*
         * Encryption of password und Base64-Enconding
         */

        String passwordEncrytion = ldapGroup.getLdapServer().getPasswordEncryption().getTitle();

        MessageDigest md = MessageDigest.getInstance(passwordEncrytion);
        md.update(inPassword.getBytes(StandardCharsets.UTF_8));
        String encodedDigest = new String(Base64.encodeBase64(md.digest()), StandardCharsets.UTF_8);
        this.attributes.put("userPassword", "{" + passwordEncrytion + "}" + encodedDigest);
    }
}

From source file:org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationBase.java

static Optional<ResourceFileDataAndIDs> getFileDataContainingResource(List<FileData> filesToSearch,
        String resourceId, TranslationContext context, FileData.Type... types) {
    if (CollectionUtils.isEmpty(filesToSearch)) {
        return Optional.empty();
    }// w  w w . ja  va  2s .  c  o  m

    List<FileData> fileDatas = Objects.isNull(types) ? filesToSearch
            : HeatToToscaUtil.getFilteredListOfFileDataByTypes(filesToSearch, types);
    for (FileData data : fileDatas) {
        HeatOrchestrationTemplate heatOrchestrationTemplate = new YamlUtil().yamlToObject(
                context.getFiles().getFileContent(data.getFile()), HeatOrchestrationTemplate.class);
        Map<String, Output> outputs = heatOrchestrationTemplate.getOutputs();
        if (Objects.isNull(outputs)) {
            continue;
        }
        Output output = outputs.get(resourceId);
        if (Objects.nonNull(output)) {
            Optional<AttachedResourceId> attachedOutputId = HeatToToscaUtil.extractAttachedResourceId(
                    data.getFile(), heatOrchestrationTemplate, context, output.getValue());
            if (attachedOutputId.isPresent()) {
                AttachedResourceId attachedResourceId = attachedOutputId.get();
                if (!attachedResourceId.isGetResource()) {
                    logger.warn("output: '" + resourceId + "' in file '" + data.getFile()
                            + "' is not defined as get_resource and therefor not supported.");
                    continue;
                }
                ResourceFileDataAndIDs fileDataAndIDs = new ResourceFileDataAndIDs(
                        (String) attachedResourceId.getEntityId(),
                        (String) attachedResourceId.getTranslatedId(), data);
                return Optional.of(fileDataAndIDs);
            }
        }
    }
    return Optional.empty();
}

From source file:org.eclipse.winery.common.version.WineryVersion.java

@Override
@ADR(19)/*w  w w . j  a va 2 s.c  om*/
public int compareTo(WineryVersion o) {
    if (Objects.isNull(o)) {
        return 1;
    }

    int cVersion = this.componentVersion.compareToIgnoreCase(o.componentVersion);
    if (cVersion < 0) {
        return -1;
    } else if (cVersion > 0) {
        return 1;
    }

    if (this.wineryVersion < o.wineryVersion) {
        return -1;
    } else if (this.wineryVersion > o.wineryVersion) {
        return 1;
    }

    if (this.wineryVersion > 0 && this.workInProgressVersion == 0) {
        return 1;
    } else if (o.wineryVersion > 0 && o.workInProgressVersion == 0) {
        return -1;
    }

    if (this.workInProgressVersion < o.workInProgressVersion) {
        return -1;
    } else if (this.workInProgressVersion > o.workInProgressVersion) {
        return 1;
    }

    return 0;
}

From source file:io.openshift.booster.service.FruitController.java

private void verifyCorrectPayload(Fruit fruit) {
    if (Objects.isNull(fruit)) {
        throw new UnsupportedMediaTypeException("Fruit cannot be null");
    }/*from w  ww.j a va 2s.  c  o  m*/

    if (!Objects.isNull(fruit.getId())) {
        throw new UnprocessableEntityException("Id filed must be generated");
    }
}

From source file:alfio.controller.form.PaymentForm.java

public void validate(BindingResult bindingResult, TotalPrice reservationCost, Event event,
        List<TicketFieldConfiguration> fieldConf) {

    List<PaymentProxy> allowedPaymentMethods = event.getAllowedPaymentProxies();

    Optional<PaymentProxy> paymentProxyOptional = Optional.ofNullable(paymentMethod);
    PaymentProxy paymentProxy = paymentProxyOptional.filter(allowedPaymentMethods::contains)
            .orElse(PaymentProxy.STRIPE);
    boolean priceGreaterThanZero = reservationCost.getPriceWithVAT() > 0;
    boolean multiplePaymentMethods = allowedPaymentMethods.size() > 1;
    if (multiplePaymentMethods && priceGreaterThanZero && !paymentProxyOptional.isPresent()) {
        bindingResult.reject(ErrorsCode.STEP_2_MISSING_PAYMENT_METHOD);
    } else if (priceGreaterThanZero
            && (paymentProxy == PaymentProxy.STRIPE && StringUtils.isBlank(stripeToken))) {
        bindingResult.reject(ErrorsCode.STEP_2_MISSING_STRIPE_TOKEN);
    }//  ww w  .j a v a 2  s.  co m

    if (Objects.isNull(termAndConditionsAccepted) || !termAndConditionsAccepted) {
        bindingResult.reject(ErrorsCode.STEP_2_TERMS_NOT_ACCEPTED);
    }

    email = StringUtils.trim(email);

    fullName = StringUtils.trim(fullName);
    firstName = StringUtils.trim(firstName);
    lastName = StringUtils.trim(lastName);

    billingAddress = StringUtils.trim(billingAddress);

    ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "email", ErrorsCode.STEP_2_EMPTY_EMAIL);
    rejectIfOverLength(bindingResult, "email", ErrorsCode.STEP_2_MAX_LENGTH_EMAIL, email, 255);

    if (event.mustUseFirstAndLastName()) {
        ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "firstName",
                ErrorsCode.STEP_2_EMPTY_FIRSTNAME);
        rejectIfOverLength(bindingResult, "firstName", ErrorsCode.STEP_2_MAX_LENGTH_FIRSTNAME, fullName, 255);
        ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "lastName", ErrorsCode.STEP_2_EMPTY_LASTNAME);
        rejectIfOverLength(bindingResult, "lastName", ErrorsCode.STEP_2_MAX_LENGTH_LASTNAME, fullName, 255);
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "fullName", ErrorsCode.STEP_2_EMPTY_FULLNAME);
        rejectIfOverLength(bindingResult, "fullName", ErrorsCode.STEP_2_MAX_LENGTH_FULLNAME, fullName, 255);
    }

    rejectIfOverLength(bindingResult, "billingAddress", ErrorsCode.STEP_2_MAX_LENGTH_BILLING_ADDRESS,
            billingAddress, 450);

    if (email != null && !email.contains("@") && !bindingResult.hasFieldErrors("email")) {
        bindingResult.rejectValue("email", ErrorsCode.STEP_2_INVALID_EMAIL);
    }

    if (hasPaypalTokens() && !PaypalManager.isValidHMAC(new CustomerName(fullName, firstName, lastName, event),
            email, billingAddress, hmac, event)) {
        bindingResult.reject(ErrorsCode.STEP_2_INVALID_HMAC);
    }

    if (!postponeAssignment) {
        boolean success = Optional.ofNullable(tickets).filter(m -> !m.isEmpty()).map(m -> m.entrySet().stream()
                .map(e -> Validator.validateTicketAssignment(e.getValue(), fieldConf, Optional.empty(), event)))
                .filter(s -> s.allMatch(ValidationResult::isSuccess)).isPresent();
        if (!success) {
            bindingResult.reject(ErrorsCode.STEP_2_MISSING_ATTENDEE_DATA);
        }
    }
}

From source file:org.restheart.hal.metadata.singletons.JsonSchemaChecker.java

@Override
public boolean check(HttpServerExchange exchange, RequestContext context, BsonDocument contentToCheck,
        BsonValue args) {//ww  w.  j  a va  2  s  .  c  om
    Objects.requireNonNull(args, "missing metadata property 'args'");

    // cannot PUT an array
    if (args == null || !args.isDocument()) {
        ResponseHelper.endExchangeWithMessage(exchange, context, HttpStatus.SC_NOT_ACCEPTABLE,
                "args must be a json object");
        return false;
    }

    BsonDocument _args = args.asDocument();

    BsonValue _schemaStoreDb = _args.get(SCHEMA_STORE_DB_PROPERTY);
    String schemaStoreDb;

    BsonValue schemaId = _args.get(SCHEMA_ID_PROPERTY);

    Objects.requireNonNull(schemaId,
            "missing property '" + SCHEMA_ID_PROPERTY + "' in metadata property 'args'");

    if (_schemaStoreDb == null) {
        // if not specified assume the current db as the schema store db
        schemaStoreDb = context.getDBName();
    } else if (_schemaStoreDb.isString()) {
        schemaStoreDb = _schemaStoreDb.asString().getValue();
    } else {
        throw new IllegalArgumentException(
                "property " + SCHEMA_STORE_DB_PROPERTY + " in metadata 'args' must be a string");
    }

    try {
        URLUtils.checkId(schemaId);
    } catch (UnsupportedDocumentIdException ex) {
        throw new IllegalArgumentException("schema 'id' is not a valid id", ex);
    }

    Schema theschema;

    try {
        theschema = JsonSchemaCacheSingleton.getInstance().get(schemaStoreDb, schemaId);
    } catch (JsonSchemaNotFoundException ex) {
        context.addWarning(ex.getMessage());
        return false;
    }

    if (Objects.isNull(theschema)) {
        throw new IllegalArgumentException("cannot validate, schema " + schemaStoreDb + "/"
                + RequestContext._SCHEMAS + "/" + schemaId.toString() + " not found");
    }

    String _data = contentToCheck == null ? "{}" : contentToCheck.toJson();

    try {
        theschema.validate(new JSONObject(_data));
    } catch (JSONException je) {
        context.addWarning(je.getMessage());

        return false;
    } catch (ValidationException ve) {
        context.addWarning(ve.getMessage());
        ve.getCausingExceptions().stream().map(ValidationException::getMessage).forEach(context::addWarning);

        return false;
    }

    return true;
}

From source file:com.mac.holdempoker.app.impl.SimplePlayOrder.java

private int getPlayerOrder() {
    if (Objects.isNull(orderedPlayers)) {
        throw new NullPointerException("orderedPlayers is null");
    }/*from   ww  w  .ja  v a  2s. com*/
    System.out.println("Play Order: " + playOrder);
    return playOrder = (playOrder + 1) < orderedPlayers.size() ? playOrder++ : 0;
}