org.apache.commons.lang3.StringUtils.equalsIgnoreCase()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(134)

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

StringUtils.equalsIgnoreCase介绍

[英]Compares two CharSequences, returning true if they represent equal sequences of characters, ignoring case.

nulls are handled without exceptions. Two nullreferences are considered equal. Comparison is case insensitive.

StringUtils.equalsIgnoreCase(null, null)   = true 
StringUtils.equalsIgnoreCase(null, "abc")  = false 
StringUtils.equalsIgnoreCase("abc", null)  = false 
StringUtils.equalsIgnoreCase("abc", "abc") = true 
StringUtils.equalsIgnoreCase("abc", "ABC") = true

[中]比较两个字符序列,如果它们表示相等的字符序列,则返回true,忽略大小写。
空值的处理没有异常。两个空引用被视为相等。比较不区分大小写。

StringUtils.equalsIgnoreCase(null, null)   = true 
StringUtils.equalsIgnoreCase(null, "abc")  = false 
StringUtils.equalsIgnoreCase("abc", null)  = false 
StringUtils.equalsIgnoreCase("abc", "abc") = true 
StringUtils.equalsIgnoreCase("abc", "ABC") = true

代码示例

代码示例来源:origin: gocd/gocd

public boolean equals(Object o) {
  if (this == o) {
    return true;
  }
  if (!(o instanceof SubversionRevision)) {
    return false;
  }
  SubversionRevision that = (SubversionRevision) o;
  return StringUtils.equalsIgnoreCase(revision, that.revision);
}

代码示例来源:origin: knowm/XChange

@JsonCreator
public static CexioPositionType forValue(String value) {
 if (StringUtils.equalsIgnoreCase("long", value)) return LONG;
 else if (StringUtils.equalsIgnoreCase("short", value)) return SHORT;
 else return null;
}

代码示例来源:origin: gocd/gocd

static TriState toTriState(String agentConfigState) {
    if (StringUtils.isBlank(agentConfigState)) {
      return TriState.UNSET;
    } else if (StringUtils.equalsIgnoreCase(agentConfigState, "enabled")) {
      return TriState.TRUE;
    } else if (StringUtils.equalsIgnoreCase(agentConfigState, "disabled")) {
      return TriState.FALSE;
    } else {
      throw HaltApiResponses.haltBecauseOfReason("The value of `agent_config_state` can be one of `Enabled`, `Disabled` or null.");
    }
  }
}

代码示例来源:origin: pinterest/secor

private boolean shouldDecodeFromJsonMessage(String topic){
    if (StringUtils.isNotEmpty(messageFormatForAll) && StringUtils.equalsIgnoreCase(messageFormatForAll, JSON)) {
      return true;
    } else if (StringUtils.equalsIgnoreCase(messageFormatByTopic.getOrDefault(topic, ""), JSON)) {
      return true;
    }
    return false;
  }
}

代码示例来源:origin: gocd/gocd

/**
 * Ugly parsing of Exec output into some Elements. Gets called from StreamPumper.
 *
 * @param line the line of output to parse
 */
public synchronized void consumeLine(final String line) {
  // check if the output contains the error string
  if (StringUtils.isNotEmpty(errorStr)) {
    // YES: set error flag
    if (StringUtils.equalsIgnoreCase(line.trim(), errorStr)) {
      foundError = true;
    }
  }
} // consumeLine

代码示例来源:origin: Activiti/Activiti

@Override
public boolean handlesMode(final String mode) {
  return StringUtils.equalsIgnoreCase(mode, getDeploymentMode());
}

代码示例来源:origin: jeremylong/DependencyCheck

/**
 * Implements equals for Evidence.
 *
 * @param that an object to check the equality of.
 * @return whether the two objects are equal.
 */
@SuppressWarnings("deprecation")
@Override
public boolean equals(Object that) {
  if (this == that) {
    return true;
  }
  if (!(that instanceof Evidence)) {
    return false;
  }
  final Evidence e = (Evidence) that;
  //TODO the call to ObjectUtils.equals needs to be replaced when we
  //stop supporting Jenkins 1.6 requirement.
  return StringUtils.equalsIgnoreCase(name, e.name)
      && StringUtils.equalsIgnoreCase(source, e.source)
      && StringUtils.equalsIgnoreCase(value, e.value)
      && ObjectUtils.equals(confidence, e.confidence);
}

代码示例来源:origin: apache/incubator-gobblin

@Override
 public boolean apply(FieldSchema input) {
  return StringUtils.equalsIgnoreCase(input.getName(), DatePartitionHiveVersionFinder.this.partitionKeyName);
 }
};

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

