Example usage for org.apache.commons.lang Validate notEmpty

List of usage examples for org.apache.commons.lang Validate notEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang Validate notEmpty.

Prototype

public static void notEmpty(String string, String message) 

Source Link

Document

Validate an argument, throwing IllegalArgumentException if the argument String is empty (null or zero length).

 Validate.notEmpty(myString, "The string must not be empty"); 

Usage

From source file:io.cloudslang.engine.partitions.services.PartitionServiceImpl.java

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public boolean rollPartitions(String groupName) {
    Validate.notEmpty(groupName, "Group name is empty or null");

    Validate.isTrue(repository.lock(groupName) == 1, "Unknown partition group [" + groupName + "]");

    // the partition group cannot be null since it is locked in the database
    PartitionGroup partitionGroup = repository.findByName(groupName);
    if (!shouldBeRolled(partitionGroup)) {
        return false;
    }//from   w  w  w. j a va 2  s  .c  o m

    if (logger.isDebugEnabled())
        logger.debug("Rolling partition group [" + groupName + "]");
    long t = System.currentTimeMillis();

    // increment the active partition
    partitionGroup.setActivePartition(
            partitionUtils.partitionAfter(partitionGroup.getActivePartition(), partitionGroup.getGroupSize()))
            .setLastRollTime(System.currentTimeMillis());

    // truncate next partition
    jdbcTemplate.execute(SQL("truncate table " + table(partitionGroup)));

    if (logger.isDebugEnabled()) {
        logger.debug("Group [" + groupName + "]: active partition is " + partitionGroup.getActivePartition()
                + " (rolled in " + (System.currentTimeMillis() - t) + " ms)");
    }

    return true;
}

From source file:net.jadler.KeyValues.java

/**
 * Returns all values for the given key//from ww w. j  a  v a  2s. c om
 * @param key key (case insensitive)
 * @return all values of the given header or {@code null}, if there is no such a key in this instance
 */
public List<String> getValues(final String key) {
    Validate.notEmpty(key, "name cannot be empty");

    @SuppressWarnings("unchecked")
    final List<String> result = (List<String>) values.get(key.toLowerCase());
    return result == null || result.isEmpty() ? null : new ArrayList<String>(result);
}

From source file:it.gualtierotesta.gdocx.GTc.java

/**
 * Set cell width/*  w  ww  .  j a  v  a 2 s . co m*/
 *
 * @param lWidth width value (should be greater than 0)
 * @param sType type (unit) of the value (for ex. "dxa")
 * @return same GTc instance
 */
@Nonnull
public GTc width(final long lWidth, @Nonnull final String sType) {

    Validate.isTrue(0L < lWidth, "Width value not valid");
    Validate.notEmpty(sType, "Type not valid");

    final TblWidth cellWidth = FACTORY.createTblWidth();
    cellWidth.setType(sType);
    cellWidth.setW(BigInteger.valueOf(lWidth));
    tcPr.setTcW(cellWidth);
    return this;
}

From source file:edu.snu.leader.spatial.calculator.DefaultGautraisDecisionProbabilityCalculator.java

/**
 * Initializes the calculator//from   w  w  w.j  av a  2 s .  co m
 *
 * @param simState The simulation's state
 * @see edu.snu.leader.spatial.DecisionProbabilityCalculator#initialize(edu.snu.leader.spatial.SimulationState)
 */
