org.javalite.common.Util.blank()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(258)

本文整理了Java中org.javalite.common.Util.blank()方法的一些代码示例,展示了Util.blank()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.blank()方法的具体详情如下:
包路径:org.javalite.common.Util
类名称:Util
方法名:blank

Util.blank介绍

[英]Returns true if value is either null or it's String representation is blank.
[中]如果值为null或其字符串表示形式为空,则返回true。

代码示例

代码示例来源:origin: javalite/activejdbc

  1. /**
  2. * @param source instance of String
  3. * @return null if source is empty or contains only whitespaces, source otherwise
  4. */
  5. @Override
  6. public Object convert(String source) {
  7. return blank(source) ? null : source;
  8. }
  9. }

代码示例来源:origin: javalite/activejdbc

  1. /**
  2. * @param source instance of String or null
  3. * @return source converted to java.sql.Date, or null if source is blank
  4. * @throws ParseException if conversion failed
  5. */
  6. @Override
  7. public java.sql.Date doConvert(String source) throws ParseException {
  8. return blank(source) ? null : new java.sql.Date(threadLocalFormat.get().parse(source).getTime());
  9. }
  10. }

代码示例来源:origin: javalite/activejdbc

  1. /**
  2. * @param source instance of String or null
  3. * @return source converted to java.sql.Timestamp, or null if source is blank
  4. * @throws ParseException if conversion failed
  5. */
  6. @Override
  7. public java.sql.Timestamp doConvert(String source) throws ParseException {
  8. return blank(source) ? null : new java.sql.Timestamp(threadLocalFormat.get().parse(source).getTime());
  9. }
  10. }

代码示例来源:origin: javalite/activejdbc

  1. /**
  2. * @return current environment as specified by environment variable <code>ACTIVE_ENV</code>
  3. * of <code>active_env</code> system property. System property value overrides environment variable.
  4. *
  5. * Defaults to "development" if no environment variable provided.
  6. */
  7. public String getEnvironment(){
  8. String env = "development";
  9. if(!blank(System.getenv("ACTIVE_ENV"))){
  10. env = System.getenv("ACTIVE_ENV");
  11. }
  12. if(!blank(System.getProperty("active_env"))){
  13. env = System.getProperty("active_env");
  14. }
  15. return env;
  16. }

代码示例来源:origin: javalite/activejdbc

  1. protected void appendSubQuery(StringBuilder queryBuilder, String subQuery) {
  2. if (!blank(subQuery)) {
  3. // this is only to support findFirst("order by..."), might need to revisit later
  4. if (!GROUP_BY_PATTERN.matcher(subQuery).find() && !ORDER_BY_PATTERN.matcher(subQuery).find()) {
  5. queryBuilder.append(" WHERE");
  6. }
  7. queryBuilder.append(' ').append(subQuery);
  8. }
  9. }

代码示例来源:origin: javalite/activejdbc

  1. /**
  2. * Returns name of environment, such as "development", "production", etc.
  3. * This is a value that is usually setup with an environment variable <code>ACTIVE_ENV</code>.
  4. *
  5. * @return name of environment
  6. */
  7. public static String getEnv(){
  8. if(ENV == null){
  9. if(!blank(System.getenv("ACTIVE_ENV"))) {
  10. ENV = System.getenv("ACTIVE_ENV");
  11. }
  12. if(!blank(System.getProperty("ACTIVE_ENV"))) {
  13. ENV = System.getProperty("ACTIVE_ENV");
  14. }
  15. if(!blank(System.getProperty("active_env"))) {
  16. ENV = System.getProperty("active_env");
  17. }
  18. if(blank(ENV)){
  19. ENV = "development";
  20. LogFilter.log(LOGGER, LogLevel.INFO, "Environment variable ACTIVE_ENV not provided, defaulting to '" + ENV + "'");
  21. }
  22. }
  23. return ENV;
  24. }

