Example usage for org.apache.commons.lang ArrayUtils isEmpty

List of usage examples for org.apache.commons.lang ArrayUtils isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils isEmpty.

Prototype

public static boolean isEmpty(boolean[] array) 

Source Link

Document

Checks if an array of primitive booleans is empty or null.

Usage

From source file:cn.fastmc.core.utils.ReflectionUtils.java

/**
 * ?field?annotationClass//  ww  w . java2 s . c  om
 * 
 * @param fields
 *            field
 * @param annotationClass
 *            annotationClass
 * 
 * @return List
 */
public static <T extends Annotation> List<T> getAnnotations(Field[] fields, Class annotationClass) {

    if (ArrayUtils.isEmpty(fields)) {
        return null;
    }

    List<T> result = new ArrayList<T>();

    for (Field field : fields) {
        field.setAccessible(true);
        Annotation annotation = getAnnotation(field, annotationClass);
        if (annotation != null) {
            result.add((T) annotation);
        }
    }

    return result;
}

From source file:kina.config.GenericCassandraKinaConfig.java

private void validateTableMetadata(TableMetadata tableMetadata) {

    if (tableMetadata == null && !isWriteConfig) {
        throw new IllegalArgumentException(
                String.format("Column family {%s.%s} does not exist", keyspace, columnFamily));
    }//ww w .j  av a  2  s  . c  o m

    if (tableMetadata == null && !createTableOnWrite) {
        throw new IllegalArgumentException(
                String.format("Column family {%s.%s} does not exist and " + "createTableOnWrite = false",
                        keyspace, columnFamily));
    }

    if (!ArrayUtils.isEmpty(inputColumns)) {
        for (String column : inputColumns) {
            assert tableMetadata != null;
            ColumnMetadata columnMetadata = tableMetadata.getColumn(column);

            if (columnMetadata == null) {
                throw new NoSuchFieldException("No column with name " + column + " has been found on table "
                        + this.keyspace + "." + this.columnFamily);
            }
        }
    }

}

From source file:com.vmware.bdd.specpolicy.ClusterSpecFactory.java

/**
 * There are two approach to create a cluster: 1) specify a cluster type and
 * optionally overwriting the parameters 2) specify a customized spec with
 * cluster type not specified//from  w  w  w . j ava  2s  .c o m
 * 
 * @param spec
 *           spec with customized field
 * @return customized cluster spec
 * @throws FileNotFoundException
 */
public static ClusterCreate getCustomizedSpec(ClusterCreate spec, String appManagerType)
        throws FileNotFoundException {

    if (!ArrayUtils.isEmpty(spec.getNodeGroups())) {
        spec.setSpecFile(true);
    }
    if (spec.isSpecFile()) {
        return spec;
    }

    ClusterCreate newSpec = createDefaultSpec(spec.getType(), spec.getDistroVendor(), spec.getDistroVersion(),
            appManagerType);

    // --name
    if (spec.getName() != null) {
        newSpec.setName(spec.getName());
    }

    //--password
    newSpec.setPassword(spec.getPassword());

    // --appManager
    if (!CommonUtil.isBlank(spec.getAppManager())) {
        newSpec.setAppManager(spec.getAppManager());
    }

    // --locaRepoURL
    if (!CommonUtil.isBlank(spec.getLocalRepoURL())) {
        newSpec.setLocalRepoURL(spec.getLocalRepoURL());
    }

    // --distro
    if (spec.getDistro() != null) {
        newSpec.setDistro(spec.getDistro());
    }

    //vendor
    if (spec.getDistroVendor() != null) {
        newSpec.setDistroVendor(spec.getDistroVendor());
    }

    //version
    if (spec.getDistroVersion() != null) {
        newSpec.setDistroVersion(spec.getDistroVersion());
    }

    // template name
    if (spec.getTemplateName() != null) {
        newSpec.setTemplateName(spec.getTemplateName());
    }

    // --dsNames
    if (spec.getDsNames() != null) {
        newSpec.setDsNames(spec.getDsNames());
    }

    // --rpNames
    if (spec.getRpNames() != null) {
        newSpec.setRpNames(spec.getRpNames());
    }

    // --networkConfig
    if (spec.getNetworkConfig() != null) {
        newSpec.setNetworkConfig(spec.getNetworkConfig());
    }

    // --topology
    if (spec.getTopologyPolicy() != null) {
        newSpec.setTopologyPolicy(spec.getTopologyPolicy());
    }

    if (MapUtils.isNotEmpty(spec.getInfrastructure_config())) {
        newSpec.setInfrastructure_config(spec.getInfrastructure_config());
    }

    return newSpec;
}

