org.apache.commons.lang.BooleanUtils类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(312)

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

BooleanUtils介绍

[英]Operations on boolean primitives and Boolean objects.

This class tries to handle null input gracefully. An exception will not be thrown for a null input. Each method documents its behaviour in more detail.

#ThreadSafe#
[中]对布尔基元和布尔对象的操作。
此类尝试优雅地处理null输入。不会为null输入引发异常。每种方法都更详细地记录了其行为。
#线程安全#

代码示例

代码示例来源:origin: alibaba/canal

public MessageSerializer(){
  this.filterTransactionEntry = BooleanUtils.toBoolean(System.getProperty("canal.instance.filter.transaction.entry",
    "false"));
}

代码示例来源:origin: commons-lang/commons-lang

/**
 * <p>Checks if a <code>Boolean</code> value is <i>not</i> <code>true</code>,
 * handling <code>null</code> by returning <code>true</code>.</p>
 *
 * <pre>
 *   BooleanUtils.isNotTrue(Boolean.TRUE)  = false
 *   BooleanUtils.isNotTrue(Boolean.FALSE) = true
 *   BooleanUtils.isNotTrue(null)          = true
 * </pre>
 *
 * @param bool  the boolean to check, null returns <code>true</code>
 * @return <code>true</code> if the input is null or false
 * @since 2.3
 */
public static boolean isNotTrue(Boolean bool) {
  return !isTrue(bool);
}

代码示例来源:origin: commons-lang/commons-lang

/**
 * <p>Converts a String to a boolean (optimised for performance).</p>
 * 
 * <p><code>'true'</code>, <code>'on'</code> or <code>'yes'</code>
 * (case insensitive) will return <code>true</code>. Otherwise,
 * <code>false</code> is returned.</p>
 * 
 * <p>This method performs 4 times faster (JDK1.4) than
 * <code>Boolean.valueOf(String)</code>. However, this method accepts
 * 'on' and 'yes' as true values.
 *
 * <pre>
 *   BooleanUtils.toBoolean(null)    = false
 *   BooleanUtils.toBoolean("true")  = true
 *   BooleanUtils.toBoolean("TRUE")  = true
 *   BooleanUtils.toBoolean("tRUe")  = true
 *   BooleanUtils.toBoolean("on")    = true
 *   BooleanUtils.toBoolean("yes")   = true
 *   BooleanUtils.toBoolean("false") = false
 *   BooleanUtils.toBoolean("x gti") = false
 * </pre>
 *
 * @param str  the String to check
 * @return the boolean value of the string, <code>false</code> if no match or the String is null
 */
public static boolean toBoolean(String str) {
  return toBoolean(toBooleanObject(str));
}

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

/**
 * Handles '/deepSearch' request.
 */
@GET
@Path("/deepSearch/{topoId}")
public Response deepSearch(@PathParam("topoId") String topologyId,
              @Context HttpServletRequest request) {
  String user = httpCredsHandler.getUserName(request);
  String searchString = request.getParameter("search-string");
  String numMatchesStr = request.getParameter("num-matches");
  String portStr = request.getParameter("port");
  String startFileOffset = request.getParameter("start-file-offset");
  String startByteOffset = request.getParameter("start-byte-offset");
  String searchArchived = request.getParameter("search-archived");
  String callback = request.getParameter(StormApiResource.callbackParameterName);
  String origin = request.getHeader("Origin");
  Boolean alsoSearchArchived = BooleanUtils.toBooleanObject(searchArchived);
  if (BooleanUtils.isTrue(alsoSearchArchived)) {
    numDeepSearchArchived.mark();
  } else {
    numDeepSearchNonArchived.mark();
  }
  try (Timer.Context t = deepSearchRequestDuration.time()) {
    return logSearchHandler.deepSearchLogsForTopology(topologyId, user, searchString, numMatchesStr, portStr, startFileOffset,
      startByteOffset, alsoSearchArchived, callback, origin);
  }
}

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

