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:hudson.plugins.clearcase.history.AbstractHistoryAction.java

private String[] normalizeBranches(String[] branchNames) {
    if (ArrayUtils.isEmpty(branchNames)) {
        // If no branch was specified lshistory should be called
        // without branch filtering.
        // This solves [HUDSON-4800] and is required for [HUDSON-7218].
        branchNames = new String[] { StringUtils.EMPTY };
    }/*  ww  w .  j  ava 2s.  c  o m*/
    return branchNames;
}

From source file:net.shopxx.service.impl.MemberAttributeServiceImpl.java

@Transactional(readOnly = true)
public boolean isValid(MemberAttribute memberAttribute, String[] values) {
    Assert.notNull(memberAttribute);//  w w  w  .j a  v  a  2 s .c  o m
    Assert.notNull(memberAttribute.getType());

    String value = ArrayUtils.isNotEmpty(values) ? values[0].trim() : null;
    switch (memberAttribute.getType()) {
    case name:
    case address:
    case zipCode:
    case phone:
    case mobile:
    case text:
        if (memberAttribute.getIsRequired() && StringUtils.isEmpty(value)) {
            return false;
        }
        if (StringUtils.isNotEmpty(memberAttribute.getPattern()) && StringUtils.isNotEmpty(value)
                && !Pattern.compile(memberAttribute.getPattern()).matcher(value).matches()) {
            return false;
        }
        break;
    case gender:
        if (memberAttribute.getIsRequired() && StringUtils.isEmpty(value)) {
            return false;
        }
        if (StringUtils.isNotEmpty(value)) {
            try {
                Member.Gender.valueOf(value);
            } catch (IllegalArgumentException e) {
                return false;
            }
        }
        break;
    case birth:
        if (memberAttribute.getIsRequired() && StringUtils.isEmpty(value)) {
            return false;
        }
        if (StringUtils.isNotEmpty(value)) {
            try {
                DateUtils.parseDate(value, CommonAttributes.DATE_PATTERNS);
            } catch (ParseException e) {
                return false;
            }
        }
        break;
    case area:
        Long id = NumberUtils.toLong(value, -1L);
        Area area = areaDao.find(id);
        if (memberAttribute.getIsRequired() && area == null) {
            return false;
        }
        break;
    case select:
        if (memberAttribute.getIsRequired() && StringUtils.isEmpty(value)) {
            return false;
        }
        if (CollectionUtils.isEmpty(memberAttribute.getOptions())) {
            return false;
        }
        if (StringUtils.isNotEmpty(value) && !memberAttribute.getOptions().contains(value)) {
            return false;
        }
        break;
    case checkbox:
        if (memberAttribute.getIsRequired() && ArrayUtils.isEmpty(values)) {
            return false;
        }
        if (CollectionUtils.isEmpty(memberAttribute.getOptions())) {
            return false;
        }
        if (ArrayUtils.isNotEmpty(values) && !memberAttribute.getOptions().containsAll(Arrays.asList(values))) {
            return false;
        }
        break;
    }
    return true;
}

From source file:de.codesourcery.eve.skills.datamodel.IndustryJob.java

public boolean hasJobStatus(ISystemClock clock, JobStatus... states) {
    if (ArrayUtils.isEmpty(states)) {
        throw new IllegalArgumentException("NULL/empty states array ?");
    }/*  ww w  .  ja v  a 2s .  c  om*/

    for (JobStatus s : states) {
        if (getJobStatus(clock) == s) {
            return true;
        }
    }
    return false;
}

From source file:com.abiquo.server.core.enterprise.UserDAO.java

private Criteria createCriteria(final Enterprise enterprise, final Role role, final String[] filters,
        final String orderBy, final boolean desc, final boolean connected) {
    Criteria criteria = createCriteria();

    if (enterprise != null) {
        criteria.add(sameEnterprise(enterprise));
    }/*  w w w.  j av a 2 s. c o m*/

    if (role != null) {
        criteria.add(sameRole(role));
    }
    if (!ArrayUtils.isEmpty(filters)) {
        for (String filter : filters) {
            if (!StringUtils.isEmpty(filter)) {
                criteria.add(filterBy(filter));
            }
        }
    }

    if (!StringUtils.isEmpty(orderBy)) {
        Order order = Order.asc(orderBy);
        if (desc) {
            order = Order.desc(orderBy);
        }
        criteria.addOrder(order);
    }

    if (connected) {
        criteria.createCriteria("sessions").add(Restrictions.gt("expireDate", new Date()));
        criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    }
    return criteria;
}

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

