org.springframework.util.Assert.isTrue()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(835)

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

Assert.isTrue介绍

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

Assert.isTrue(i > 0);

[中]断言一个布尔表达式,如果测试结果为false,则抛出IllegalArgumentException

Assert.isTrue(i > 0);

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Create a new {@code BufferingStompDecoder} wrapping the given {@code StompDecoder}.
 * @param stompDecoder the target decoder to wrap
 * @param bufferSizeLimit the buffer size limit
 */
public BufferingStompDecoder(StompDecoder stompDecoder, int bufferSizeLimit) {
  Assert.notNull(stompDecoder, "StompDecoder is required");
  Assert.isTrue(bufferSizeLimit > 0, "Buffer size limit must be greater than 0");
  this.stompDecoder = stompDecoder;
  this.bufferSizeLimit = bufferSizeLimit;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Create a new {@code ResourceRegion} from a given {@link Resource}.
 * This region of a resource is represented by a start {@code position}
 * and a byte {@code count} within the given {@code Resource}.
 * @param resource a Resource
 * @param position the start position of the region in that resource
 * @param count the byte count of the region in that resource
 */
public ResourceRegion(Resource resource, long position, long count) {
  Assert.notNull(resource, "Resource must not be null");
  Assert.isTrue(position >= 0, "'position' must be larger than or equal to 0");
  Assert.isTrue(count >= 0, "'count' must be larger than or equal to 0");
  this.resource = resource;
  this.position = position;
  this.count = count;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Construct a new {@code SpringFailOnTimeout} statement for the supplied
 * {@code timeout}.
 * <p>If the supplied {@code timeout} is {@code 0}, the execution of the
 * {@code next} statement will not be timed.
 * @param next the next {@code Statement} in the execution chain; never {@code null}
 * @param timeout the configured {@code timeout} for the current test, in milliseconds;
 * never negative
 */
public SpringFailOnTimeout(Statement next, long timeout) {
  Assert.notNull(next, "next statement must not be null");
  Assert.isTrue(timeout >= 0, "timeout must be non-negative");
  this.next = next;
  this.timeout = timeout;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the interface that the proxy must implement.
 * @param serviceInterface the interface that the proxy must implement
 * @throws IllegalArgumentException if the supplied {@code serviceInterface}
 * is not an interface type
 */
public void setServiceInterface(Class<?> serviceInterface) {
  Assert.notNull(serviceInterface, "'serviceInterface' must not be null");
  Assert.isTrue(serviceInterface.isInterface(), "'serviceInterface' must be an interface");
  this.serviceInterface = serviceInterface;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the interface of the service to export.
 * The interface must be suitable for the particular service and remoting strategy.
 */
public void setServiceInterface(Class<?> serviceInterface) {
  Assert.notNull(serviceInterface, "'serviceInterface' must not be null");
  Assert.isTrue(serviceInterface.isInterface(), "'serviceInterface' must be an interface");
  this.serviceInterface = serviceInterface;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Sets the cache directory. If this property is set to an existing directory,
 * this converter will cache image data.
 */
public void setCacheDir(File cacheDir) {
  Assert.notNull(cacheDir, "'cacheDir' must not be null");
  Assert.isTrue(cacheDir.isDirectory(), "'cacheDir' is not a directory");
  this.cacheDir = cacheDir;
}

代码示例来源:origin: spring-projects/spring-framework

public ReflectiveElementFactory(Class<? extends E> elementClass) {
  Assert.notNull(elementClass, "Element class must not be null");
  Assert.isTrue(!elementClass.isInterface(), "Element class must not be an interface type");
  Assert.isTrue(!Modifier.isAbstract(elementClass.getModifiers()), "Element class cannot be an abstract class");
  this.elementClass = elementClass;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the interface of the service to access.
 * The interface must be suitable for the particular service and remoting strategy.
 * <p>Typically required to be able to create a suitable service proxy,
 * but can also be optional if the lookup returns a typed proxy.
 */
public void setServiceInterface(Class<?> serviceInterface) {
  Assert.notNull(serviceInterface, "'serviceInterface' must not be null");
  Assert.isTrue(serviceInterface.isInterface(), "'serviceInterface' must be an interface");
  this.serviceInterface = serviceInterface;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the interface of the service to access.
 * The interface must be suitable for the particular service and remoting tool.
 * <p>Typically required to be able to create a suitable service proxy,
 * but can also be optional if the lookup returns a typed stub.
 */
public void setServiceInterface(Class<?> serviceInterface) {
  Assert.notNull(serviceInterface, "'serviceInterface' must not be null");
  Assert.isTrue(serviceInterface.isInterface(), "'serviceInterface' must be an interface");
  this.serviceInterface = serviceInterface;
}

代码示例来源:origin: spring-projects/spring-framework

public final void addConnection(Connection connection) {
  Assert.isTrue(!this.frozen, "Cannot add Connection because JmsResourceHolder is frozen");
  Assert.notNull(connection, "Connection must not be null");
  if (!this.connections.contains(connection)) {
    this.connections.add(connection);
  }
}

代码示例来源:origin: spring-projects/spring-framework

public final void addSession(Session session, @Nullable Connection connection) {
  Assert.isTrue(!this.frozen, "Cannot add Session because JmsResourceHolder is frozen");
  Assert.notNull(session, "Session must not be null");
  if (!this.sessions.contains(session)) {
    this.sessions.add(session);
    if (connection != null) {
      List<Session> sessions = this.sessionsPerConnection.computeIfAbsent(connection, k -> new LinkedList<>());
      sessions.add(session);
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Add an argument value for the given index in the constructor argument list.
 * @param index the index in the constructor argument list
 * @param newValue the argument value in the form of a ValueHolder
 */
public void addIndexedArgumentValue(int index, ValueHolder newValue) {
  Assert.isTrue(index >= 0, "Index must not be negative");
  Assert.notNull(newValue, "ValueHolder must not be null");
  addOrMergeIndexedArgumentValue(index, newValue);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the default HTTP Status to use for redirects.
 * <p>By default this is {@link HttpStatus#SEE_OTHER}.
 * @param status the 3xx redirect status to use
 */
public void setRedirectStatus(HttpStatus status) {
  Assert.notNull(status, "Property 'redirectStatus' is required");
  Assert.isTrue(status.is3xxRedirection(), "Not a redirect status code");
  this.redirectStatus = status;
}

代码示例来源:origin: org.springframework/spring-context

/**
 * Set the interface of the service to export.
 * The interface must be suitable for the particular service and remoting strategy.
 */
public void setServiceInterface(Class<?> serviceInterface) {
  Assert.notNull(serviceInterface, "'serviceInterface' must not be null");
  Assert.isTrue(serviceInterface.isInterface(), "'serviceInterface' must be an interface");
  this.serviceInterface = serviceInterface;
}

代码示例来源:origin: org.springframework/spring-context

/**
 * Set the interface of the service to access.
 * The interface must be suitable for the particular service and remoting tool.
 * <p>Typically required to be able to create a suitable service proxy,
 * but can also be optional if the lookup returns a typed stub.
 */
public void setServiceInterface(Class<?> serviceInterface) {
  Assert.notNull(serviceInterface, "'serviceInterface' must not be null");
  Assert.isTrue(serviceInterface.isInterface(), "'serviceInterface' must be an interface");
  this.serviceInterface = serviceInterface;
}

代码示例来源:origin: org.springframework/spring-context

/**
 * Set the interface of the service to access.
 * The interface must be suitable for the particular service and remoting strategy.
 * <p>Typically required to be able to create a suitable service proxy,
 * but can also be optional if the lookup returns a typed proxy.
 */
public void setServiceInterface(Class<?> serviceInterface) {
  Assert.notNull(serviceInterface, "'serviceInterface' must not be null");
  Assert.isTrue(serviceInterface.isInterface(), "'serviceInterface' must be an interface");
  this.serviceInterface = serviceInterface;
}

代码示例来源:origin: org.springframework/spring-core

public ReflectiveElementFactory(Class<? extends E> elementClass) {
  Assert.notNull(elementClass, "Element class must not be null");
  Assert.isTrue(!elementClass.isInterface(), "Element class must not be an interface type");
  Assert.isTrue(!Modifier.isAbstract(elementClass.getModifiers()), "Element class cannot be an abstract class");
  this.elementClass = elementClass;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Attempt to find a {@link Field field} on the supplied {@link Class} with the
 * supplied {@code name} and/or {@link Class type}. Searches all superclasses
 * up to {@link Object}.
 * @param clazz the class to introspect
 * @param name the name of the field (may be {@code null} if type is specified)
 * @param type the type of the field (may be {@code null} if name is specified)
 * @return the corresponding Field object, or {@code null} if not found
 */
@Nullable
public static Field findField(Class<?> clazz, @Nullable String name, @Nullable Class<?> type) {
  Assert.notNull(clazz, "Class must not be null");
  Assert.isTrue(name != null || type != null, "Either name or type of the field must be specified");
  Class<?> searchType = clazz;
  while (Object.class != searchType && searchType != null) {
    Field[] fields = getDeclaredFields(searchType);
    for (Field field : fields) {
      if ((name == null || name.equals(field.getName())) &&
          (type == null || type.equals(field.getType()))) {
        return field;
      }
    }
    searchType = searchType.getSuperclass();
  }
  return null;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Constructor accepting a request and response pair that are expected to be of type
 * {@link ServletServerHttpRequest} and {@link ServletServerHttpResponse}
 * respectively.
 */
public ServletServerHttpAsyncRequestControl(ServletServerHttpRequest request, ServletServerHttpResponse response) {
  Assert.notNull(request, "request is required");
  Assert.notNull(response, "response is required");
  Assert.isTrue(request.getServletRequest().isAsyncSupported(),
      "Async support must be enabled on a servlet and for all filters involved " +
      "in async request processing. This is done in Java code using the Servlet API " +
      "or by adding \"<async-supported>true</async-supported>\" to servlet and " +
      "filter declarations in web.xml. Also you must use a Servlet 3.0+ container");
  this.request = request;
  this.response = response;
}

代码示例来源:origin: org.springframework/spring-beans

/**
 * Add an argument value for the given index in the constructor argument list.
 * @param index the index in the constructor argument list
 * @param newValue the argument value in the form of a ValueHolder
 */
public void addIndexedArgumentValue(int index, ValueHolder newValue) {
  Assert.isTrue(index >= 0, "Index must not be negative");
  Assert.notNull(newValue, "ValueHolder must not be null");
  addOrMergeIndexedArgumentValue(index, newValue);
}

相关文章