@Override
public void initialize(SimulationState simState) {
    _LOG.trace("Entering initialize( simState )");

    // Save the simulation state
    _simState = simState;

    // Use hard-coded values from the paper
    _initRateBase = 1290.0f;
    _followAlpha = 162.3f;
    _followBeta = 75.4f;
    _cancelAlpha = 0.009f;
    _cancelGamma = 2.0f;
    _cancelEpsilon = 2.3f;

    // Get the properties
    Properties props = simState.getProperties();

    // Get the initiation rate modification flag
    String modifyInitiationRateStr = props.getProperty(_MODIFY_INITIATION_RATE_KEY);
    Validate.notEmpty(modifyInitiationRateStr,
            "Modify initation rate (key=" + _MODIFY_INITIATION_RATE_KEY + ") may not be empty");
    _modifyInitiationRate = Boolean.parseBoolean(modifyInitiationRateStr);
    _LOG.info("Using _modifyInitiationRate=[" + _modifyInitiationRate + "]");

    // Get the following rate modification flag
    String modifyFollowingRateStr = props.getProperty(_MODIFY_FOLLOWING_RATE_KEY);
    Validate.notEmpty(modifyFollowingRateStr,
            "Modify following rate (key=" + _MODIFY_FOLLOWING_RATE_KEY + ") may not be empty");
    _modifyFollowingRate = Boolean.parseBoolean(modifyFollowingRateStr);
    _LOG.info("Using _modifyFollowingRate=[" + _modifyFollowingRate + "]");

    // Get the cancellation rate modification flag
    String modifyCancellationRateStr = props.getProperty(_MODIFY_CANCELLATION_RATE_KEY);
    Validate.notEmpty(modifyCancellationRateStr,
            "Modify cancellation rate (key=" + _MODIFY_CANCELLATION_RATE_KEY + ") may not be empty");
    _modifyCancellationRate = Boolean.parseBoolean(modifyCancellationRateStr);
    _LOG.info("Using _modifyCancellationRate=[" + _modifyCancellationRate + "]");

    _LOG.trace("Leaving initialize( simState )");
}

From source file:ch.algotrader.dao.PositionDaoImpl.java

@Override
public List<Position> findOpenPositionsByStrategy(String strategyName) {

    Validate.notEmpty(strategyName, "Strategy name is empty");

    return findCaching("Position.findOpenPositionsByStrategy", QueryType.BY_NAME,
            new NamedParam("strategyName", strategyName));
}

From source file:com.manpowergroup.cn.core.utils.Reflections.java

/**
 * ?, ?DeclaredField, ?.//www. j ava  2 s  .  com
 * 
 * ?Object?, null.
 */
public static Field getAccessibleField(final Object obj, final String fieldName) {
    Validate.notNull(obj, "object can't be null");
    Validate.notEmpty(fieldName, "fieldName can't be blank");
    for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass
            .getSuperclass()) {
        try {
            Field field = superClass.getDeclaredField(fieldName);
            makeAccessible(field);
            return field;
        } catch (NoSuchFieldException e) {//NOSONAR
            // Field??,?
        }
    }
    return null;
}

From source file:edu.snu.leader.hidden.event.AbstractEventTimeCalculator.java

/**
 * Initializes the calculator/* w w w  . j a  va 2  s  .  c  om*/
 *
 * @param simState The simulation's state
 * @see edu.snu.leader.hidden.event.EventTimeCalculator#initialize(edu.snu.leader.hidden.SimulationState)
 */
@Override
public void initialize(SimulationState simState) {
    _LOG.trace("Entering initialize( simState )");

    // Save the simulation state
    _simState = simState;

    // Use hard-coded values from the paper
    _initRateBase = 1290.0f;
    _followAlpha = 162.3f;
    _followBeta = 75.4f;
    _cancelAlpha = 0.009f;
    _cancelGamma = 2.0f;
    _cancelEpsilon = 2.3f;

    // Get the properties
    Properties props = simState.getProps();

    // Get the initiation rate modification flag
    String modifyInitiationRateStr = props.getProperty(_MODIFY_INITIATION_RATE_KEY);
    Validate.notEmpty(modifyInitiationRateStr,
            "Modify initation rate (key=" + _MODIFY_INITIATION_RATE_KEY + ") may not be empty");
    _modifyInitiationRate = Boolean.parseBoolean(modifyInitiationRateStr);
    _LOG.info("Using _modifyInitiationRate=[" + _modifyInitiationRate + "]");

    // Get the following rate modification flag
    String modifyFollowingRateStr = props.getProperty(_MODIFY_FOLLOWING_RATE_KEY);
    Validate.notEmpty(modifyFollowingRateStr,
            "Modify following rate (key=" + _MODIFY_FOLLOWING_RATE_KEY + ") may not be empty");
    _modifyFollowingRate = Boolean.parseBoolean(modifyFollowingRateStr);
    _LOG.info("Using _modifyFollowingRate=[" + _modifyFollowingRate + "]");

    // Get the cancellation rate modification flag
    String modifyCancellationRateStr = props.getProperty(_MODIFY_CANCELLATION_RATE_KEY);
    Validate.notEmpty(modifyCancellationRateStr,
            "Modify cancellation rate (key=" + _MODIFY_CANCELLATION_RATE_KEY + ") may not be empty");
    _modifyCancellationRate = Boolean.parseBoolean(modifyCancellationRateStr);
    _LOG.info("Using _modifyCancellationRate=[" + _modifyCancellationRate + "]");

    _LOG.trace("Leaving initialize( simState )");
}