From source file:com.etcc.csc.presentation.datatype.PaymentContext.java

public BigDecimal getFirstInvTotalFNAdminFee() {
    BigDecimal amount = BigDecimal.ZERO;
    if (!ArrayUtils.isEmpty(firstInvs)) {
        for (int i = 0; i < firstInvs.length; i++) {
            if ("N".equals(firstInvs[i].getPaidIndicator())) {
                amount = amount.add(BigDecimalUtil.nullSafe(firstInvs[i].getInvoiceAdminFee()));
            }/*from ww  w  . ja va  2s . com*/
        }
    }
    return amount;
}

From source file:edu.cornell.med.icb.goby.modes.CompactToFastaMode.java

@Override
public void execute() throws IOException {
    // output file extension is based on the output format type
    final String outputExtension = "." + outputFormat.name().toLowerCase(Locale.getDefault());
    if (outputFilename == null) {
        outputFilename = FilenameUtils.removeExtension(inputFilename) + (hashOutputFilename ? hash() : "")
                + outputExtension;//from ww  w .ja va  2 s  .com
    } else if (hashOutputFilename) {
        outputFilename = FilenameUtils.removeExtension(outputFilename) + (hashOutputFilename ? hash() : "")
                + outputExtension;
    }

    ReadSet readIndexFilter = new ReadSet();
    if (readIndexFilterFile == null) {
        readIndexFilter = null;
    } else {
        readIndexFilter.load(readIndexFilterFile);
    }

    final ProgressLogger progress = new ProgressLogger();
    progress.start();
    progress.displayFreeMemory = true;

    // Only sanger and illumina encoding are supported at this time
    if (qualityEncoding == QualityEncoding.SOLEXA) {
        throw new UnsupportedOperationException(
                "SOLEXA encoding is not supported " + "at this time for lack of clear documentation.");
    } else if (qualityEncoding != QualityEncoding.SANGER && qualityEncoding != QualityEncoding.ILLUMINA) {
        throw new UnsupportedOperationException("Unknown encoding: " + qualityEncoding);
    }

    ReadsReader reader = null;
    Writer writer = null;
    OutputStreamWriter pairWriter = null;
    final int newEntryCharacter;
    switch (outputFormat) {
    case FASTQ:
        newEntryCharacter = '@';
        break;
    case FASTA:
    default:
        newEntryCharacter = '>';
        break;
    }
    try {
        writer = new OutputStreamWriter(new FastBufferedOutputStream(new FileOutputStream(outputFilename)));
        pairWriter = processPairs
                ? new OutputStreamWriter(new FastBufferedOutputStream(new FileOutputStream(outputPairFilename)))
                : null;

        final MutableString colorSpaceBuffer = new MutableString();
        final MutableString sequence = new MutableString();
        final MutableString sequencePair = new MutableString();

        if (hasStartOrEndPosition) {
            reader = new ReadsReader(startPosition, endPosition, inputFilename);
        } else {
            reader = new ReadsReader(inputFilename);
        }

        for (final Reads.ReadEntry readEntry : reader) {
            if (readIndexFilter == null || readIndexFilter.contains(readEntry.getReadIndex())) {
                final String description;

                if (indexToHeader) {
                    description = Integer.toString(readEntry.getReadIndex());
                } else if (identifierToHeader && readEntry.hasReadIdentifier()) {
                    description = readEntry.getReadIdentifier();
                } else if (readEntry.hasDescription()) {
                    description = readEntry.getDescription();
                } else {
                    description = Integer.toString(readEntry.getReadIndex());
                }

                writer.write(newEntryCharacter);
                writer.write(description);
                writer.write('\n');
                final boolean processPairInThisRead = processPairs && readEntry.hasSequencePair();
                if (processPairInThisRead) {
                    pairWriter.write(newEntryCharacter);
                    pairWriter.write(description);
                    pairWriter.write('\n');
                }
                observeReadIndex(readEntry.getReadIndex());
                ReadsReader.decodeSequence(readEntry, sequence);

                if (processPairInThisRead) {
                    ReadsReader.decodeSequence(readEntry, sequencePair, true);
                }

                if (queryLengths != null) {
                    queryLengths.put(readEntry.getReadIndex(), sequence.length());
                }

                MutableString transformedSequence = sequence;
                MutableString transformedSequencePair = sequencePair;
                if (outputColorMode) {
                    ColorSpaceConverter.convert(transformedSequence, colorSpaceBuffer, referenceConversion);
                    transformedSequence = colorSpaceBuffer;
                    if (processPairInThisRead) {
                        ColorSpaceConverter.convert(transformedSequencePair, colorSpaceBuffer,
                                referenceConversion);
                        transformedSequencePair = colorSpaceBuffer;
                    }
                }
                if (outputFakeNtMode) {
                    for (int i = 0; i < transformedSequence.length(); i++) {
                        transformedSequence.charAt(i, getFakeNtCharacter(transformedSequence.charAt(i)));
                    }
                    if (processPairInThisRead) {
                        for (int i = 0; i < transformedSequencePair.length(); i++) {
                            transformedSequencePair.charAt(i,
                                    getFakeNtCharacter(transformedSequencePair.charAt(i)));
                        }
                    }
                }
                if (trimAdaptorLength > 0) {
                    transformedSequence = transformedSequence.substring(trimAdaptorLength);
                    if (processPairInThisRead) {
                        transformedSequencePair = transformedSequencePair.substring(trimAdaptorLength);
                    }
                }
                // filter unrecognized bases from output
                if (alphabet != null) {
                    for (int i = 0; i < transformedSequence.length(); i++) {
                        if (alphabet.indexOf(transformedSequence.charAt(i)) == -1) {
                            transformedSequence.charAt(i, 'N');
                        }
                    }
                }
                if (processPairInThisRead) {
                    if (alphabet != null) {

                        for (int i = 0; i < transformedSequencePair.length(); i++) {
                            if (alphabet.indexOf(transformedSequencePair.charAt(i)) == -1) {
                                transformedSequencePair.charAt(i, 'N');
                            }
                        }
                    }
                }
                writeSequence(writer, transformedSequence, fastaLineLength);
                if (processPairInThisRead) {
                    writeSequence(pairWriter, transformedSequencePair, fastaLineLength);
                }
                if (outputFormat == OutputFormat.FASTQ) {
                    final int readLength = transformedSequence.length();
                    final byte[] qualityScores = readEntry.getQualityScores().toByteArray();
                    final boolean hasQualityScores = readEntry.hasQualityScores()
                            && !ArrayUtils.isEmpty(qualityScores);
                    writeQualityScores(writer, hasQualityScores, qualityScores, outputFakeQualityMode,
                            readLength);

                    if (processPairInThisRead) {
                        final int readLengthPair = transformedSequencePair.length();
                        final byte[] qualityScoresPair = readEntry.getQualityScoresPair().toByteArray();
                        final boolean hasPairQualityScores = readEntry.hasQualityScoresPair()
                                && !ArrayUtils.isEmpty(qualityScoresPair);
                        writeQualityScores(pairWriter, hasPairQualityScores, qualityScoresPair,
                                outputFakeQualityMode, readLengthPair);

                    }
                }
                ++numberOfFilteredSequences;

                progress.lightUpdate();
                ++numberOfSequences;
            }

        }
    } finally {
        IOUtils.closeQuietly(writer);
        if (processPairs) {
            IOUtils.closeQuietly(pairWriter);
        }
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) { // NOPMD
                // silently ignore
            }
        }
    }

    progress.stop();
}