代码示例来源:origin: javalite/activejdbc

  1. /**
  2. * Overrides current environment's connection spec from system properties.
  3. */
  4. private void overrideFromEnvironmentVariables() {
  5. String url = System.getenv("ACTIVEJDBC.URL");
  6. String user = System.getenv("ACTIVEJDBC.USER");
  7. String password = System.getenv("ACTIVEJDBC.PASSWORD");
  8. String driver = System.getenv("ACTIVEJDBC.DRIVER");
  9. if(!blank(url) && !blank(user) && !blank(password) && !blank(driver)){
  10. connectionSpecMap.put(getEnvironment(), new ConnectionJdbcSpec(driver, url, user, password));
  11. }
  12. String jndi = System.getenv("ACTIVEJDBC.JNDI");
  13. if(!blank(jndi)){
  14. connectionSpecMap.put(getEnvironment(), new ConnectionJndiSpec(jndi));
  15. }
  16. }

代码示例来源:origin: javalite/activejdbc

  1. /**
  2. * Overrides current environment's connection spec from system properties.
  3. */
  4. private void overrideFromSystemProperties() {
  5. String url = System.getProperty("activejdbc.url");
  6. String user = System.getProperty("activejdbc.user");
  7. String password = System.getProperty("activejdbc.password");
  8. String driver = System.getProperty("activejdbc.driver");
  9. if(!blank(url) && !blank(user) && !blank(driver)){
  10. connectionSpecMap.put(getEnvironment(), new ConnectionJdbcSpec(driver, url, user, password));
  11. }
  12. String jndi = System.getProperty("activejdbc.jndi");
  13. if(!blank(jndi)){
  14. connectionSpecMap.put(getEnvironment(), new ConnectionJndiSpec(jndi));
  15. }
  16. }

代码示例来源:origin: javalite/activejdbc

  1. /**
  2. * TDS converts a number of important data types to String. This isn't what we want, nor helpful. Here, we change them back.
  3. */
  4. @Override
  5. public Object overrideDriverTypeConversion(MetaModel mm, String attributeName, Object value) {
  6. if (value instanceof String && !Util.blank(value)) {
  7. String typeName = mm.getColumnMetadata().get(attributeName).getTypeName();
  8. if ("date".equalsIgnoreCase(typeName)) {
  9. return java.sql.Date.valueOf((String) value);
  10. } else if ("datetime2".equalsIgnoreCase(typeName)) {
  11. return java.sql.Timestamp.valueOf((String) value);
  12. }
  13. }
  14. return value;
  15. }

代码示例来源:origin: javalite/activejdbc

  1. public RedisCacheManager() {
  2. try {
  3. String host = p("redis.cache.manager.host");
  4. String port = p("redis.cache.manager.port");
  5. jedisPool = blank(host) || blank(port) ? new JedisPool() : new JedisPool(host,toInteger(port));
  6. } catch (Exception e) {
  7. throw new InitException("Failed to configure connection to Redis server", e);
  8. }
  9. }

代码示例来源:origin: javalite/activejdbc

  1. @Override
  2. public void convert(Model m) {
  3. Object val = m.get(attributeName);
  4. if (!(val instanceof java.util.Date) && !blank(val)) {
  5. try {
  6. long time = df.parse(val.toString()).getTime();
  7. java.sql.Date d = new java.sql.Date(time);
  8. m.set(attributeName, d);
  9. } catch (ParseException e) {
  10. m.addValidator(this, attributeName);
  11. }
  12. }
  13. }

代码示例来源:origin: javalite/activejdbc

  1. @Override
  2. public void convert(Model m) {
  3. Object val = m.get(attributeName);
  4. if (!(val instanceof Timestamp) && !blank(val)) {
  5. try {
  6. long time = df.parse(val.toString()).getTime();
  7. Timestamp t = new Timestamp(time);
  8. m.set(attributeName, t);
  9. } catch(ParseException e) {
  10. m.addValidator(this, attributeName);
  11. }
  12. }
  13. }

代码示例来源:origin: javalite/activejdbc

  1. @Override
  2. public void validate(Model m) {
  3. if (blank(m.get(attribute))) {
  4. //TODO: use resource bundles for messages
  5. m.addValidator(this, attribute);
  6. }
  7. }