From source file:com.evolveum.midpoint.repo.sql.data.common.container.RContainerReference.java

public static void copyFromJAXB(ObjectReferenceType jaxb, RContainerReference repo, PrismContext prismContext) {
    Validate.notNull(repo, "Repo object must not be null.");
    Validate.notNull(jaxb, "JAXB object must not be null.");
    Validate.notEmpty(jaxb.getOid(), "Target oid must not be null.");

    repo.setType(ClassMapper.getHQLTypeForQName(jaxb.getType()));
    repo.setRelation(RUtil.qnameToString(jaxb.getRelation()));

    repo.setTargetOid(jaxb.getOid());//from  ww  w.  jav  a  2s  .com
}

From source file:com.vmware.identity.idm.server.RsaAgentConfFilesUpdater.java

/**
* Update rsa_api.properties, sdconf.rec, sdopts.rec on local sso server conf directory
* @param tenantInfo//from   w w  w .j  a  va2s . c o m
* @param rsaConfig
* @throws Exception
*/
public void updateRSAConfigFiles(TenantInformation tenantInfo, RSAAgentConfig rsaConfig) throws Exception {

    Validate.notNull(tenantInfo, "tenantInfo");

    String tenantName = tenantInfo.getTenant().getName();
    Validate.notEmpty(tenantName, "tenantName");

    // read from template from class resource
    ClassLoader classLoader = getClass().getClassLoader();
    InputStream templateStrm = classLoader.getResourceAsStream(RSA_API_PROPERTIES_TEMPLATE);
    Validate.notNull(templateStrm, "rsa_api.properties resource not found");

    // create tenant config directory if it does not exist
    File tenantConfigDir = ensureTenantConfigDirExist(tenantName);

    // create config file
    File tenantConfigFile = new File(tenantConfigDir, RSA_API_PROPERTIES_NAME);

    BufferedReader br = new BufferedReader(new InputStreamReader(templateStrm));

    String lines = "";
    String siteID = _clusterID;
    RSAAMInstanceInfo instInfo = rsaConfig.get_instMap().get(siteID);

    if (instInfo == null) {
        // site info are not defined.
        return;
    }
    String line;
    try {
        line = br.readLine();
        String ls = System.getProperty("line.separator");
        while (line != null) {
            String[] attrVal = line.split("=");

            if (attrVal == null || attrVal.length < 1) {
                continue;
            }

            String attr = attrVal[0].replace("#", "");
            String newLine;
            switch (attr) {
            // keys that are configurable
            case RSA_AGENT_NAME:
                newLine = RSA_AGENT_NAME + "=" + instInfo.get_agentName() + ls;
                lines += newLine;
                break;

            case SDCONF_LOC: {
                byte[] sdConfBytes = instInfo.get_sdconfRec();
                Validate.notNull(sdConfBytes);

                // delete existing file.
                File sdConfFile = new File(tenantConfigDir, SD_CONF_NAME);
                sdConfFile.delete();

                // write the file
                String sdConfFilePath = sdConfFile.getAbsolutePath();
                FileOutputStream fos;
                try {
                    fos = new FileOutputStream(sdConfFilePath);
                } catch (IOException e) {
                    logger.error("Can not create or open sdconf.rec: " + sdConfFilePath, e);
                    throw e;
                }
                try {
                    fos.write(sdConfBytes);
                } catch (IOException e) {
                    logger.error("Can not write to sdconf.rec: " + sdConfFilePath, e);
                    throw e;
                } finally {
                    fos.close();
                }
                // update the api properties
                newLine = SDCONF_LOC + "=" + sdConfFilePath + ls;
                lines += StringEscapeUtils.escapeJava(newLine);

                break;
            }
            case SDOPTS_LOC: {
                byte[] sdOptsBytes = instInfo.get_sdoptsRec();
                if (sdOptsBytes == null) {
                    newLine = "#" + SDOPTS_LOC + "=" + ls;
                    lines += newLine;
                    break;
                }

                // delete existing file.
                File sdOptsFile = new File(tenantConfigDir, SD_OPTS_NAME);
                sdOptsFile.delete();

                // write the file
                String sdOptsFilePath = sdOptsFile.getAbsolutePath();
                FileOutputStream fos;
                try {
                    fos = new FileOutputStream(sdOptsFilePath);
                } catch (IOException e) {
                    logger.error("Can not create or open sdopts.rec: " + sdOptsFilePath, e);
                    throw e;
                }
                try {
                    fos.write(sdOptsBytes);
                } catch (IOException e) {
                    logger.error("Can not write to sdopts.rec: " + sdOptsFilePath, e);
                    throw e;
                } finally {
                    fos.close();
                }
                // update the api properties
                newLine = SDOPTS_LOC + "=" + sdOptsFilePath;
                lines += StringEscapeUtils.escapeJava(newLine);

                break;
            }

            case RSA_LOG_LEVEL:
                newLine = RSA_LOG_LEVEL + "=" + rsaConfig.get_logLevel() + ls;
                lines += newLine;
                break;

            case RSA_LOG_FILE_SIZE:
                newLine = RSA_LOG_FILE_SIZE + "=" + rsaConfig.get_logFileSize() + "MB" + ls;
                lines += newLine;
                break;

            case RSA_LOG_FILE_COUNT:
                newLine = RSA_LOG_FILE_COUNT + "=" + rsaConfig.get_maxLogFileCount() + ls;
                lines += newLine;
                break;

            case RSA_CONNECTION_TIMEOUT:
                newLine = RSA_CONNECTION_TIMEOUT + "=" + rsaConfig.get_connectionTimeOut() + ls;
                lines += newLine;
                break;

            case RSA_READ_TIMEOUT:
                newLine = RSA_READ_TIMEOUT + "=" + rsaConfig.get_readTimeOut() + ls;
                lines += newLine;
                break;

            case RSA_ENC_ALGLIST:
                Set<String> encSet = rsaConfig.get_rsaEncAlgList();
                Validate.notNull(encSet);
                String[] encArray = encSet.toArray(new String[encSet.size()]);

                newLine = RSA_ENC_ALGLIST + "=";
                if (encArray.length > 0) {
                    newLine += encArray[0];
                }
                for (int i = 1; i < encArray.length; i++) {
                    newLine += ("," + encArray[i]);
                }
                newLine += ls;
                lines += newLine;
                break;

            // keys that not configurable
            case RSA_AGENT_PLATFORM:
                newLine = RSA_AGENT_PLATFORM + "=";
                if (SystemUtils.IS_OS_LINUX) {
                    newLine = RSA_AGENT_PLATFORM + "=linux" + ls;
                } else {
                    newLine = RSA_AGENT_PLATFORM + "=windows" + ls;
                }
                lines += newLine;
                break;

            case RSA_CONFIG_DATA_LOC:
                newLine = RSA_CONFIG_DATA_LOC + "=" + tenantConfigDir.getAbsolutePath() + ls;
                lines += StringEscapeUtils.escapeJava(newLine);
                break;

            case SDNDSCRT_LOC:
                File sdndscrtLoc = new File(tenantConfigDir, "secureid");
                newLine = RSA_CONFIG_DATA_LOC + "=" + sdndscrtLoc.getAbsolutePath() + ls;
                lines += StringEscapeUtils.escapeJava(newLine);
                break;

            case RSA_LOG_FILE:
                String ssoConfigDir = IdmUtils.getIdentityServicesLogDir();
                File rsaLogFile = new File(ssoConfigDir, RSA_SECUREID_LOG_NAME);
                newLine = RSA_LOG_FILE + "=" + rsaLogFile.getAbsolutePath() + ls;
                lines += StringEscapeUtils.escapeJava(newLine);
                break;

            default:
                lines += (line + ls);

            }
            line = br.readLine();
        }
    } catch (IOException e) {
        logger.error("Fail to read from rsa_api.properties resource stream", e);
        throw new IDMException("Unable to generate rsa_api property file", e);
    }
    FileWriter fw;
    try {
        fw = new FileWriter(tenantConfigFile);
    } catch (IOException e) {
        logger.error("Fail to create rsa_api.properties file", e);
        throw new IDMException("Unable to generate rsa_api property file", e);
    }

    BufferedWriter out = new BufferedWriter(fw);
    try {
        tenantInfo.get_rsaConfigFilesLock().writeLock().lock();
        out.write(lines.toString());
    } catch (IOException e) {
        logger.error("Fail to write to rsa_api.properties file", e);
        throw new IDMException("Unable to generate rsa_api property file", e);
    } finally {
        try {
            out.close();
        } catch (IOException e) {
            tenantInfo.get_rsaConfigFilesLock().writeLock().unlock();
            logger.error("Fail to close to rsa_api.properties file BufferWriter", e);
            throw new IDMException("Unable to generate rsa_api property file", e);
        }
        tenantInfo.get_rsaConfigFilesLock().writeLock().unlock();
    }
}

