当前位置: 首页>>代码示例>>Java>>正文


Java BooleanUtils.toBoolean方法代码示例

本文整理汇总了Java中org.apache.commons.lang3.BooleanUtils.toBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java BooleanUtils.toBoolean方法的具体用法?Java BooleanUtils.toBoolean怎么用?Java BooleanUtils.toBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang3.BooleanUtils的用法示例。


在下文中一共展示了BooleanUtils.toBoolean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: call

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
@Override
public Object call(Element element, List<SyntaxNode> params) {
    if (params.size() == 0) {
        return false;
    }
    Object calc = params.get(0).calc(element);
    if (calc == null) {
        return false;
    }
    if (calc instanceof Boolean) {
        return calc;
    }
    if (calc instanceof String) {
        return BooleanUtils.toBoolean(calc.toString());
    }
    if (calc instanceof Integer) {
        return calc != 0;
    }
    if (calc instanceof Number) {
        return ((Number) calc).doubleValue() > 0D;
    }
    return false;
}
 
开发者ID:virjar,项目名称:sipsoup,代码行数:24,代码来源:BooleanFunction.java

示例2: buildByTokenHolder

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
private SyntaxNode buildByTokenHolder(TokenHolder tokenHolder) {
    if (tokenHolder.tokenType == TokenType.Expression) {
        return new ExpressionParser(new StringFunctionTokenQueue(tokenHolder.data)).parse();
    }
    if (tokenHolder.tokenType == TokenType.Function) {
        return parseFunction(new StringFunctionTokenQueue(tokenHolder.data));
    }
    if (tokenHolder.tokenType == TokenType.String) {
        return new StringSyntaxNode(tokenHolder.data);
    }
    if (tokenHolder.tokenType == TokenType.Boolean) {
        return new BooleanSyntaxNode(BooleanUtils.toBoolean(tokenHolder.data));
    }
    if (tokenHolder.tokenType == TokenType.Number) {
        if (tokenHolder.data.contains(".")) {
            return new NumberSyntaxNode(NumberUtils.toDouble(tokenHolder.data));
        } else {
            return new NumberSyntaxNode(NumberUtils.toInt(tokenHolder.data));
        }
    }
    throw new IllegalStateException("unknown token type: " + tokenHolder.tokenType);
}
 
开发者ID:virjar,项目名称:vscrawler,代码行数:23,代码来源:ExpressionParser.java

示例3: handleException

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
/**
 * 处理异常。如果是 AJAX 请求,以 JSON 格式返回;如果是普通请求,dispatch 到错误页面。
 */
private Object handleException(Exception e, int status, String message, ServletWebRequest request) {
    Map<String, Object> errorResponse = getErrorResponse(e, message);

    // 如果开启 debug,则将 debug 标记写入 error response 中
    boolean isDebug = BooleanUtils.toBoolean(request.getParameter("debug"));
    logger.debug("Debug is {}", isDebug ? "on" : "off");
    if (isDebug) {
        errorResponse.put("debug", true);
    }

    // AJAX 请求需要手工指定 status
    if (isAjaxRequest(request)) {
        request.getResponse().setStatus(status);
        return errorResponse;
    }

    // 如果是普通请求,dispatch 到错误页面
    String exName = e.getClass().getName();
    String exView = StringUtils.defaultString(exceptionMappings.get(exName), defaultErrorView);
    return new ModelAndView(exView, errorResponse);
}
 
开发者ID:akuma,项目名称:meazza,代码行数:25,代码来源:DefaultControllerAdvice.java