代码示例来源:origin: javalite/activejdbc

  1. for (String line : lines) {
  2. line = line.trim();
  3. if (!commentLine(line) && !blank(line)) {
  4. if (line.startsWith(DELIMITER_KEYWORD)) {
  5. delimiter = line.substring(10).trim();
  6. } else if (line.endsWith(delimiter)) {
  7. currentStatement += line.substring(0, line.length() - delimiter.length()) ;
  8. if(!blank(currentStatement)){
  9. statements.add(currentStatement);
  10. if(!blank(currentStatement)){
  11. statements.add(currentStatement);

代码示例来源:origin: javalite/activejdbc

  1. break;
  2. case XMLStreamConstants.END_ELEMENT:
  3. if (attr != null && !blank(chars)) {
  4. res.put(attr, chars);

代码示例来源:origin: javalite/activejdbc

  1. private static String exec(String command) {
  2. Runtime runtime = Runtime.getRuntime();
  3. try {
  4. Process p = runtime.exec(command);
  5. String output = read(p.getInputStream());
  6. String error = read(p.getErrorStream());
  7. if (!blank(error)) {
  8. throw new ExecException(error);
  9. }
  10. return output;
  11. } catch (ExecException e) {
  12. throw e;
  13. } catch (Exception e) {
  14. throw new ExecException(e);
  15. }
  16. }
  17. }

代码示例来源:origin: javalite/activejdbc

  1. @Override
  2. public Object overrideDriverTypeConversion(MetaModel mm, String attributeName, Object value) {
  3. // SQLite returns DATE and DATETIME as String or Number values
  4. if (value instanceof String && !Util.blank(value) || value instanceof Number) {
  5. String typeName = mm.getColumnMetadata().get(attributeName).getTypeName();
  6. if ("DATE".equalsIgnoreCase(typeName)) {
  7. return Convert.toSqlDate(value);
  8. } else if ("DATETIME".equalsIgnoreCase(typeName)) {
  9. return Convert.toTimestamp(value);
  10. } else if ("TIME".equalsIgnoreCase(typeName)) {
  11. return Convert.toTime(value);
  12. }
  13. }
  14. return value;
  15. }

代码示例来源:origin: javalite/activejdbc

  1. private static int update(MetaModel metaModel, String updates, String conditions, Object... params) {
  2. StringBuilder sql = new StringBuilder().append("UPDATE ").append(metaModel.getTableName()).append(" SET ");
  3. Object[] allParams;
  4. if (metaModel.hasAttribute("updated_at")) {
  5. sql.append("updated_at = ?, ");
  6. allParams = new Object[params.length + 1];
  7. allParams[0] = new Timestamp(System.currentTimeMillis());
  8. System.arraycopy(params, 0, allParams, 1, params.length);
  9. } else {
  10. allParams = params;
  11. }
  12. sql.append(updates);
  13. if (!blank(conditions)) {
  14. sql.append(" WHERE ").append(conditions);
  15. }
  16. int count = new DB(metaModel.getDbName()).exec(sql.toString(), allParams);
  17. if (metaModel.cached()) {
  18. Registry.cacheManager().purgeTableCache(metaModel);
  19. }
  20. return count;
  21. }

代码示例来源:origin: com.github.tchoulihan/activejdbc

  1. /**
  2. * @param source instance of String or null
  3. * @return source converted to java.sql.Date, or null if source is blank
  4. * @throws ParseException if conversion failed
  5. */
  6. @Override
  7. public java.sql.Date doConvert(String source) throws ParseException {
  8. return blank(source) ? null : new java.sql.Date(threadLocalFormat.get().parse(source).getTime());
  9. }
  10. }

代码示例来源:origin: org.javalite/activejdbc

  1. protected void appendSubQuery(StringBuilder queryBuilder, String subQuery) {
  2. if (!blank(subQuery)) {
  3. // this is only to support findFirst("order by..."), might need to revisit later
  4. if (!GROUP_BY_PATTERN.matcher(subQuery).find() && !ORDER_BY_PATTERN.matcher(subQuery).find()) {
  5. queryBuilder.append(" WHERE");
  6. }
  7. queryBuilder.append(' ').append(subQuery);
  8. }
  9. }

相关文章