Java Code Examples for org.apache.commons.lang3.Validate#notBlank()

The following examples show how to use org.apache.commons.lang3.Validate#notBlank() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientDelegator.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String deleteClient(final String clientName, final DeleteClientOptions opts)
		throws P4JavaException {

	Validate.notBlank(clientName, "Null or empty client name passed in updateClient()");
	List<Map<String, Object>> resultMaps = execMapCmdList(
			CLIENT,
			Parameters.processParameters(
					opts,
					null,
					new String[]{"-d", clientName},
					server),
			null);

	return parseCommandResultMapIfIsInfoMessageAsString(resultMaps);
}
 
Example 2
Source File: ClientDelegator.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public String switchClientView(final String templateClientName,
							   final String targetClientName,
							   final SwitchClientViewOptions opts) throws P4JavaException {

	Validate.notBlank(templateClientName, "Template client name shouldn't blank");

	List<String> args = new ArrayList<>(Arrays.asList("-s", "-t", templateClientName));
	if (isNotBlank(targetClientName)) {
		args.add(targetClientName);
	}

	List<Map<String, Object>> resultMaps = execMapCmdList(
			CLIENT,
			processParameters(
					opts,
					null,
					args.toArray(new String[args.size()]),
					server),
			null);

	return parseCommandResultMapIfIsInfoMessageAsString(resultMaps);
}
 
Example 3
Source File: CounterDelegator.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
@Override
public String getCounter(final String counterName, final CounterOptions opts)
        throws P4JavaException {

    Validate.notBlank(counterName, "Counter name shouldn't be null or empty");

    List<Map<String, Object>> resultMaps = execMapCmdList(COUNTER,
            processParameters(opts, null, new String[] { counterName }, server), null);
    
    return ResultListBuilder.buildNullableObjectFromNonInfoMessageCommandResultMaps(
            resultMaps,
            new Function<Map, String>() {
                @Override
                public String apply(Map map) {
                    return parseString(map, VALUE);
                }
            }
    );
}
 
Example 4
Source File: CounterDelegator.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
@Override
public String getCounter(final String counterName, final CounterOptions opts)
        throws P4JavaException {

    Validate.notBlank(counterName, "Counter name shouldn't be null or empty");

    List<Map<String, Object>> resultMaps = execMapCmdList(COUNTER,
            processParameters(opts, null, new String[] { counterName }, server), null);
    
    return ResultListBuilder.buildNullableObjectFromNonInfoMessageCommandResultMaps(
            resultMaps,
            new Function<Map, String>() {
                @Override
                public String apply(Map map) {
                    return parseString(map, VALUE);
                }
            }
    );
}
 
Example 5
Source File: LogTail.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public LogTail(final String logFilePath, final long offset, @Nonnull final List<String> data) {
    Validate.notBlank(logFilePath, "logFilePath shouldn't null or empty");
    Validate.isTrue(offset >= 0, "offset should be greater than or equal to 0");
    Validate.notNull(data, "No data passed to the LogTail constructor.");
    Validate.notEmpty(data, "No data passed to the LogTail constructor.");
    this.logFilePath = logFilePath;
    this.offset = offset;
    this.data.addAll(data);
}
 
Example 6
Source File: DepotDelegator.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Override
public String deleteDepot(final String name) throws P4JavaException {
    Validate.notBlank(name, "Delete depot name shouldn't null or empty");

    List<Map<String, Object>> resultMaps = execMapCmdList(DEPOT, new String[]{"-d", name},
            null);
    return ResultMapParser.parseCommandResultMapIfIsInfoMessageAsString(resultMaps);
}
 
Example 7
Source File: StringUtil.java    From feilong-core with Apache License 2.0 5 votes vote down vote up
/**
 * 字符串 <code>value</code> 转换成byte数组.
 * 
 * @param value
 *            字符串
 * @param charsetName
 *            受支持的 charset 名称,比如 utf-8, {@link CharsetType}
 * @return 如果 <code>value</code> 是null,抛出 {@link NullPointerException}<br>
 *         如果 <code>charsetName</code> 是null,抛出 {@link NullPointerException}<br>
 *         如果 <code>charsetName</code> 是blank,抛出 {@link IllegalArgumentException}<br>
 * @see String#getBytes(String)
 * @since 1.3.0
 */