示例4: AccessibilityReportConfiguration

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
public AccessibilityReportConfiguration(Map<String, String> params) {
  if (params.containsKey(PARAM_SHOW_EXCLUDED)) {
    showExcluded = BooleanUtils.toBoolean(params.get(PARAM_SHOW_EXCLUDED));
  }

  if (params.containsKey(PARAM_IGNORE_NOTICE)) {
    ignoreNotice = BooleanUtils.toBoolean(params.get(PARAM_IGNORE_NOTICE));
  }

  String reportLevelString = StringUtils
      .defaultString(params.get(PARAM_REPORT_LEVEL), DEFAULT_REPORT_LEVEL);
  if (!ignoreNotice) {
    reportLevelString = IssueType.NOTICE.toString();
  }

  IssueType reportLevel;
  reportLevel = IssueType.valueOf(reportLevelString.toUpperCase());

  showNotice = IssueType.NOTICE.compareTo(reportLevel) <= 0;
  showWarning = IssueType.WARN.compareTo(reportLevel) <= 0;
}
 
开发者ID:Cognifide,项目名称:aet,代码行数:22,代码来源:AccessibilityReportConfiguration.java

示例5: createSvnCredentials

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
/**
 * Creates the String to include SVN user and password in the command if necessary.
 * @return
 */
public static String createSvnCredentials() {
  boolean isSvnUsingCredentials =
      BooleanUtils.toBoolean( PropertiesUtil.getString("svn.enable.password.auth"));
  String credentials;
  if (isSvnUsingCredentials){
    String user = PropertiesUtil.getString("svn.username");
    String password = PropertiesUtil.getString("svn.password");
    credentials = String.format(SvnOperationsEnum.SVN_CREDENTIALS, user, password);
  } else {
    credentials = "";
  }
  return credentials;
}
 
开发者ID:lpavone,项目名称:SVNAutoMerger,代码行数:18,代码来源:SvnUtils.java

示例6: toBoolean

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
/**
 * 转换为Boolean类型
 * 'true', 'on', 'y', 't', 'yes' or '1' (case insensitive) will return true. Otherwise, false is returned.
 */
public static Boolean toBoolean(final Object val) {
    if (val == null) {
        return false;
    }
    return BooleanUtils.toBoolean(val.toString()) || "1".equals(val.toString());
}
 
开发者ID:NeilRen,项目名称:NEILREN4J,代码行数:11,代码来源:StringUtils.java

示例7: mapToInternal

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
/**
 * Convert Map to InternalMessage
 *
 * @param map Map
 * @return InternalMessage
 */
public static InternalMessage mapToInternal(Map<String, String> map) {
    if (map == null || map.isEmpty()) return null;

    int type = Integer.parseInt(map.get("type"));
    if (type == MqttMessageType.PUBLISH.value()) {
        byte[] payload = null;
        if (map.get("payload") != null) try {
            payload = map.get("payload").getBytes("ISO-8859-1");
        } catch (UnsupportedEncodingException ignore) {
        }
        return new InternalMessage<>(
                MqttMessageType.PUBLISH,
                BooleanUtils.toBoolean(map.getOrDefault("dup", "0"), "1", "0"),
                MqttQoS.valueOf(Integer.parseInt(map.getOrDefault("qos", "0"))),
                BooleanUtils.toBoolean(map.getOrDefault("retain", "0"), "1", "0"),
                MqttVersion.valueOf(map.getOrDefault("version", MqttVersion.MQTT_3_1_1.toString())),
                map.get("clientId"),
                map.get("userName"),
                null,
                new Publish(
                        map.get("topicName"),
                        Integer.parseInt(map.getOrDefault("packetId", "0")),
                        payload
                ));
    } else if (type == MqttMessageType.PUBREL.value()) {
        return new InternalMessage<>(
                MqttMessageType.PUBREL,
                false,
                MqttQoS.AT_LEAST_ONCE,
                false,
                MqttVersion.valueOf(map.getOrDefault("version", MqttVersion.MQTT_3_1_1.toString())),
                map.get("clientId"),
                map.get("userName"),
                null,
                new PacketId(Integer.parseInt(map.getOrDefault("packetId", "0"))));
    } else {
        throw new IllegalArgumentException("Invalid in-flight MQTT message type: " + MqttMessageType.valueOf(type));
    }
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:46,代码来源:Converter.java

示例8: toBoolean

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
/**
 * 转换为Boolean类型
 * 'true', 'on', 'y', 't', 'yes' or '1' (case insensitive) will return true. Otherwise, false is returned.
 */
public static Boolean toBoolean(final Object val){
	if (val == null){
		return false;
	}
	return BooleanUtils.toBoolean(val.toString()) || "1".equals(val.toString());
}
 
开发者ID:egojit8,项目名称:easyweb,代码行数:11,代码来源:StringUtils.java

示例9: login

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
/**
 * 登录
 */
@RequestMapping(value = "/sys/login", method = RequestMethod.POST)
public Map<String, Object> login(String username, String password, String captcha) throws IOException {
    //是否开启验证码
    if (BooleanUtils.toBoolean(this.captcha.getIsOpen())) {
        String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY);
        if (!captcha.equalsIgnoreCase(kaptcha)) {
            return Result.error("验证码不正确");
        }
    }

    //用户信息
    SysUserEntity user = sysUserService.queryByUserName(username);

    //账号不存在、密码错误
    if (user == null || !user.getPassword().equals(new Sha256Hash(password, user.getSalt()).toHex())) {
        return Result.error("账号或密码不正确");
    }

    //账号锁定
    if (user.getStatus() == 0) {
        return Result.error("账号已被锁定,请联系管理员");
    }

    //生成token,并保存到数据库
    try {
        return sysUserTokenService.createToken(user.getUserId());
    } catch (Exception e) {
        log.error("生产token异常", e);
        return Result.error("生产token异常");
    }
}
 