public BigDecimal getAuthorizedViolationAmount() {
    BigDecimal total = new BigDecimal(0.0);
    if (!ArrayUtils.isEmpty(violations)) {
        for (int i = 0; i < violations.length; i++) {
            if (violations[i].isAuthorized()) {
                total = total.add(violations[i].getCashAmount());
            }/*from   w w  w  .ja v  a 2  s.c  o m*/
        }
    }
    return total;
}

From source file:com.codeabovelab.dm.cluman.job.AbstractJobInstance.java

/**
 * Send message into job log which formatted as {@link MessageFormat#format(String, Object...)}
 * @param message message with//from ww  w .  jav a2s.  co m
 * @param args objects, also first find throwable will be extracted and passed into event as {@link JobEvent#getException()}
 */
@Override
public void send(String message, Object... args) {
    Throwable throwable = null;
    if (!ArrayUtils.isEmpty(args)) {
        //find and extract throwable
        for (int i = 0; i < args.length; i++) {
            Object arg = args[i];
            if (arg instanceof Throwable) {
                throwable = (Throwable) arg;
                args = ArrayUtils.remove(args, i);
                break;
            }
        }
        if (message != null) {
            try {
                message = MessageFormat.format(message, args);
            } catch (Exception e) {
                LOG.error("Cannot format message: \"{}\"", message, e);
            }
        }
    }
    sendEvent(new JobEvent(getInfo(), message, throwable));
}

From source file:com.lyh.licenseworkflow.dao.EnhancedHibernateDaoSupport.java

/**
 * ????????//from  w  w  w.  j a v  a  2 s  .  c  o  m
 *
 * @param selectedProps ???
 * @param conditionKeys where???
 * @param values        where???
 * @return ????
 */
@SuppressWarnings("unchecked")
public List<?> getEntityProperties(final String[] selectedProps, final String[] conditionKeys,
        final Object[] values) {
    if (ArrayUtils.isEmpty(selectedProps) || (!ArrayUtils.isEmpty(conditionKeys) && !ArrayUtils.isEmpty(values)
            && conditionKeys.length != values.length)) {
        throw new IllegalArgumentException("Invalid arguments to execute sql query.");
    }
    StringBuilder sql = new StringBuilder("select ");
    for (int i = 0, n = selectedProps.length; i < n; i++) {
        if (i != n - 1)
            sql.append(selectedProps[i] + ",");
        else
            sql.append(selectedProps[i] + " from ");
    }
    if (conditionKeys == null) {
        sql.append(getEntityName());
    } else {
        sql.append(getEntityName() + " where ");
        for (int i = 0, n = conditionKeys.length; i < n; i++) {
            if (i != n - 1) {
                sql.append(conditionKeys[i]);
                sql.append(" = ? and ");
            } else {
                sql.append(conditionKeys[i]);
                sql.append(" = ?");
            }
        }
    }
    return getHibernateTemplate().find(sql.toString(), values);
}

From source file:ml.shifu.shifu.core.ConfusionMatrix.java

