org.apache.shiro.util.Assert.state()方法的使用及代码示例

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

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

Assert.state介绍

[英]Assert a boolean expression, throwing IllegalStateExceptionif the test result is false.

Call #isTrue(boolean) if you wish to throw IllegalArgumentException on an assertion failure.

Assert.state(id == null);

[中]断言一个布尔表达式,如果测试结果为false,则抛出IllegalStateException。
如果希望在断言失败时抛出IllegalArgumentException,请调用#isTrue(布尔值)。

Assert.state(id == null);

代码示例

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

/**
 * Assert a boolean expression, throwing {@link IllegalStateException}
 * if the test result is <code>false</code>.
 * <p>Call {@link #isTrue(boolean)} if you wish to
 * throw {@link IllegalArgumentException} on an assertion failure.
 * <pre class="code">Assert.state(id == null);</pre>
 * @param expression a boolean expression
 * @throws IllegalStateException if the supplied expression is <code>false</code>
 */
public static void state(boolean expression) {
  state(expression, "[Assertion failed] - this state invariant must be true");
}

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

@SuppressWarnings({"unchecked"})
public <T> T getBean(String id, Class<T> requiredType) {
  if (requiredType == null) {
    throw new NullPointerException("requiredType argument cannot be null.");
  }
  Object bean = getBean(id);
  if (bean == null) {
    return null;
  }
  Assert.state(requiredType.isAssignableFrom(bean.getClass()),
      "Bean with id [" + id + "] is not of the required type [" + requiredType.getName() + "].");
  return (T) bean;
}

代码示例来源:origin: org.apache.shiro/shiro-lang

/**
 * Assert a boolean expression, throwing {@link IllegalStateException}
 * if the test result is <code>false</code>.
 * <p>Call {@link #isTrue(boolean)} if you wish to
 * throw {@link IllegalArgumentException} on an assertion failure.
 * <pre class="code">Assert.state(id == null);</pre>
 * @param expression a boolean expression
 * @throws IllegalStateException if the supplied expression is <code>false</code>
 */
public static void state(boolean expression) {
  state(expression, "[Assertion failed] - this state invariant must be true");
}

代码示例来源:origin: org.apache.shiro/shiro-config-ogdl

@SuppressWarnings({"unchecked"})
public <T> T getBean(String id, Class<T> requiredType) {
  if (requiredType == null) {
    throw new NullPointerException("requiredType argument cannot be null.");
  }
  Object bean = getBean(id);
  if (bean == null) {
    return null;
  }
  Assert.state(requiredType.isAssignableFrom(bean.getClass()),
      "Bean with id [" + id + "] is not of the required type [" + requiredType.getName() + "].");
  return (T) bean;
}

相关文章