开发者ID:davichi11,项目名称:my-spring-boot-project,代码行数:35,代码来源:SysLoginController.java

示例10: flush

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
@Http("/flush")
public void flush(final HttpServletRequest req,
                  final HttpServletResponse resp) throws ModuleException, IOException {
    final String isForceString = getParamWithDefault(req, "force", EMPTY);
    final boolean isForce = BooleanUtils.toBoolean(isForceString);
    moduleManager.flush(isForce);
    output(resp.getWriter(), "module flush finished, total=%s;", moduleManager.list().size());
}
 
开发者ID:alibaba,项目名称:jvm-sandbox,代码行数:9,代码来源:ModuleMgrModule.java

示例11: MigrationBrokerDefinitionAdaptor

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
/**
 * Creates instance of the adaptor.
 *
 * @param def broker definition
 * @throws InvalidDefinitionException if invalid definition
 */
public MigrationBrokerDefinitionAdaptor(EntityDefinition def) throws InvalidDefinitionException {
  super(def);
  if (StringUtils.trimToEmpty(def.getType()).isEmpty()) {
    def.setType(MigrationConnector.TYPE);
  } else if (!MigrationConnector.TYPE.equals(def.getType())) {
    throw new InvalidDefinitionException("Broker definition doesn't match");
  } else {
    jndi = get(P_JNDI_NAME);
    preserveUuids = BooleanUtils.toBoolean(get(P_PRESERVE_UUIDS));
  }
}
 
开发者ID:Esri,项目名称:geoportal-server-harvester,代码行数:18,代码来源:MigrationBrokerDefinitionAdaptor.java

示例12: parseBooleanOrNull

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
/**
 * Parses an arbitrary object for a boolean. If it can't be found, return null.
 *
 * @param value Object to parse for an boolean
 * @return if parsing fails, return null
 */
public static Boolean parseBooleanOrNull(final Object value) {
    if (value == null) {
        return null;
    }

    if (value instanceof Boolean) {
        return (Boolean)value;
    }

    final String string = StringUtils.strip(toStringEmptyToNull(value));

    if (string == null) {
        return null;
    }

    Boolean parsed;

    try {
        parsed = BooleanUtils.toBoolean(string);
    } catch (Exception e) {
        Logger logger = LoggerFactory.getLogger(CloudApiUtils.class);
        String msg = "Error parsing value as boolean. Value: %s";
        logger.warn(String.format(msg, value), e);
        parsed = null;
    }

    return parsed;
}
 