From source file:edu.snu.leader.spatial.calculator.AbstractSueurDecisionProbabilityCalculator.java

/**
 * Initializes the calculator/*from   ww w .  j  a  v a  2s. c o m*/
 *
 * @param simState The simulation's state
 * @see edu.snu.leader.spatial.DecisionProbabilityCalculator#initialize(edu.snu.leader.spatial.SimulationState)
 */
@Override
public void initialize(SimulationState simState) {
    _LOG.trace("Entering initialize( simState )");

    // Save the simulation state
    _simState = simState;

    // Get the properties
    Properties props = simState.getProperties();

    // Get the initiation rate modification flag
    String modifyInitiationRateStr = props.getProperty(_MODIFY_INITIATION_RATE_KEY);
    Validate.notEmpty(modifyInitiationRateStr,
            "Modify initation rate (key=" + _MODIFY_INITIATION_RATE_KEY + ") may not be empty");
    _modifyInitiationRate = Boolean.parseBoolean(modifyInitiationRateStr);
    _LOG.info("Using _modifyInitiationRate=[" + _modifyInitiationRate + "]");

    // Get the following innate rate modification flag
    String modifyFollowingInnateRateStr = props.getProperty(_MODIFY_FOLLOWING_INNATE_RATE_KEY);
    Validate.notEmpty(modifyFollowingInnateRateStr,
            "Modify following innate rate (key=" + _MODIFY_FOLLOWING_INNATE_RATE_KEY + ") may not be empty");
    _modifyFollowingInnateRate = Boolean.parseBoolean(modifyFollowingInnateRateStr);
    _LOG.info("Using _modifyFollowingInnateRate=[" + _modifyFollowingInnateRate + "]");

    // Get the following mimetic rate modification flag
    String modifyFollowingMimeticRateStr = props.getProperty(_MODIFY_FOLLOWING_MIMETIC_RATE_KEY);
    Validate.notEmpty(modifyFollowingMimeticRateStr,
            "Modify following mimetic rate (key=" + _MODIFY_FOLLOWING_MIMETIC_RATE_KEY + ") may not be empty");
    _modifyFollowingMimeticRate = Boolean.parseBoolean(modifyFollowingMimeticRateStr);
    _LOG.info("Using _modifyFollowingMimeticRate=[" + _modifyFollowingMimeticRate + "]");

    // Get the cancellation rate modification flag
    String modifyCancellationRateStr = props.getProperty(_MODIFY_CANCELLATION_RATE_KEY);
    Validate.notEmpty(modifyCancellationRateStr,
            "Modify cancellation rate (key=" + _MODIFY_CANCELLATION_RATE_KEY + ") may not be empty");
    _modifyCancellationRate = Boolean.parseBoolean(modifyCancellationRateStr);
    _LOG.info("Using _modifyCancellationRate=[" + _modifyCancellationRate + "]");

    // For now, hard code the equation values
    _alpha = 0.000775f;
    _LOG.info("Using _alpha=[" + _alpha + "]");
    _beta = 0.008f;
    _LOG.info("Using _beta=[" + _beta + "]");
    _s = simState.getAgentCount() * 0.6f;
    _LOG.info("Using _s=[" + _s + "]");
    _q = 1.4f;
    _LOG.info("Using _q=[" + _q + "]");
    _alphaC = 0.009f;
    _LOG.info("Using _alphaC=[" + _alphaC + "]");
    _betaC = -0.009f;
    _LOG.info("Using _betaC=[" + _betaC + "]");
    _sC = 2.0f;
    _LOG.info("Using _sC=[" + _sC + "]");
    _qC = 2.3f;
    _LOG.info("Using _qC=[" + _qC + "]");

    _LOG.trace("Leaving initialize( simState )");
}