From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java

/**
 * Loads the classes with the given full-qualified names using the provided {@link ClassLoader}.<br/>
 * This method is the inverse of {@link #getNamesFromClasses(Class[])}.
 * <p/>/* w  w  w  .j a v  a2s .  c o m*/
 * Note that unknown parameter types i.e., {@code "null"} are handled gracefully. Instead of throwing an exception,
 * they are resolved to {@code null} instead. This allows the caller to predict the type e.g., by comparing them
 * with method or constructor signatures.
 * 
 * @param names the names of the classes to load
 * @param classLoader the class loader to use
 * @return a non-null array of the classes loaded
 * @throws ClassNotFoundException if a class cannot be located by the specified class loader
 */
public static Class<?>[] getClassesFromNames(String[] names, ClassLoader classLoader)
        throws ClassNotFoundException {
    if (ArrayUtils.isEmpty(names)) {
        return ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    Class<?>[] classes = new Class<?>[names.length];
    for (int i = 0; i < names.length; i++) {
        if (names[i] == null) {
            // If there is no name, skip the determination and assume that the caller is able to predict it
            classes[i] = null;
        } else if (isPrimitive(names[i])) {
            classes[i] = getPrimitiveType(names[i]);
        } else {
            classes[i] = Class.forName(names[i], true, classLoader);
        }
    }
    return classes;
}

From source file:com.nec.harvest.service.impl.InventoryServiceImpl.java

/** {@inheritDoc} */
@Override//  ww  w.  j  a v  a  2s.c  o  m
public double calculateInventoryByOrgCodesAndMonth(String month, String... orgCodes) throws ServiceException {
    if (ArrayUtils.isEmpty(orgCodes)) {
        throw new IllegalArgumentException(
                "Calculation inventory price cannot implement with organization code null");
    }
    if (StringUtils.isEmpty(month)) {
        throw new IllegalArgumentException(
                "Calculation inventory amount cannot implement with current month null");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    double amountOfInventory = 0;
    try {
        tx = session.beginTransaction();
        StringBuffer sql = new StringBuffer(" SELECT TRUNCATE(SUM(Kingaku)/1000, 0) ");
        sql.append(" FROM " + TblConstants.TBL_INVENTORY);
        sql.append(" WHERE StrCode IN (:orgCodes) AND GetSudo=:month AND DelKbn=2");

        Query query = repository.getSQLQuery(session, sql.toString());
        query.setParameterList("orgCodes", orgCodes);
        query.setString("month", month);

        Object amount = query.uniqueResult();
        // Release transaction
        tx.commit();
        if (amount == null) {
            throw new ObjectNotFoundException(
                    "Could not find any object in monthly " + month + " for the organization " + orgCodes);
        }
        amountOfInventory = Double.valueOf(amount.toString());
    } catch (SQLGrammarException | GenericJDBCException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException(
                "Runtime exception occur when calculate inventory price for multi-organization in a month");
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return amountOfInventory;
}

From source file:com.etcc.csc.presentation.datatype.PaymentContext.java

public BigDecimal getFirstInvTotalSNAdminFee() {
    BigDecimal amount = BigDecimal.ZERO;
    if (!ArrayUtils.isEmpty(firstInvs)) {
        for (int i = 0; i < firstInvs.length; i++) {
            if ("N".equals(firstInvs[i].getPaidIndicator())) {
                amount = amount.add(BigDecimalUtil.nullSafe(firstInvs[i].getInvSecondNoticeAdminFee()));
            }/*w  ww. j  a v  a2 s  .com*/
        }
    }
    return amount;
}

From source file:com.etcc.csc.datatype.PaymentDetailUtil.java

public static OLC_VPS_UNINV_FEE_PMT_REC[] violationsToOLC_VPS_UNINV_FEE_PMT_RECs(Violation[] violations)
        throws Exception {
    if (ArrayUtils.isEmpty(violations)) {
        return null;
    }//from  w  w w  .  j  a  v a  2 s  .  c  o  m

    OLC_VPS_UNINV_FEE_PMT_REC[] OLC_VPS_UNINV_FEE_PMT_RECs = new OLC_VPS_UNINV_FEE_PMT_REC[violations.length];
    for (int i = 0; i < violations.length; i++) {
        OLC_VPS_UNINV_FEE_PMT_REC rec = violationToOLC_VPS_UNINV_FEE_PMT_REC(violations[i]);
        rec.setARR_INDEX(new BigDecimal(i + 1));
        OLC_VPS_UNINV_FEE_PMT_RECs[i] = rec;
    }
    return OLC_VPS_UNINV_FEE_PMT_RECs;
}

From source file:com.photon.phresco.framework.actions.applications.Configurations.java

private boolean validate(ProjectAdministrator administrator, String fromPage) throws PhrescoException {
    if (debugEnabled) {
        S_LOGGER.debug(/*w w w .j a  v  a  2 s .  c o  m*/
                "Entering Method  Configurations.validate(ProjectAdministrator administrator, String fromPage)");
        S_LOGGER.debug("validate() Frompage = " + fromPage);
    }
    boolean validate = true;
    String[] environments = getHttpRequest().getParameterValues(ENVIRONMENTS);

    if (StringUtils.isEmpty(configType)) {
        setTypeError(getText(NO_CONFIG_TYPE));
        return false;
    }

    if (StringUtils.isEmpty(configName.trim())) {
        setNameError(ERROR_NAME);
        validate = false;
    }

    if (ArrayUtils.isEmpty(environments)) {
        setEnvError(ERROR_ENV);
        return false;
    }

    Project project = administrator.getProject(projectCode);
    if (StringUtils.isNotEmpty(configName) && !configName.equals(oldName)) {
        for (String environment : environments) {
            List<SettingsInfo> configurations = administrator.configurationsByEnvName(environment, project);
            for (SettingsInfo configuration : configurations) {
                if (configName.trim().equalsIgnoreCase(configuration.getName())) {
                    setNameError(ERROR_DUPLICATE_NAME);
                    validate = false;
                }
            }
        }
    }

    if (StringUtils.isEmpty(fromPage)
            || (StringUtils.isNotEmpty(fromPage) && !configType.equals(oldConfigType))) {
        if (configType.equals(Constants.SETTINGS_TEMPLATE_SERVER)
                || configType.equals(Constants.SETTINGS_TEMPLATE_EMAIL)) {
            for (String env : environments) {
                List<SettingsInfo> settingsinfos = administrator.configurations(project, env, configType,
                        oldName);
                if (CollectionUtils.isNotEmpty(settingsinfos)) {
                    setTypeError(CONFIG_ALREADY_EXIST);
                    validate = false;
                }
            }
        }
    }

    SettingsTemplate selectedSettingTemplate = administrator.getSettingsTemplate(configType);

    boolean serverTypeValidation = false;
    for (PropertyTemplate propertyTemplate : selectedSettingTemplate.getProperties()) {
        String key = null;
        String value = null;
        if (propertyTemplate.getKey().equals("Server") || propertyTemplate.getKey().equals("Database")) {
            List<PropertyTemplate> compPropertyTemplates = propertyTemplate.getpropertyTemplates();
            for (PropertyTemplate compPropertyTemplate : compPropertyTemplates) {
                key = compPropertyTemplate.getKey();
                value = getHttpRequest().getParameter(key);
                //If nodeJs server selected , there should not be valition for deploy dir.
                if ("type".equals(key) && "NodeJS".equals(value)) {
                    serverTypeValidation = true;
                }
            }
        } else {
            key = propertyTemplate.getKey();
        }
        value = getHttpRequest().getParameter(key);
        boolean isRequired = propertyTemplate.isRequired();
        String techId = project.getProjectInfo().getTechnology().getId();
        if (serverTypeValidation && "deploy_dir".equals(key) || TechnologyTypes.ANDROIDS.contains(techId)) {
            isRequired = false;
        }
        // validation for UserName & Password for RemoteDeployment
        boolean remoteDeply = Boolean.parseBoolean(remoteDeployment);
        if (remoteDeply) {
            if ("admin_username".equals(key) || "admin_password".equals(key)) {
                isRequired = true;
            }
            if ("deploy_dir".equals(key)) {
                isRequired = false;
            }
        }

        if (isRequired == true && StringUtils.isEmpty(value.trim())) {
            I18NString i18NString = propertyTemplate.getName();
            String field = i18NString.get("en-US").getValue();
            dynamicError += propertyTemplate.getKey() + ":" + field + " is empty" + ",";
        }
    }

    if (StringUtils.isNotEmpty(dynamicError)) {
        dynamicError = dynamicError.substring(0, dynamicError.length() - 1);
        setDynamicError(dynamicError);
        validate = false;
    }

    if (StringUtils.isNotEmpty(getHttpRequest().getParameter("port"))) {
        int value = Integer.parseInt(getHttpRequest().getParameter("port"));
        if (validate && (value < 1 || value > 65535)) {
            setPortError(ERROR_PORT);
            validate = false;
        }
    }

    if (StringUtils.isNotEmpty(getHttpRequest().getParameter("emailid"))) {
        String value = getHttpRequest().getParameter("emailid");
        Pattern p = Pattern.compile("[a-zA-Z]*[0-9]*@[a-zA-Z]*.[a-zA-Z]*");
        Matcher m = p.matcher(value);
        boolean b = m.matches();
        if (b == false) {
            setEmailError(ERROR_EMAIL);
            validate = false;
        }
    }

    return validate;
}