protected boolean processedTabKeyMatchesTabName(String tabName, String candidateTabKey) {
  try {
    String processedCandidateTabKey = BLCMessageUtils.getMessage(candidateTabKey);
    boolean candidateTabKeyWasProcessed = !StringUtils.equals(candidateTabKey, processedCandidateTabKey);
    return candidateTabKeyWasProcessed && StringUtils.equalsIgnoreCase(tabName, processedCandidateTabKey);
  } catch (NoSuchMessageException e) {
    LOG.debug("No such message exists for " + candidateTabKey, e);
    return false;
  }
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * <p>Compares given <code>string</code> to a CharSequences vararg of <code>searchStrings</code>,
 * returning {@code true} if the <code>string</code> is equal to any of the <code>searchStrings</code>, ignoring case.</p>
 *
 * <pre>
 * StringUtils.equalsAnyIgnoreCase(null, (CharSequence[]) null) = false
 * StringUtils.equalsAnyIgnoreCase(null, null, null)    = true
 * StringUtils.equalsAnyIgnoreCase(null, "abc", "def")  = false
 * StringUtils.equalsAnyIgnoreCase("abc", null, "def")  = false
 * StringUtils.equalsAnyIgnoreCase("abc", "abc", "def") = true
 * StringUtils.equalsAnyIgnoreCase("abc", "ABC", "DEF") = true
 * </pre>
 *
 * @param string to compare, may be {@code null}.
 * @param searchStrings a vararg of strings, may be {@code null}.
 * @return {@code true} if the string is equal (case-insensitive) to any other element of <code>searchStrings</code>;
 * {@code false} if <code>searchStrings</code> is null or contains no matches.
 * @since 3.5
 */
public static boolean equalsAnyIgnoreCase(final CharSequence string, final CharSequence...searchStrings) {
  if (ArrayUtils.isNotEmpty(searchStrings)) {
    for (final CharSequence next : searchStrings) {
      if (equalsIgnoreCase(string, next)) {
        return true;
      }
    }
  }
  return false;
}

代码示例来源:origin: wuyouzhuguli/SpringAll

@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
  if (StringUtils.equalsIgnoreCase("/login/mobile", httpServletRequest.getRequestURI())
      && StringUtils.equalsIgnoreCase(httpServletRequest.getMethod(), "post")) {
    try {
      validateCode(new ServletWebRequest(httpServletRequest));
    } catch (ValidateCodeException e) {
      authenticationFailureHandler.onAuthenticationFailure(httpServletRequest, httpServletResponse, e);
      return;
    }
  }
  filterChain.doFilter(httpServletRequest, httpServletResponse);
}

代码示例来源:origin: wuyouzhuguli/SpringAll

@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
  if (StringUtils.equalsIgnoreCase("/login", httpServletRequest.getRequestURI())
      && StringUtils.equalsIgnoreCase(httpServletRequest.getMethod(), "post")) {
    try {
      validateCode(new ServletWebRequest(httpServletRequest));
    } catch (ValidateCodeException e) {
      authenticationFailureHandler.onAuthenticationFailure(httpServletRequest, httpServletResponse, e);
      return;
    }
  }
  filterChain.doFilter(httpServletRequest, httpServletResponse);
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

private boolean typeMatchesAdminSection(TypedEntity typedEntity, String sectionKey) {
  String urlType = StringUtils.substring(sectionKey, sectionKey.indexOf(":") + 1);
  if(!StringUtils.equalsIgnoreCase(typedEntity.getType().getType(), urlType)) {
    return false;
  }
  return true;
}

代码示例来源:origin: org.apache.commons/commons-lang3

@Test
public void testEqualsIgnoreCase() {
  assertTrue(StringUtils.equalsIgnoreCase(null, null));
  assertTrue(StringUtils.equalsIgnoreCase(FOO, FOO));
  assertTrue(StringUtils.equalsIgnoreCase(FOO, new String(new char[] { 'f', 'o', 'o' })));
  assertTrue(StringUtils.equalsIgnoreCase(FOO, new String(new char[] { 'f', 'O', 'O' })));
  assertFalse(StringUtils.equalsIgnoreCase(FOO, BAR));
  assertFalse(StringUtils.equalsIgnoreCase(FOO, null));
  assertFalse(StringUtils.equalsIgnoreCase(null, FOO));
  assertTrue(StringUtils.equalsIgnoreCase("",""));
  assertFalse(StringUtils.equalsIgnoreCase("abcd","abcd "));
}

代码示例来源:origin: liuyangming/ByteTCC

