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

The following examples show how to use org.apache.commons.lang3.Validate#notEmpty() . 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: FunctionFactoryImpl.java    From moql with Apache License 2.0 6 votes vote down vote up
@Override
public String registFunction(String name, String className) {
  // TODO Auto-generated method stub
  Validate.notEmpty(name, "Parameter name is empty!");
  Validate.notEmpty(name, "Parameter className is empty!");
  name = name.toLowerCase();
  FunctionBean bean = functionMap.get(name);
  if (bean != null) {
    if (bean.isReadonly())
      return null;
    functionMap.put(name, new FunctionBean(name, className, false));
    return bean.getClassName();
  } else {
    functionMap.put(name, new FunctionBean(name, className, false));
  }
  return null;
}
 
Example 2
Source File: ListNamingService.java    From brpc-java with Apache License 2.0 6 votes vote down vote up
public ListNamingService(BrpcURL namingUrl) {
    Validate.notNull(namingUrl);
    Validate.notEmpty(namingUrl.getHostPorts());

    String hostPorts = namingUrl.getHostPorts();
    String[] hostPortSplits = hostPorts.split(",");
    this.instances = new ArrayList<ServiceInstance>(hostPortSplits.length);
    for (String hostPort : hostPortSplits) {
        String[] hostPortSplit = hostPort.split(":");
        String host = hostPortSplit[0];
        int port;
        if (hostPortSplit.length == 2) {
            port = Integer.valueOf(hostPortSplit[1]);
        } else {
            port = 80;
        }
        instances.add(new ServiceInstance(host, port));
    }
}
 
Example 3
Source File: OperandFactoryImpl.java    From moql with Apache License 2.0 6 votes vote down vote up
@Override
public Operand createOperand(String operand) throws MoqlException {
	// TODO Auto-generated method stub
	Validate.notEmpty(operand, "Parameter 'operand' is empty!");
	Operand pseudoOperand = createPseudoOperand(operand);
	if (pseudoOperand != null)
	  return pseudoOperand;
	try {
		ANTLRInputStream is = new ANTLRInputStream(new ByteArrayInputStream(operand.getBytes()));
		OperandLexer lexer = new OperandLexer(is);
		CommonTokenStream tokens = new CommonTokenStream(lexer);
		OperandParser parser = new OperandParser(tokens);
		parser.setFunctionFactory(functionFactory);
		return parser.operand();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		throw new MoqlException(
         StringFormater.format("Create operand '{}' failed!", operand), e);
	}
}
 
Example 4
Source File: MongoDbSteps.java    From vividus with Apache License 2.0 6 votes vote down vote up
private static void verify(List<MongoCommandEntry> commands)
{
    Validate.notEmpty(commands, "Command sequence must not be empty");

    List<String> errors = new ArrayList<>();
    boolean checkStart = !commands.get(0).getCommand().getCommandType().equals(CommandType.SOURCE);
    appendIf(checkStart, () -> "Command sequence must start with one of the source commands: "
            + MongoCommand.findByCommandType(CommandType.SOURCE), errors);

    boolean checkEnd = !commands.get(commands.size() - 1).getCommand().getCommandType()
            .equals(CommandType.TERMINAL);
    appendIf(checkEnd, () -> "Command sequence must end with one of the terminal commands: "
            + MongoCommand.findByCommandType(CommandType.TERMINAL), errors);

    boolean checkIntermediate = commands.size() > 2 && !commands.subList(1, commands.size() - 1).stream()
            .map(MongoCommandEntry::getCommand)
            .map(MongoCommand::getCommandType)
            .allMatch(CommandType.INTERMEDIATE::equals);
    appendIf(checkIntermediate,
        () -> "Only the following commands are allowed between the first and the last ones: "
            + MongoCommand.findByCommandType(CommandType.INTERMEDIATE), errors);

    Validate.isTrue(errors.isEmpty(), "%n%s",
            errors.stream().map(e -> " - " + e).collect(Collectors.joining(System.lineSeparator())));
}
 
Example 5
Source File: ZKChildMonitor.java    From ECFileCache with Apache License 2.0 6 votes vote down vote up
private void loadZkInfos() {

    Properties props = new Properties();
    try {
      props.load(ZKChildMonitor.class.getResourceAsStream(CLUSTER_CONF_FILE));
    } catch (IOException e) {
      LOGGER.error("Read cluster.properties exception", e);
    }

    String zkServersStr = System.getProperty(ZK_SERVERS);
    if (StringUtils.isNotEmpty(zkServersStr)) {
      LOGGER.warn("Apply the zk servers from system setting: [{}]", zkServersStr);
    } else {
      zkServersStr = props.getProperty(ZK_SERVERS);
      LOGGER.warn("Apply the zk servers from cluster.properties: [{}]", zkServersStr);
    }
    Validate.notEmpty(zkServersStr);

    zkServers = zkServersStr;
  }
 