public static byte[] getBytes(String value,String charsetName){
    Validate.notNull(value, "value can't be null!");
    Validate.notBlank(charsetName, "charsetName can't be blank!");

    //---------------------------------------------------------------
    try{
        return value.getBytes(charsetName);
    }catch (UnsupportedEncodingException e){
        String pattern = "value:[{}],charsetName:[{}],suggest you use [{}] constants";
        String message = Slf4jUtil.format(pattern, value, charsetName, CharsetType.class.getCanonicalName());
        throw new UncheckedIOException(message, e);
    }
}
 
Example 8
Source File: SkipFieldValueBolt.java    From cognition with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(Configuration conf) {
  field = conf.getString(FIELD);
  value = conf.getString(VALUE);

  Validate.notBlank(field);
  Validate.notBlank(value);
}
 
Example 9
Source File: SecuritySchemeDefinitionComponent.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
public Parameters(String securitySchemeDefinitionName,
                  SecuritySchemeDefinition securitySchemeDefinition,
                  int titleLevel) {
    this.securitySchemeDefinitionName = Validate.notBlank(securitySchemeDefinitionName, "SecuritySchemeDefinitionName must not be empty");
    this.securitySchemeDefinition = Validate.notNull(securitySchemeDefinition, "SecuritySchemeDefinition must not be null");
    this.titleLevel = titleLevel;
}
 
Example 10
Source File: GrepDelegator.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
/**
 * Get list of matching lines in the specified file specs. This method
 * implements the p4 grep command; for full semantics, see the separate p4
 * documentation and / or the GrepOptions Javadoc.
 * <p>
 *
 * This method allows the user to retrieve useful info and warning message
 * lines the Perforce server may generate in response to things like
 * encountering a too-long line, etc., by passing in a non-null infoLines
 * parameter.
 *
 * @param fileSpecs
 *            file specs to search for matching lines
 * @param pattern
 *            non-null string pattern to be passed to the grep command
 * @param infoLines
 *            if not null, any "info" lines returned from the server (i.e.
 *            warnings about exceeded line lengths, etc.) will be put into
 *            the passed-in list in the order they are received.
 * @param options
 *            - Options to grep command
 * @return - non-null but possibly empty list of file line matches
 * @throws P4JavaException
 *             if any error occurs in the processing of this method.
 * @since 2011.1
 */
public List<IFileLineMatch> getMatchingLines(@Nonnull final List<IFileSpec> fileSpecs,
        @Nonnull final String pattern, @Nullable final List<String> infoLines,
        final MatchingLinesOptions options) throws P4JavaException {

    Validate.notNull(fileSpecs);
    Validate.notBlank(pattern, "Match pattern string shouldn't null or empty");

    List<Map<String, Object>> resultMaps = execMapCmdList(GREP,
            processParameters(options, fileSpecs, "-e" + pattern, server), null);

    List<IFileLineMatch> specList = new ArrayList<>();
    if (nonNull(resultMaps)) {
        for (Map<String, Object> map : resultMaps) {
            String message = ResultMapParser.getErrorStr(map);
            throwRequestExceptionIfConditionFails(isBlank(message), parseCode0ErrorString(map),
                    message);
            message = ResultMapParser.getErrorOrInfoStr(map);
            if (isBlank(message)) {
                specList.add(new FileLineMatch(map));
            } else if (nonNull(infoLines)) {
                infoLines.add(message);
            }
        }
    }
    return specList;
}
 
Example 11
Source File: BranchDelegator.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Override
public IBranchSpec getBranchSpec(final String name, final GetBranchSpecOptions opts)
        throws P4JavaException {
    Validate.notBlank(name, "Branch spec name shouldn't blank");

    List<Map<String, Object>> resultMaps = execMapCmdList(BRANCH,
            processParameters(opts, null, new String[]{"-o", name}, server), null);

    return ResultListBuilder.buildNullableObjectFromNonInfoMessageCommandResultMaps(
            resultMaps,
            // p4ic4idea: define map generics and use a lambda.
            (Function<Map<String, Object>, IBranchSpec>) map ->
                    new BranchSpec(map, server)
    );
}
 
Example 12
Source File: GraphListTree.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public GraphListTree(int mode, String type, String sha, String name) {
	Validate.notBlank(name, "Name should not be null or empty");
	Validate.notBlank(sha, "SHA should not be null or empty");
	Validate.notBlank(type, "Type should not be null or empty");

	this.mode = mode;
	this.type = type;
	this.sha = sha;
	this.name = name;
}
 
Example 13
Source File: JDBCUtil.java    From aws-athena-query-federation with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a map of Catalog to respective record handler to be used by Multiplexer.
 *
 * @param properties system properties.
 * @return Map of String -> {@link JdbcRecordHandler}
 */