public void process(WatchedEvent event) throws Exception {
  if (EventType.NodeChildrenChanged.equals(event.getType())) {
    this.processNodeChildrenChanged(event);
  } else if (EventType.NodeDeleted.equals(event.getType())) {
    String application = CommonUtils.getApplication(this.endpoint);
    String parent = String.format("%s/%s/instances", CONSTANTS_ROOT_PATH, application);
    String current = event.getPath();
    String path = String.format("%s/%s", parent, this.endpoint);
    if (StringUtils.equalsIgnoreCase(path, current)) {
      this.initializeCurrentClusterInstanceConfigIfNecessary(false);
    } // end-if (StringUtils.equalsIgnoreCase(path, current))
  }
}

代码示例来源:origin: liuyangming/ByteTCC

private String getParticipantsIdentifier(Object proxy, Method method, Object[] args) throws Throwable {
  if (StringUtils.isBlank(this.identifier)) {
    return null;
  }
  RemoteNode remoteNode = CommonUtils.getRemoteNode(this.identifier);
  if (remoteNode == null) {
    return null;
  }
  String serverHost = remoteNode.getServerHost();
  String serviceKey = remoteNode.getServiceKey();
  int serverPort = remoteNode.getServerPort();
  if (StringUtils.isNotBlank(serviceKey) && StringUtils.equalsIgnoreCase(serviceKey, "null") == false) {
    return this.identifier;
  }
  Object application = this.getParticipantsApplication(proxy, method, args);
  return String.format("%s:%s:%s", serverHost, application, serverPort);
}

代码示例来源:origin: apache/nifi

public ACLProvider create(ZooKeeperClientConfig config){
  return StringUtils.equalsIgnoreCase(config.getAuthType(),SASL_AUTH_SCHEME) ? new SaslACLProvider(config) : new DefaultACLProvider();
}

代码示例来源:origin: liuyangming/ByteTCC

private void checkRemoteResourceDescriptor(RemoteResourceDescriptor descriptor) throws IllegalStateException {
  RemoteCoordinator transactionCoordinator = (RemoteCoordinator) this.beanFactory.getCompensableNativeParticipant();
  RemoteSvc nativeSvc = CommonUtils.getRemoteSvc(transactionCoordinator.getIdentifier());
  RemoteSvc parentSvc = CommonUtils.getRemoteSvc(String.valueOf(this.transactionContext.getPropagatedBy()));
  RemoteSvc remoteSvc = descriptor.getRemoteSvc();
  boolean nativeFlag = StringUtils.equalsIgnoreCase(remoteSvc.getServiceKey(), nativeSvc.getServiceKey());
  boolean parentFlag = StringUtils.equalsIgnoreCase(remoteSvc.getServiceKey(), parentSvc.getServiceKey());
  if (nativeFlag || parentFlag) {
    throw new IllegalStateException("Endpoint can not be its own remote branch!");
  } // end-if (nativeFlag || parentFlag)
}

代码示例来源:origin: wuyouzhuguli/SpringAll

private void validateCode(ServletWebRequest servletWebRequest) throws ServletRequestBindingException {
  ImageCode codeInSession = (ImageCode) sessionStrategy.getAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);
  String codeInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), "imageCode");
  if (StringUtils.isBlank(codeInRequest)) {
    throw new ValidateCodeException("验证码不能为空!");
  }
  if (codeInSession == null) {
    throw new ValidateCodeException("验证码不存在!");
  }
  if (codeInSession.isExpire()) {
    sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);
    throw new ValidateCodeException("验证码已过期!");
  }
  if (!StringUtils.equalsIgnoreCase(codeInSession.getCode(), codeInRequest)) {
    throw new ValidateCodeException("验证码不正确!");
  }
  sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);
}

代码示例来源:origin: wuyouzhuguli/SpringAll

private void validateCode(ServletWebRequest servletWebRequest) throws ServletRequestBindingException {
    String smsCodeInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), "smsCode");
    String mobileInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), "smsCode");

    SmsCode codeInSession = (SmsCode) sessionStrategy.getAttribute(servletWebRequest, ValidateController.SESSION_KEY_SMS_CODE + mobileInRequest);

    if (StringUtils.isBlank(smsCodeInRequest)) {
      throw new ValidateCodeException("验证码不能为空!");
    }
    if (codeInSession == null) {
      throw new ValidateCodeException("验证码不存在!");
    }
    if (codeInSession.isExpire()) {
      sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);
      throw new ValidateCodeException("验证码已过期!");
    }
    if (!StringUtils.equalsIgnoreCase(codeInSession.getCode(), smsCodeInRequest)) {
      throw new ValidateCodeException("验证码不正确!");
    }
    sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);

  }
}

相关文章

StringUtils类方法