public ConfusionMatrix(ModelConfig modelConfig, List<ColumnConfig> columnConfigList, EvalConfig evalConfig,
        Object source) throws IOException {
    this.modelConfig = modelConfig;
    this.evalConfig = evalConfig;
    this.pathFinder = new PathFinder(modelConfig);
    this.lock = source;
    this.columnConfigList = columnConfigList;

    this.delimiter = Environment.getProperty(Constants.SHIFU_OUTPUT_DATA_DELIMITER,
            Constants.DEFAULT_DELIMITER);

    String[] evalScoreHeader = getEvalScoreHeader();
    if (ArrayUtils.isEmpty(evalScoreHeader)) {
        throw new ShifuException(ShifuErrorCode.ERROR_EVAL_NO_EVALSCORE_HEADER);
    }//from   w w  w. j ava  2s .c om

    if (StringUtils.isEmpty(evalConfig.getPerformanceScoreSelector())) {
        throw new ShifuException(ShifuErrorCode.ERROR_EVAL_SELECTOR_EMPTY);
    }

    if (modelConfig.isRegression()) {
        scoreColumnIndex = getColumnIndex(evalScoreHeader,
                StringUtils.trimToEmpty(evalConfig.getPerformanceScoreSelector()));
        if (scoreColumnIndex < 0) {
            // the score column is not found in the header of EvalScore
            throw new ShifuException(ShifuErrorCode.ERROR_EVAL_SELECTOR_EMPTY);
        }
    }

    targetColumnIndex = getColumnIndex(evalScoreHeader,
            StringUtils.trimToEmpty(modelConfig.getTargetColumnName(evalConfig)));
    if (targetColumnIndex < 0) {
        // the target column is not found in the header of EvalScore
        throw new ShifuException(ShifuErrorCode.ERROR_EVAL_TARGET_NOT_FOUND);
    }

    weightColumnIndex = getColumnIndex(evalScoreHeader,
            StringUtils.trimToEmpty(evalConfig.getDataSet().getWeightColumnName()));

    // only works for multi classification
    multiClassScore1Index = targetColumnIndex + 2; // target, weight, score1, score2, this is hard code
    try {
        multiClassModelCnt = ModelSpecLoaderUtils.getBasicModelsCnt(modelConfig, evalConfig,
                evalConfig.getDataSet().getSource());
    } catch (FileNotFoundException e) {
        multiClassModelCnt = 0;
    }

    if (modelConfig.isClassification()) {
        if (modelConfig.getTrain().isOneVsAll()) {
            if (modelConfig.getTags().size() == 2) {
                // onevsall, modelcnt is 1
                multiClassModelCnt = 1;
            } else {
                multiClassModelCnt = modelConfig.getTags().size();
            }
        } else {
            multiClassModelCnt = 1;
        }
    }

    // Number of meta columns
    metaColumns = evalConfig.getAllMetaColumns(modelConfig).size();

    posTags = new HashSet<String>(modelConfig.getPosTags(evalConfig));
    negTags = new HashSet<String>(modelConfig.getNegTags(evalConfig));

    scoreScale = Double.parseDouble(
            Environment.getProperty(Constants.SHIFU_SCORE_SCALE, Integer.toString(Scorer.DEFAULT_SCORE_SCALE)));
}

From source file:com.dianping.wed.cache.redis.biz.WeddingRedisKeyConfigurationServiceImpl.java

@Override
public String syncCfg(String... categories) {
    try {//from  www .  j ava 2  s. co m
        String resultMsg = "";
        if (ArrayUtils.isEmpty(categories)) {
            resultMsg = "categories cannot be empty or null";
        } else if ("all".equals(categories[0])) {
            //TODO
            resultMsg = "operation unsupported now";
        } else {
            for (final String category : categories) {
                WeddingRedisKeyConfigurationDTO configurationDTO = this.loadRedisKeyCfgByCategory(category);
                if (configurationDTO == null) {
                    resultMsg += "category:" + category + "??";
                    JedisHelper.doJedisOperation(new JedisCallback<Long>() {
                        @Override
                        public Long doWithJedis(Jedis jedis) {
                            return jedis.hdel(REDIS__KEY_CONFIGURATION, category);
                        }
                    }, REDIS__KEY_CONFIGURATION, RedisActionType.WRITE);
                    continue;
                }
                final String cfgString = JSON.toJSONString(configurationDTO);
                JedisHelper.doJedisOperation(new JedisCallback<Long>() {
                    @Override
                    public Long doWithJedis(Jedis jedis) {
                        return jedis.hset(REDIS__KEY_CONFIGURATION, category, cfgString);
                    }
                }, REDIS__KEY_CONFIGURATION, RedisActionType.WRITE);
            }
        }
        //   key??
        if (StringUtils.isNotEmpty(resultMsg)) {
            return resultMsg;
        }

    } catch (Exception e) {
        logger.error(e);
        Cat.logError(e);
        return e.getMessage();
    }
    return "OK";
}

From source file:gov.nih.nci.caarray.domain.MultiPartBlob.java

/**
 * Writes data to the blob. If writeAll is false, this method only writes out data that fills the max blob size. Any
 * remaining unwritten data is returned.
 * //  w w w.ja  v  a 2  s  .co  m
 * @param data the data to write the blob
 * @param writeAll whether to write out all the data
 * @param blobPartSize the maximum size of a single blob
 * @return array of any unwritten data
 */
private byte[] writeData(byte[] data, int blobPartSize, boolean writeAll) {
    if (data == null) {
        return new byte[0];
    }
    int index = 0;
    while (data.length - index >= blobPartSize) {
        addBlob(ArrayUtils.subarray(data, index, index + blobPartSize));
        index += blobPartSize;
    }
    final byte[] unwritten = ArrayUtils.subarray(data, index, data.length);
    if (writeAll && !ArrayUtils.isEmpty(unwritten)) {
        addBlob(unwritten);
        return new byte[0];
    } else {
        return unwritten;
    }
}