當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。