Tabnine Logo
StringUtils
Code IndexAdd Tabnine to your IDE (free)

How to use
StringUtils
in
org.apache.commons.lang

Best Java code snippets using org.apache.commons.lang.StringUtils (Showing top 20 results out of 38,826)

origin: alibaba/canal

public void putQueryString(String name, String value) {
  if (StringUtils.isBlank(name) || StringUtils.isBlank(value)) {
    return;
  }
  treeMap.put(name, value);
}
origin: alibaba/canal

  private static String chooseSocketChannel() {
    String socketChannel = System.getenv("canal.socketChannel");
    if (StringUtils.isEmpty(socketChannel)) {
      socketChannel = System.getProperty("canal.socketChannel");
    }

    if (StringUtils.isEmpty(socketChannel)) {
      socketChannel = "bio"; // bio or netty
    }

    return socketChannel;
  }
}
origin: alibaba/canal

public Boolean hasFilter() {
  if (filter == null) {
    return false;
  }
  return StringUtils.isNotBlank(filter);
}
origin: alibaba/canal

public boolean isLastFile(String fileName) {
  String needCompareName = lastDownload;
  if (StringUtils.isNotEmpty(needCompareName) && StringUtils.endsWith(needCompareName, "tar")) {
    needCompareName = needCompareName.substring(0, needCompareName.indexOf("."));
  }
  return (needCompareName == null || fileName.equalsIgnoreCase(needCompareName)) && binlogList.isEmpty();
}
origin: jenkinsci/jenkins

@Override
public void checkName(String name) {
  if (StringUtils.isNotBlank(namePattern) && StringUtils.isNotBlank(name)) {
    if (!Pattern.matches(namePattern, name)) {
      throw new Failure(StringUtils.isEmpty(description) ?
        Messages.Hudson_JobNameConventionNotApplyed(name, namePattern) :
        description);
    }
  }
}
origin: SonarSource/sonarqube

@CheckForNull
private static String checkCsrf(@Nullable String csrfState, @Nullable String stateInHeader) {
 if (isBlank(csrfState)) {
  return "Missing reference CSRF value";
 }
 if (!StringUtils.equals(csrfState, stateInHeader)) {
  return "Wrong CSFR in request";
 }
 return null;
}
origin: alibaba/canal

public AviaterRegexFilter(String pattern, boolean defaultEmptyValue){
  this.defaultEmptyValue = defaultEmptyValue;
  List<String> list = null;
  if (StringUtils.isEmpty(pattern)) {
    list = new ArrayList<String>();
  } else {
    String[] ss = StringUtils.split(pattern, SPLIT);
    list = Arrays.asList(ss);
  }
  // 对pattern按照从长到短的排序
  // 因为 foo|foot 匹配 foot 会出错,原因是 foot 匹配了 foo 之后,会返回 foo,但是 foo 的长度和 foot
  // 的长度不一样
  Collections.sort(list, COMPARATOR);
  // 对pattern进行头尾完全匹配
  list = completionPattern(list);
  this.pattern = StringUtils.join(list, PATTERN_SPLIT);
}
origin: jenkinsci/jenkins

public String getChoicesText() {
  return StringUtils.join(choices, "\n");
}
origin: alibaba/canal

public void setUrl(String url) {
  if (StringUtils.isNotEmpty(url)) {
    this.url = url;
  }
}
origin: SonarSource/sonarqube

private static void addFile(Node root, ScannerReport.Component file) {
 Preconditions.checkArgument(!StringUtils.isEmpty(file.getProjectRelativePath()), "Files should have a project relative path: " + file);
 String[] split = StringUtils.split(file.getProjectRelativePath(), '/');
 Node currentNode = root;
 for (int i = 0; i < split.length; i++) {
  currentNode = currentNode.children().computeIfAbsent(split[i], k -> new Node());
 }
 currentNode.reportComponent = file;
}
origin: alibaba/canal

/**
 * 'utf8' COLLATE 'utf8_general_ci'
 * 
 * @param charset
 * @return
 */
public static final String collateCharset(String charset) {
  String[] output = StringUtils.split(charset, "COLLATE");
  return output[0].replace('\'', ' ').trim();
}
origin: jenkinsci/jenkins

/**
 * {@inheritDoc}
 */
@Override
public boolean equals(@Nonnull String id1, @Nonnull String id2) {
  return StringUtils.equals(id1, id2);
}
origin: SonarSource/sonarqube

 public MinimumViableSystem checkRequiredJavaOptions(Map<String, String> requiredJavaOptions) {
  for (Map.Entry<String, String> entry : requiredJavaOptions.entrySet()) {
   String value = System.getProperty(entry.getKey());
   if (!StringUtils.equals(value, entry.getValue())) {
    throw new MessageException(format(
     "JVM option '%s' must be set to '%s'. Got '%s'", entry.getKey(), entry.getValue(), StringUtils.defaultString(value)));
   }
  }
  return this;
 }
}
origin: thinkaurelius/titan

  @Override
  public String toString() {
    return "Config[hostnames=" + StringUtils.join(hostnames, ',') + ", port=" + port
        + ", timeoutMS=" + timeoutMS + ", frameSize=" + frameSize
        + "]";
  }
}
origin: apache/storm