Example 6
Source File: MonetaSearchDAO.java    From moneta with Apache License 2.0 6 votes vote down vote up
public SearchResult find(SearchRequest request) {
	Validate.notNull(request, "Null search request not allowed.");
	Validate.notEmpty(request.getTopic(), "Null or blank search topic not allowed.");
	
	Topic searchTopic = MonetaEnvironment.getConfiguration().getTopic(request.getTopic());
	Validate.notNull(searchTopic, "Search topic not found.   topic="+request.getTopic());
	
	MonetaDataSource source = MonetaEnvironment.getConfiguration().getMonetaDataSource(searchTopic.getDataSourceName());
	
	SqlStatement sqlStmt = SqlGeneratorFactory.findSqlGenerator(source.getDialect())
			.generateSelect(searchTopic, 
					request.getSearchCriteria(), 
					request.getFieldNames());
	SqlSelectExecutor sExec = new SqlSelectExecutor(request.getTopic(), sqlStmt);
	sExec.setMaxRows(request.getMaxRows());
	sExec.setStartRow(request.getStartRow());
	return sExec.call();
}
 
Example 7
Source File: AlexaApiEndpoint.java    From alexa-skills-kit-tester-java with Apache License 2.0 5 votes vote down vote up
AlexaApiEndpointBuilder(final HashMap<Object, Object> endpointConfiguration) {
    Validate.notEmpty(endpointConfiguration, "configuration section in your YAML file must not be empty. At least a type needs to be set.");
    this.skillId = Optional.ofNullable(endpointConfiguration.get("skillId"))
            .filter(o -> o instanceof String)
            .map(Object::toString)
            .filter(StringUtils::isNotBlank)
            .orElse(System.getenv("skillId"));

    Optional.ofNullable(endpointConfiguration.get("lwa")).filter(o -> o instanceof HashMap).map(o -> (HashMap)o).ifPresent(yLwa -> {
        this.lwaClientId = Optional.ofNullable(yLwa.get("clientId")).map(Object::toString).orElse(null);
        this.lwaClientSecret = Optional.ofNullable(yLwa.get("clientSecret")).map(Object::toString).orElse(null);
        this.lwaRefreshToken = Optional.ofNullable(yLwa.get("refreshToken")).map(Object::toString).orElse(null);
    });
}
 
Example 8
Source File: MoqlParser.java    From moql with Apache License 2.0 5 votes vote down vote up
public static SelectorDefinition translateXml2SelectorDefinition(
    String xmlData) throws MoqlException {
  Validate.notEmpty(xmlData, "xmlData is empty!");
  DefaultDocumentFormater<SelectorDefinition> documentFormater = new DefaultDocumentFormater<SelectorDefinition>();
  SelectorFormater selectorFormater = new SelectorFormater();
  documentFormater.setFormater(selectorFormater);
  return documentFormater.importObjectFromString(xmlData);
}
 
Example 9
Source File: MultiplexingJdbcMetadataHandler.java    From aws-athena-query-federation with Apache License 2.0 5 votes vote down vote up
/**
 * @param metadataHandlerMap catalog -> JdbcMetadataHandler
 */
@VisibleForTesting
MultiplexingJdbcMetadataHandler(final AWSSecretsManager secretsManager, final AmazonAthena athena, final JdbcConnectionFactory jdbcConnectionFactory,
        final Map<String, JdbcMetadataHandler> metadataHandlerMap, final DatabaseConnectionConfig databaseConnectionConfig)
{
    super(databaseConnectionConfig, secretsManager, athena, jdbcConnectionFactory);
    this.metadataHandlerMap = Validate.notEmpty(metadataHandlerMap, "metadataHandlerMap must not be empty");

    if (this.metadataHandlerMap.size() > MAX_CATALOGS_TO_MULTIPLEX) {
        throw new RuntimeException("Max 100 catalogs supported in multiplexer.");
    }
}
 
Example 10
Source File: ModAPIImpl.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
@Override
public IKeybinding registerKeyBinding(String description, int keyCode, String category) {
	Validate.notNull(description, "Description may not be null!");
	Validate.notEmpty(description, "Description may not be empty!");
	Validate.notNull(category, "Category may not be null!");
	Validate.notEmpty(category, "Category may not be empty!");

	IKeybinding keybinding = The5zigMod.getVars().createKeybinding(description, keyCode, category);
	The5zigMod.getVars().registerKeybindings(Collections.singletonList(keybinding));
	return keybinding;
}
 
Example 11
Source File: SearchUtils.java    From coroutines with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Find field within a class by its name.
 * @param classNode class to search
 * @param name name to search for
 * @return found field (or {@code null} if not found)
 * @throws NullPointerException if any argument is {@code null}
 * @throws IllegalArgumentException if {@code name} is empty
 */
public static FieldNode findField(ClassNode classNode, String name) {
    Validate.notNull(classNode);
    Validate.notNull(name);
    Validate.notEmpty(name);
    return classNode.fields.stream()
            .filter(x -> name.equals(x.name))
            .findAny().orElse(null);
}
 