开发者ID:joyent,项目名称:java-triton,代码行数:35,代码来源:CloudApiUtils.java

示例13: convertKeys

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
public Object convertKeys(String key) {
	if (BooleanUtils.toBooleanObject(key) != null) {
		return BooleanUtils.toBoolean(key);
	} else if (NumberUtils.isNumber(key) && (key.contains(",") || key.contains("."))) {
		return NumberUtils.toFloat(key);
	} else if (NumberUtils.isNumber(key)) {
		return NumberUtils.toInt(key);
	} else {
		return key;
	}
}
 
开发者ID:daflockinger,项目名称:spongeblog,代码行数:12,代码来源:PaginationMapper.java

示例14: configureShowFilter

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
/**
 * Configure {@link GetCollectionTimelineNoteParameter} note parameter for showing direct
 * messages OR notes for me OR only followed items - it is an OR relationship
 *
 * @param getCollectionTimelineNoteParameter
 *            {@link GetCollectionTimelineNoteParameter}
 */
private void configureShowFilter(
        GetCollectionTimelineNoteParameter getCollectionTimelineNoteParameter) {
    boolean showDirectMessages = BooleanUtils.toBoolean(getCollectionTimelineNoteParameter
            .getF_showDirectMessages());
    boolean showNotesForMe = BooleanUtils.toBoolean(getCollectionTimelineNoteParameter
            .getF_showNotesForMe());
    boolean showFollowedItems = BooleanUtils.toBoolean(getCollectionTimelineNoteParameter
            .getF_showFollowedItems());

    if ((showDirectMessages ? 1 : 0) + (showNotesForMe ? 1 : 0) + (showFollowedItems ? 1 : 0) > 1) {
        getCollectionTimelineNoteParameter.setOffset(0);
    }
    if (showDirectMessages) {
        getCollectionTimelineNoteParameter.setF_showNotesForMe(true);
        getCollectionTimelineNoteParameter.setF_showNotesForMe(false);
        getCollectionTimelineNoteParameter.setF_showFollowedItems(false);
    }
    if (showNotesForMe) {
        getCollectionTimelineNoteParameter.setF_showDirectMessages(false);
        getCollectionTimelineNoteParameter.setF_showNotesForMe(true);
        getCollectionTimelineNoteParameter.setF_showFollowedItems(false);
    }
    if (showFollowedItems) {
        getCollectionTimelineNoteParameter.setF_showDirectMessages(false);
        getCollectionTimelineNoteParameter.setF_showNotesForMe(false);
        getCollectionTimelineNoteParameter.setF_showFollowedItems(true);
    }
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:36,代码来源:TimelineNoteResourceHandler.java

示例15: readResolve

import org.apache.commons.lang3.BooleanUtils; //导入方法依赖的package包/类
private Object readResolve() {
    // TODO: this should be done better
    ActionContext ac = ActionContext.getContext();
    Container cont = ac.getContainer();
    XWorkConverter xworkConverter = cont.getInstance(XWorkConverter.class);
    CompoundRootAccessor accessor = (CompoundRootAccessor) cont.getInstance(PropertyAccessor.class, CompoundRoot.class.getName());
    TextProvider prov = cont.getInstance(TextProvider.class, "system");
    boolean allow = BooleanUtils.toBoolean(cont.getInstance(String.class, XWorkConstants.ALLOW_STATIC_METHOD_ACCESS));
    OgnlValueStack aStack = new OgnlValueStack(xworkConverter, accessor, prov, allow);
    aStack.setOgnlUtil(cont.getInstance(OgnlUtil.class));
    aStack.setRoot(xworkConverter, accessor, this.root, allow);

    return aStack;
}
 
开发者ID:txazo,项目名称:struts2,代码行数:15,代码来源:OgnlValueStack.java


注:本文中的org.apache.commons.lang3.BooleanUtils.toBoolean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。