private static String getLocalMavenRepositoryPath() {
  String userHome = System.getProperty("user.home");
  if (StringUtils.isNotEmpty(userHome)) {
    return userHome + File.separator + ".m2" + File.separator + "repository";
  }
  return null;
}
origin: alibaba/canal

  /**
   * 判断当前的entry和position是否相同
   */
  public static boolean checkPosition(Event event, LogPosition logPosition) {
    EntryPosition position = logPosition.getPostion();
    boolean result = position.getTimestamp().equals(event.getExecuteTime());

    boolean exactely = (StringUtils.isBlank(position.getJournalName()) && position.getPosition() == null);
    if (!exactely) {// 精确匹配
      result &= position.getPosition().equals(event.getPosition());
      if (result) {// short path
        result &= StringUtils.equals(event.getJournalName(), position.getJournalName());
      }
    }

    return result;
  }
}
origin: alibaba/jstorm

private Map<String, String> parseRawQuery(String uriRawQuery) {
  Map<String, String> paramMap = Maps.newHashMap();
  for (String param : StringUtils.split(uriRawQuery, "&")) {
    String[] pair = StringUtils.split(param, "=");
    if (pair.length == 2) {
      paramMap.put(pair[0], pair[1]);
    }
  }
  return paramMap;
}
origin: jenkinsci/jenkins

/**
 * {@inheritDoc}
 */
@Override
public boolean equals(@Nonnull String id1, @Nonnull String id2) {
  return StringUtils.equals(keyFor(id1), keyFor(id2));
}
origin: alibaba/nacos

public int aggrConfigInfoCount(String dataId, String group, String tenant) {
  String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
  String sql = " SELECT COUNT(ID) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
  Integer result = jt.queryForObject(sql, Integer.class, new Object[] {dataId, group, tenantTmp});
  if (result == null) {
    throw new IllegalArgumentException("aggrConfigInfoCount error");
  }
  return result.intValue();
}
origin: apache/storm

private void assertMandatoryParameterNotEmpty(String paramValue, String fieldName) {
  if (StringUtils.isEmpty(paramValue)) {
    throw new IllegalArgumentException(fieldName + " should be provided.");
  }
}
org.apache.commons.langStringUtils

Javadoc

Operations on java.lang.String that are null safe.

  • IsEmpty/IsBlank - checks if a String contains text
  • Trim/Strip - removes leading and trailing whitespace
  • Equals - compares two strings null-safe
  • startsWith - check if a String starts with a prefix null-safe
  • endsWith - check if a String ends with a suffix null-safe
  • IndexOf/LastIndexOf/Contains - null-safe index-of checks
  • IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut - index-of any of a set of Strings
  • ContainsOnly/ContainsNone/ContainsAny - does String contains only/none/any of these characters
  • Substring/Left/Right/Mid - null-safe substring extractions
  • SubstringBefore/SubstringAfter/SubstringBetween - substring extraction relative to other strings
  • Split/Join - splits a String into an array of substrings and vice versa
  • Remove/Delete - removes part of a String
  • Replace/Overlay - Searches a String and replaces one String with another
  • Chomp/Chop - removes the last part of a String
  • LeftPad/RightPad/Center/Repeat - pads a String
  • UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize - changes the case of a String
  • CountMatches - counts the number of occurrences of one String in another
  • IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable - checks the characters in a String
  • DefaultString - protects against a null input String
  • Reverse/ReverseDelimited - reverses a String
  • Abbreviate - abbreviates a string using ellipsis
  • Difference - compares Strings and reports on their differences
  • LevensteinDistance - the number of changes needed to change one String into another

The StringUtils class defines certain words related to String handling.

  • null - null
  • empty - a zero-length string ("")
  • space - the space character (' ', char 32)
  • whitespace - the characters defined by Character#isWhitespace(char)
  • trim - the characters <= 32 as in String#trim()

StringUtils handles null input Strings quietly. That is to say that a null input will return null. Where a boolean or int is being returned details vary by method.

A side effect of the null handling is that a NullPointerException should be considered a bug in StringUtils (except for deprecated methods).

Methods in this class give sample code to explain their operation. The symbol * is used to indicate any input including null.

#ThreadSafe#

Most used methods

  • isBlank
    Checks if a String is whitespace, empty ("") or null. StringUtils.isBlank(null) = true Stri
  • isEmpty
    Checks if a String is empty ("") or null. StringUtils.isEmpty(null) = true StringUtils.isEm
  • isNotBlank
    Checks if a String is not empty (""), not null and not whitespace only. StringUtils.isNotBlank(nu
  • join
    Joins the elements of the provided array into a single String containing the provided list of elemen
  • isNotEmpty
    Checks if a String is not empty ("") and not null. StringUtils.isNotEmpty(null) = false Str
  • split
    Splits the provided text into an array with a maximum length, separators specified. The separator i
  • equals
    Compares two Strings, returning true if they are equal. nulls are handled without exceptions. Two n
  • replace
    Replaces a String with another String inside a larger String, for the first max values of the searc
  • trim
    Removes control characters (char <= 32) from both ends of this String, handling null by returningnu
  • capitalize
    Capitalizes a String changing the first letter to title case as per Character#toTitleCase(char). No
  • contains
    Checks if String contains a search String, handling null. This method uses String#indexOf(String).
  • substringAfter
    Gets the substring after the first occurrence of a separator. The separator is not returned. A null
  • contains,
  • substringAfter,
  • removeEnd,
  • equalsIgnoreCase,
  • repeat,
  • defaultString,
  • substringBefore,
  • isNumeric,
  • substringAfterLast,
  • removeStart

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getSystemService (Context)
  • requestLocationUpdates (LocationManager)
  • setRequestProperty (URLConnection)
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • JFileChooser (javax.swing)
  • JList (javax.swing)
  • JOptionPane (javax.swing)
  • JTable (javax.swing)
  • Join (org.hibernate.mapping)
  • PhpStorm for WordPress
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now