Example 12
Source File: RowTransposition.java    From moql with Apache License 2.0 5 votes vote down vote up
public RowTransposition(List<Operand> parameters) {
  super(FUNCTION_NAME, parameters.size(), parameters);
  if (parameters.size() == 0) {
    throw new IllegalArgumentException(
        "Invalid function format! The format should be 'rowTranspose(headerColumn[,valueColumns,valueColumnsName,groupColumns])'");
  }
  // TODO Auto-generated constructor stub
  headerColumn = (String) parameters.get(0).operate(null);
  Validate.notEmpty(headerColumn, "rowColumn is empty!");
  if (parameters.size() > 1) {
    String valueColumnsString = (String) parameters.get(1).operate(null);
    if (valueColumnsString != null && valueColumnsString.length() > 0)
      valueColumns = valueColumnsString.split(",");
  }
  if (parameters.size() > 2) {
    String valueColumnsName = (String) parameters.get(2).operate(null);
    if (valueColumnsName != null && valueColumnsName.length() > 0) {
      this.valueColumnsName = valueColumnsName;
    }
  }
  if (parameters.size() > 3) {
    String groupColumnsString = (String) parameters.get(3).operate(null);
    if (groupColumnsString != null && groupColumnsString.length() > 0)
      groupColumns = groupColumnsString.split(",");
  }
  checkInvalidate();
}
 
Example 13
Source File: PitchforkServlet.java    From haystack-agent with Apache License 2.0 5 votes vote down vote up
public PitchforkServlet(final String name,
                        final Map<String, ZipkinSpanProcessor> processors) {
    Validate.notEmpty(name, "pitchfork servlet name can't be empty or null");
    Validate.isTrue(processors != null && !processors.isEmpty(), "span processors can't be null");

    this.processors = processors;
    requestRateMeter = SharedMetricRegistry.newMeter("pitchfork." + name + ".request.rate");
    errorMeter = SharedMetricRegistry.newMeter("pitchfork." + name + ".error.rate");

    logger.info("Initializing http servlet with name = {}", name);
}
 
Example 14
Source File: ZipkinSpanProcessorFactory.java    From haystack-agent with Apache License 2.0 5 votes vote down vote up
public ZipkinSpanProcessorFactory(final SpanValidator validator,
                                  final List<Dispatcher> dispatchers,
                                  final List<Enricher> enrichers) {

    Validate.notNull(validator, "span validator can't be null");
    Validate.notEmpty(dispatchers, "dispatchers can't be null or empty");
    Validate.notNull(enrichers, "enrichers can't be null or empty");

    this.validator = validator;
    this.dispatchers = dispatchers;
    this.enrichers = enrichers;
}
 
Example 15
Source File: ModAPIImpl.java    From The-5zig-Mod with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void registerModuleItem(Object plugin, String key, Class<? extends AbstractModuleItem> moduleItem, String category) {
	Validate.notNull(key, "Key may not be null!");
	Validate.notEmpty(key, "Key may not be empty!");
	Validate.notNull(moduleItem, "Module item may not be null!");
	Validate.notNull(category, "Category may not be null!");

	LoadedPlugin loadedPlugin = The5zigMod.getAPI().getPluginManager().getPlugin(plugin);
	if (loadedPlugin == null) {
		throw new IllegalArgumentException("Plugin has not been registered!");
	}
	The5zigMod.getModuleItemRegistry().registerItem(key, moduleItem, category);
	loadedPlugin.getRegisteredModuleItems().add(moduleItem);
}
 
Example 16
Source File: SqlSelectExecutor.java    From moneta with Apache License 2.0 5 votes vote down vote up
public SqlSelectExecutor(String topicName, SqlStatement sqlStmt) {
	topic = MonetaEnvironment.getConfiguration().getTopic(topicName);
	Validate.notNull(topic, "topic not found.    topic=" + topicName);
	Validate.notNull(sqlStmt, "Null SqlStatement not allowed");
	Validate.notEmpty(sqlStmt.getSqlText(), "Null or blank SqlText not allowed.");
	this.sqlStmt = sqlStmt;
}
 
Example 17
Source File: EntityMapImpl.java    From moql with Apache License 2.0 4 votes vote down vote up
@Override
public Object removeEntity(String entityName) {
	// TODO Auto-generated method stub
	Validate.notEmpty(entityName, "Parameter 'entityName' is empty!");
	return entityMap.remove(entityName);
}
 
Example 18
Source File: DoubleConstant.java    From moql with Apache License 2.0 4 votes vote down vote up
public DoubleConstant(String name) {
	Validate.notEmpty(name, "Parameter 'name' is empty!");
	this.name = name;
	this.data = Double.valueOf(name);
}
 
Example 19
Source File: Message.java    From gradle-fury with Apache License 2.0 4 votes vote down vote up
public void setMessage(final String message) {
    Validate.notEmpty(message);
    this.message = message;
}
 
Example 20
Source File: BaseController.java    From httpkit with Apache License 2.0 2 votes vote down vote up
/**
 * 获取某个请求参数的值,并且将其作为Short返回
 * @author nan.li
 * @param key
 * @return
 */
public short getParamAsShort(String key)
{
    Validate.notEmpty(getParam(key), String.format("%s不能为空!", key));
    return Short.valueOf(getParam(key));
}