public static Map<String, JdbcRecordHandler> createJdbcRecordHandlerMap(final Map<String, String> properties)
{
    ImmutableMap.Builder<String, JdbcRecordHandler> recordHandlerMap = ImmutableMap.builder();

    final String functionName = Validate.notBlank(properties.get(LAMBDA_FUNCTION_NAME_PROPERTY), "Lambda function name not present in environment.");
    List<DatabaseConnectionConfig> databaseConnectionConfigs = new DatabaseConnectionConfigBuilder().properties(properties).build();

    if (databaseConnectionConfigs.isEmpty()) {
        throw new RuntimeException("At least one connection string required.");
    }

    boolean defaultPresent = false;

    for (DatabaseConnectionConfig databaseConnectionConfig : databaseConnectionConfigs) {
        JdbcRecordHandler jdbcRecordHandler = createJdbcRecordHandler(databaseConnectionConfig);
        recordHandlerMap.put(databaseConnectionConfig.getCatalog(), jdbcRecordHandler);

        if (DatabaseConnectionConfigBuilder.DEFAULT_CONNECTION_STRING_PROPERTY.equals(databaseConnectionConfig.getCatalog())) {
            recordHandlerMap.put(DEFAULT_CATALOG_PREFIX + functionName, jdbcRecordHandler);
            defaultPresent = true;
        }
    }

    if (!defaultPresent) {
        throw new RuntimeException("Must provide connection parameters for default database instance " + DatabaseConnectionConfigBuilder.DEFAULT_CONNECTION_STRING_PROPERTY);
    }

    return recordHandlerMap.build();
}
 
Example 14
Source File: AddMetadataBolt.java    From cognition with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(Configuration conf) {
  field = conf.getString("field");
  value = conf.getString("value");

  Validate.notBlank(field);
  Validate.notBlank(value);
}
 
Example 15
Source File: GraphObject.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public GraphObject(String sha, String type) {
	Validate.notBlank(sha, "SHA should not be null or empty");
	Validate.notBlank(type, "Type should not be null or empty");

	this.sha = sha;
	this.type = type;
}
 
Example 16
Source File: ThumbImage.java    From FastDFS_Client with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 根据文件名获取缩略图路径
 */
public String getThumbImagePath(String masterFilename) {
    Validate.notBlank(masterFilename, "主文件不能为空");
    StringBuilder buff = new StringBuilder(masterFilename);
    int index = buff.lastIndexOf(".");
    buff.insert(index, getPrefixName());
    return new String(buff);
}
 
Example 17
Source File: ConfigureDelegator.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
@Override
public String setOrUnsetServerConfigurationValue(@Nonnull final String name,
                                                 @Nullable final String value) throws P4JavaException {

    Validate.notBlank(name, "Config name shouldn't null or empty");
    String[] args = new String[]{UNSET, name};
    if (isNotBlank(value)) {
        args = new String[]{SET, name + "=" + value};
    }

    List<Map<String, Object>> resultMaps = execMapCmdList(CONFIGURE, args, null);

    StringBuilder messageBuilder = new StringBuilder(STRING_BUILDER_SIZE);
    if (nonNull(resultMaps)) {
        for (Map<String, Object> map : resultMaps) {
            // p4ic4idea: use IServerMessage
            if (nonNull(map)) {
                IServerMessage msg = toServerMessage(map);
                // p4ic4idea: this is the "else" block that was at the end.
                if (nonNull(msg) && msg.isInfoOrError()) {
                    return msg.toString();
                }
                // Handling the new message format for Perforce server
                // version 2011.1; also maintain backward compatibility.
                if (map.containsKey(NAME_KEY)) {
                    if (map.containsKey(ACTION_KEY) && nonNull(map.get(ACTION_KEY))) {
                        String message = nonNull(msg) ? msg.toString() : EMPTY;
                        String serverName = parseString(map, SERVER_NAME_KEY);
                        String configureName = parseString(map, NAME_KEY);
                        String configureValue = parseString(map, VALUE_KEY);
                        String action = parseString(map, ACTION_KEY);
                        if (SET.equalsIgnoreCase(action)) {
                            message = format(
                                    "For server '%s', configuration variable '%s' "
                                            + "set to '%s'",
                                    serverName, configureName, configureValue);
                        } else if (UNSET.equalsIgnoreCase(action)) {
                            message = format(
                                    "For server '%s', configuration variable '%s' removed.",
                                    serverName, configureName);
                        }

                        if (isNotBlank(message)) {
                            messageBuilder.append(message).append("\n");
                        }
                    }
                }
            }
        }
    }
    return messageBuilder.toString();
}
 