Boolean sessionTimeout = (Boolean) request.getAttribute("sessionTimeout");
if (StringUtils.isEmpty(failureUrl) && BooleanUtils.isNotTrue(sessionTimeout)) {
  failureUrl = defaultFailureUrl;
if (BooleanUtils.isTrue(sessionTimeout)) {
  failureUrl = "?sessionTimeout=true";

代码示例来源:origin: commons-lang/commons-lang

/**
 * Gets the value as a Boolean instance.
 * 
 * @return the value as a Boolean, never null
 */
public Object getValue() {
  return BooleanUtils.toBooleanObject(this.value);
}

代码示例来源:origin: SonarSource/sonarqube

if (BooleanUtils.isTrue(query.assigned())) {
 filters.put(IS_ASSIGNED_FILTER, existsQuery(FIELD_ISSUE_ASSIGNEE_UUID));
} else if (BooleanUtils.isFalse(query.assigned())) {
 filters.put(IS_ASSIGNED_FILTER, boolQuery().mustNot(existsQuery(FIELD_ISSUE_ASSIGNEE_UUID)));
if (BooleanUtils.isTrue(query.resolved())) {
 filters.put(isResolved, existsQuery(FIELD_ISSUE_RESOLUTION));
} else if (BooleanUtils.isFalse(query.resolved())) {
 filters.put(isResolved, boolQuery().mustNot(existsQuery(FIELD_ISSUE_RESOLUTION)));

代码示例来源:origin: commons-lang/commons-lang

/**
 * <p>Checks if a <code>Boolean</code> value is <i>not</i> <code>false</code>,
 * handling <code>null</code> by returning <code>true</code>.</p>
 *
 * <pre>
 *   BooleanUtils.isNotFalse(Boolean.TRUE)  = true
 *   BooleanUtils.isNotFalse(Boolean.FALSE) = false
 *   BooleanUtils.isNotFalse(null)          = true
 * </pre>
 *
 * @param bool  the boolean to check, null returns <code>true</code>
 * @return <code>true</code> if the input is null or true
 * @since 2.3
 */
public static boolean isNotFalse(Boolean bool) {
  return !isFalse(bool);
}

代码示例来源:origin: gentics/mesh

/**
 * Return the flag which indicates whether the created schema version should automatically be assigned to the branches which reference the schema.
 * 
 * @return
 */
default boolean getUpdateAssignedBranches() {
  String value = getParameter(UPDATE_ASSIGNED_BRANCHES_QUERY_PARAM_KEY);
  return BooleanUtils.toBooleanDefaultIfNull(BooleanUtils.toBooleanObject(value), true);
}

代码示例来源:origin: docker-java/docker-java

/**
 * ValidDeviceMode checks if the mode for device is valid or not.
 * Valid mode is a composition of r (read), w (write), and m (mknod).
 *
 * @link https://github.com/docker/docker/blob/6b4a46f28266031ce1a1315f17fb69113a06efe1/runconfig/opts/parse.go#L796
 */
private static boolean validDeviceMode(String deviceMode) {
  Map<String, Boolean> validModes = new HashMap<>(3);
  validModes.put("r", true);
  validModes.put("w", true);
  validModes.put("m", true);
  if (isEmpty(deviceMode)) {
    return false;
  }
  for (char ch : deviceMode.toCharArray()) {
    final String mode = String.valueOf(ch);
    if (isNotTrue(validModes.get(mode))) {
      return false; // wrong mode
    }
    validModes.put(mode, false);
  }
  return true;
}

代码示例来源:origin: commons-lang/commons-lang

/**
 * Gets this mutable as an instance of Boolean.
 *
 * @return a Boolean instance containing the value from this mutable, never null
 * @since 2.5
 */
public Boolean toBoolean() {
  return  BooleanUtils.toBooleanObject(this.value);
}

代码示例来源:origin: SonarSource/sonar-java

private static boolean isAlwaysFalseCondition(ExpressionTree expression) {
 if (expression.is(Tree.Kind.BOOLEAN_LITERAL)) {
  return BooleanUtils.isFalse(booleanLiteralValue(expression));
 }
 if (expression.is(Tree.Kind.LOGICAL_COMPLEMENT)) {
  ExpressionTree subExpression = ((UnaryExpressionTree) expression).expression();
  return BooleanUtils.isTrue(booleanLiteralValue(subExpression));
 }
 return false;
}

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

metadata.setBroadleafEnumeration("");
metadata.setReadOnly(false);
metadata.setRequiredOverride(BooleanUtils.isFalse(option.getRequired()));

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

.filter(logs -> logs != null && !logs.isEmpty());
if (BooleanUtils.isNotTrue(searchArchived)) {
  portsOfLogs = portsOfLogs.map(fl -> Collections.singletonList(first(fl)));
  } else {
    List<File> filteredLogs = logsForPort(user, portDir);
    if (BooleanUtils.isNotTrue(searchArchived)) {
      filteredLogs = Collections.singletonList(first(filteredLogs));
      fileOffset = 0;

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

@Override
protected Prompt acceptValidatedInput(ConversationContext context, String input) {
  return acceptValidatedInput(context, BooleanUtils.toBoolean(input));
}

代码示例来源:origin: SonarSource/sonarqube

@CheckForNull
private String getAssignee(Request request) {
 String assignee = emptyToNull(request.param(PARAM_ASSIGNEE));
 if (ASSIGN_TO_ME_VALUE.equals(assignee) || BooleanUtils.isTrue(request.paramAsBoolean(DEPRECATED_PARAM_ME))) {
  return userSession.getLogin();
 }
 return assignee;
}

代码示例来源:origin: commons-lang/commons-lang

/**
 * <p>Append to the <code>toString</code> an <code>Object</code>
 * value.</p>
 *
 * @param fieldName  the field name
 * @param obj  the value to add to the <code>toString</code>
 * @param fullDetail  <code>true</code> for detail,
 *  <code>false</code> for summary info
 * @return this
 */
public ToStringBuilder append(String fieldName, Object obj, boolean fullDetail) {
  style.append(buffer, fieldName, obj, BooleanUtils.toBooleanObject(fullDetail));
  return this;
}

代码示例来源:origin: org.codehaus.sonar-plugins.java/java-checks

private boolean isAlwaysFalseCondition(ExpressionTree expression) {
 if (expression.is(Tree.Kind.BOOLEAN_LITERAL)) {
  return BooleanUtils.isFalse(booleanLiteralValue(expression));
 }
 if (expression.is(Tree.Kind.LOGICAL_COMPLEMENT)) {
  ExpressionTree subExpression = ((UnaryExpressionTree) expression).expression();
  return BooleanUtils.isTrue(booleanLiteralValue(subExpression));
 }
 return false;
}

代码示例来源:origin: org.codehaus.sonar-plugins.java/java-checks

private boolean isOverriding(MethodTree tree) {
  // if overriding cannot be determined, we consider it is overriding to avoid FP.
  return !BooleanUtils.isFalse(((MethodTreeImpl) tree).isOverriding());
 }
}

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

if (p.getMetadata() instanceof BasicFieldMetadata && BooleanUtils.isNotTrue( p.getMetadata().getExcluded())) {
  ((BasicFieldMetadata) p.getMetadata()).setVisibility(VisibilityEnum.VISIBLE_ALL);
  entityFormProperties.add(p);

相关文章