Example 18
Source File: AlexaApiEndpoint.java    From alexa-skills-kit-tester-java with Apache License 2.0 4 votes vote down vote up
void preBuild() {
    Validate.notBlank(skillId, "[ERROR] SkillId must not be empty.");
}
 
Example 19
Source File: AbstractMarkupDocBuilder.java    From markup-document-builder with Apache License 2.0 4 votes vote down vote up
protected void sectionTitleLevel(Markup markup, int level, String title) {
    Validate.notBlank(title, "title must not be blank");
    Validate.inclusiveBetween(1, MAX_TITLE_LEVEL, level);
    documentBuilder.append(newLine);
    documentBuilder.append(StringUtils.repeat(markup.toString(), level + 1)).append(" ").append(replaceNewLinesWithWhiteSpace(title)).append(newLine);
}
 
Example 20
Source File: PropertyComparator.java    From feilong-core with Apache License 2.0 3 votes vote down vote up
/**
 * 带<code>propertyName</code> 和 <code>propertyValueConvertToClass</code> 以及 <code>comparator</code> 的构造函数.
 * 
 * <h3>使用场景:</h3>
 * <blockquote>
 * 诸如需要排序的对象指定属性类型是数字,但是申明类型的时候由于种种原因是字符串,<br>
 * 此时需要排序,如果不转成Integer比较的话,字符串比较13 将会在 3数字的前面
 * </blockquote>
 * 
 * <h3>示例:</h3>
 * <blockquote>
 * 
 * <p>
 * 我们现在有这样的数据,其中属性 totalNo是字符串类型的
 * </p>
 * 
 * <pre class="code">
 * CourseEntity courseEntity1 = new CourseEntity();
 * courseEntity1.setTotalNo("3");
 * 
 * CourseEntity courseEntity2 = new CourseEntity();
 * courseEntity2.setTotalNo("13");
 * 
 * List{@code <CourseEntity>} courseList = new ArrayList{@code <>}();
 * courseList.add(courseEntity1);
 * courseList.add(courseEntity2);
 * </pre>
 * 
 * 如果 我们只是使用 propertyName进行排序的话:
 * 
 * <pre class="code">
 * Collections.sort(courseList, new PropertyComparator{@code <CourseEntity>}("totalNo"));
 * LOGGER.debug(JsonUtil.format(courseList));
 * </pre>
 * 
 * 那么<b>返回:</b>
 * 
 * <pre class="code">
 * [{
 * "totalNo": "13",
 * "name": ""
 * },{
 * "totalNo": "3",
 * "name": ""
 * }]
 * </pre>
 * 
 * 如果我们使用 propertyName+ propertyValueConvertToClass进行排序的话:
 * 
 * <pre class="code">
 * Collections.sort(courseList, new PropertyComparator{@code <CourseEntity>}("totalNo", Integer.class,ComparatorUtils.NATURAL_COMPARATOR));
 * LOGGER.debug(JsonUtil.format(courseList));
 * </pre>
 * 
 * <b>返回:</b>
 * 
 * <pre class="code">
 * [{
 * "totalNo": "3",
 * "name": ""
 * },{
 * "totalNo": "13",
 * "name": ""
 * }]
 * </pre>
 * 
 * </blockquote>
 *
 * @param propertyName
 *            指定bean对象排序属性名字(默认正序).
 * 
 *            <p>
 *            泛型T对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
 *            <a href="../../bean/BeanUtil.html#propertyName">propertyName</a>,<br>
 *            该属性的value 必须实现 {@link Comparable}接口.
 *            </p>
 * 
 *            如果 <code>propertyName</code> 是null,抛出 {@link NullPointerException}<br>
 *            如果 <code>propertyName</code> 是blank,抛出 {@link IllegalArgumentException}<br>
 * 
 * @param propertyValueConvertToClass
 *            反射提取出来的值,需要类型转成到的类型
 * @param comparator
 *            提取 <code>propertyName</code> 的属性值之后,支持使用自定义的比较器来比较值,如果是null,那么使用默认规则
 * @since 1.5.4
 */
@SuppressWarnings("rawtypes")
public PropertyComparator(String propertyName, Class<? extends Comparable> propertyValueConvertToClass, Comparator comparator){
    Validate.notBlank(propertyName, "propertyName can't be blank!");
    this.propertyName = propertyName;
    this.propertyValueConvertToClass = propertyValueConvertToClass;
    this.comparator = comparator;
    LOGGER.trace("propertyName:[{}]", propertyName);
}