本文整理了Java中org.apache.commons.lang3.Validate.isTrue()
方法的一些代码示例,展示了Validate.isTrue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Validate.isTrue()
方法的具体详情如下:
包路径:org.apache.commons.lang3.Validate
类名称:Validate
方法名:isTrue
[英]Validate that the argument condition is true; otherwise throwing an exception. This method is useful when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.
Validate.isTrue(i > 0);
Validate.isTrue(myObject.isOk());
The message of the exception is "The validated expression is false".
[中]验证参数条件是否为真;否则将引发异常。当根据任意布尔表达式进行验证时,此方法非常有用,例如验证基元数或使用自己的自定义验证表达式。
Validate.isTrue(i > 0);
Validate.isTrue(myObject.isOk());
异常的消息是“已验证的表达式为false”。
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Validate {@code enumClass}.
* @param <E> the type of the enumeration
* @param enumClass to check
* @return {@code enumClass}
* @throws NullPointerException if {@code enumClass} is {@code null}
* @throws IllegalArgumentException if {@code enumClass} is not an enum class
* @since 3.2
*/
private static <E extends Enum<E>> Class<E> asEnum(final Class<E> enumClass) {
Validate.notNull(enumClass, ENUM_CLASS_MUST_BE_DEFINED);
Validate.isTrue(enumClass.isEnum(), S_DOES_NOT_SEEM_TO_BE_AN_ENUM_TYPE, enumClass);
return enumClass;
}
}
代码示例来源:origin: apache/geode
/**
* Constructs an instance for controlling a local process.
*
* @param pid process id identifying the process to attach to
*
* @throws IllegalArgumentException if pid is not a positive integer
*/
MBeanProcessController(final MBeanControllerParameters arguments, final int pid) {
notNull(arguments, "Invalid arguments '" + arguments + "' specified");
isTrue(pid > 0, "Invalid pid '" + pid + "' specified");
this.pid = pid;
this.arguments = arguments;
}
代码示例来源:origin: Swagger2Markup/swagger2markup
/**
* Specifies parameter ordering.<br>
* By default parameter ordering == {@link OrderBy#NATURAL}.<br>
* Use {@link #withParameterOrdering(Comparator)} to set a custom ordering.
*
* @param orderBy parameter ordering
* @return this builder
*/
public Swagger2MarkupConfigBuilder withParameterOrdering(OrderBy orderBy) {
Validate.notNull(orderBy, "%s must not be null", "orderBy");
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
config.parameterOrderBy = orderBy;
return this;
}
代码示例来源:origin: Swagger2Markup/swagger2markup
/**
* Specifies operation ordering.<br>
* By default operation ordering == {@link io.github.swagger2markup.OrderBy#AS_IS}.<br>
* Use {@link #withOperationOrdering(Comparator)} to set a custom ordering.
*
* @param orderBy operation ordering
* @return this builder
*/
public Swagger2MarkupConfigBuilder withOperationOrdering(OrderBy orderBy) {
Validate.notNull(orderBy, "%s must not be null", "orderBy");
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
config.operationOrderBy = orderBy;
return this;
}
代码示例来源:origin: Swagger2Markup/swagger2markup
/**
* Specifies definition ordering.<br>
* By default definition ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.<br>
* Use {@link #withDefinitionOrdering(Comparator)} to set a custom ordering.
*
* @param orderBy definition ordering
* @return this builder
*/
public Swagger2MarkupConfigBuilder withDefinitionOrdering(OrderBy orderBy) {
Validate.notNull(orderBy, "%s must not be null", "orderBy");
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
config.definitionOrderBy = orderBy;
return this;
}
代码示例来源:origin: Swagger2Markup/swagger2markup
/**
* Specifies response ordering.<br>
* By default response ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.<br>
* Use {@link #withResponseOrdering(Comparator)} to set a custom ordering.
*
* @param orderBy response ordering
* @return this builder
*/
public Swagger2MarkupConfigBuilder withResponseOrdering(OrderBy orderBy) {
Validate.notNull(orderBy, "%s must not be null", "orderBy");
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
config.responseOrderBy = orderBy;
return this;
}
代码示例来源:origin: Swagger2Markup/swagger2markup
/**
* Specifies tag ordering.<br>
* By default tag ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.<br>
* Use {@link #withTagOrdering(Comparator)} to set a custom ordering.
*
* @param orderBy tag ordering
* @return this builder
*/
public Swagger2MarkupConfigBuilder withTagOrdering(OrderBy orderBy) {
Validate.notNull(orderBy, "%s must not be null", "orderBy");
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
config.tagOrderBy = orderBy;
return this;
}
代码示例来源:origin: Swagger2Markup/swagger2markup
/**
* Specifies property ordering.<br>
* By default property ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.<br>
* Use {@link #withPropertyOrdering(Comparator)} to set a custom ordering.
*
* @param orderBy property ordering
* @return this builder
*/
public Swagger2MarkupConfigBuilder withPropertyOrdering(OrderBy orderBy) {
Validate.notNull(orderBy, "%s must not be null", "orderBy");
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
config.propertyOrderBy = orderBy;
return this;
}
代码示例来源:origin: apache/geode
/**
* Constructs a PidFile for reading pid stored in a file.
*
* @param file the file containing the pid of the process
*
* @throws IllegalArgumentException if the specified file is null or does not exist
*/
public PidFile(final File file) {
notNull(file, "Invalid file '" + file + "' specified");
isTrue(file.exists(), "Nonexistent file '" + file + "' specified");
this.pidFile = file;
}
代码示例来源:origin: apache/nifi
public NiFiBolt(final SiteToSiteClientConfig clientConfig, final NiFiDataPacketBuilder builder, final int tickFrequencySeconds) {
Validate.notNull(clientConfig);
Validate.notNull(builder);
Validate.isTrue(tickFrequencySeconds > 0);
this.clientConfig = clientConfig;
this.builder = builder;
this.tickFrequencySeconds = tickFrequencySeconds;
}
代码示例来源:origin: apache/geode
public static int readPid(final File pidFile) throws IOException {
notNull(pidFile, "Invalid pidFile '" + pidFile + "' specified");
isTrue(pidFile.exists(), "Nonexistent pidFile '" + pidFile + "' specified");
try (BufferedReader reader = new BufferedReader(new FileReader(pidFile))) {
return Integer.parseInt(reader.readLine());
}
}
代码示例来源:origin: apache/geode
/**
* Constructs an instance for controlling a local process.
*
* @param parameters details about the controllable process
* @param pid process id identifying the process to control
* @param timeout the timeout that operations must complete within
* @param units the units of the timeout
*
* @throws IllegalArgumentException if pid is not a positive integer
*/
FileProcessController(final FileControllerParameters parameters, final int pid,
final long timeout, final TimeUnit units) {
notNull(parameters, "Invalid parameters '" + parameters + "' specified");
isTrue(pid > 0, "Invalid pid '" + pid + "' specified");
isTrue(timeout >= 0, "Invalid timeout '" + timeout + "' specified");
notNull(units, "Invalid units '" + units + "' specified");
this.pid = pid;
this.parameters = parameters;
this.statusTimeoutMillis = units.toMillis(timeout);
}
代码示例来源:origin: PipelineAI/pipeline
private void validateMetaHolder(MetaHolder metaHolder) {
Validate.notNull(metaHolder, "metaHolder is required parameter and cannot be null");
Validate.isTrue(metaHolder.isCommandAnnotationPresent(), "hystrixCommand annotation is absent");
}
代码示例来源:origin: springside/springside4
/**
* 文件复制. @see {@link Files#copy}
*
* @param from 如果为null,或文件不存在或者是目录,,抛出异常
* @param to 如果to为null,或文件存在但是一个目录,抛出异常
*/
public static void copyFile(@NotNull Path from, @NotNull Path to) throws IOException {
Validate.isTrue(Files.exists(from), "%s is not exist or not a file", from);
Validate.notNull(to);
Validate.isTrue(!FileUtil.isDirExists(to), "%s is exist but it is a dir", to);
Files.copy(from, to);
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Creates an EventListenerSupport object which supports the provided
* listener interface using the specified class loader to create the JDK
* dynamic proxy.
*
* @param listenerInterface the listener interface.
* @param classLoader the class loader.
*
* @throws NullPointerException if <code>listenerInterface</code> or
* <code>classLoader</code> is <code>null</code>.
* @throws IllegalArgumentException if <code>listenerInterface</code> is
* not an interface.
*/
public EventListenerSupport(final Class<L> listenerInterface, final ClassLoader classLoader) {
this();
Validate.notNull(listenerInterface, "Listener interface cannot be null.");
Validate.notNull(classLoader, "ClassLoader cannot be null.");
Validate.isTrue(listenerInterface.isInterface(), "Class {0} is not an interface",
listenerInterface.getName());
initializeTransientFields(listenerInterface, classLoader);
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* <p>Creates a long bit vector representation of the given subset of an Enum.</p>
*
* <p>This generates a value that is usable by {@link EnumUtils#processBitVector}.</p>
*
* <p>Do not use this method if you have more than 64 values in your Enum, as this
* would create a value greater than a long can hold.</p>
*
* @param enumClass the class of the enum we are working with, not {@code null}
* @param values the values we want to convert, not {@code null}, neither containing {@code null}
* @param <E> the type of the enumeration
* @return a long whose value provides a binary representation of the given set of enum values.
* @throws NullPointerException if {@code enumClass} or {@code values} is {@code null}
* @throws IllegalArgumentException if {@code enumClass} is not an enum class or has more than 64 values,
* or if any {@code values} {@code null}
* @since 3.0.1
* @see #generateBitVectors(Class, Iterable)
*/
public static <E extends Enum<E>> long generateBitVector(final Class<E> enumClass, final Iterable<? extends E> values) {
checkBitVectorable(enumClass);
Validate.notNull(values);
long total = 0;
for (final E constant : values) {
Validate.isTrue(constant != null, NULL_ELEMENTS_NOT_PERMITTED);
total |= 1L << constant.ordinal();
}
return total;
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Create a parameterized type instance.
*
* @param owner the owning type
* @param raw the raw class to create a parameterized type instance for
* @param typeArguments the types used for parameterization
*
* @return {@link ParameterizedType}
* @since 3.2
*/
public static final ParameterizedType parameterizeWithOwner(final Type owner, final Class<?> raw,
final Type... typeArguments) {
Validate.notNull(raw, "raw class is null");
final Type useOwner;
if (raw.getEnclosingClass() == null) {
Validate.isTrue(owner == null, "no owner allowed for top-level %s", raw);
useOwner = null;
} else if (owner == null) {
useOwner = raw.getEnclosingClass();
} else {
Validate.isTrue(isAssignable(owner, raw.getEnclosingClass()),
"%s is invalid owner type for parameterized %s", owner, raw);
useOwner = owner;
}
Validate.noNullElements(typeArguments, "null type argument at index %s");
Validate.isTrue(raw.getTypeParameters().length == typeArguments.length,
"invalid number of type parameters specified: expected %d, got %d", raw.getTypeParameters().length,
typeArguments.length);
return new ParameterizedTypeImpl(raw, useOwner, typeArguments);
}
代码示例来源:origin: springside/springside4
/**
* 文件移动/重命名.
*
* @see {@link Files#move}
*/
public static void moveFile(@NotNull Path from, @NotNull Path to) throws IOException {
Validate.isTrue(isFileExists(from), "%s is not exist or not a file", from);
Validate.notNull(to);
Validate.isTrue(!isDirExists(to), "%s is exist but it is a dir", to);
Files.move(from, to);
}
代码示例来源:origin: org.apache.commons/commons-lang3
Validate.notNull(values);
final EnumSet<E> condensed = EnumSet.noneOf(enumClass);
for (final E constant : values) {
Validate.isTrue(constant != null, NULL_ELEMENTS_NOT_PERMITTED);
condensed.add(constant);
代码示例来源:origin: apache/geode
/**
* Constructs a PidFile for reading pid stored in a file.
*
* @param directory directory containing a file of name pidFileName
* @param filename name of the file containing the pid of the process to stop
*
* @throws FileNotFoundException if the specified filename is not found within the directory
* @throws IllegalArgumentException if directory is null, does not exist or is not a directory
*/
public PidFile(final File directory, final String filename) throws FileNotFoundException {
notNull(directory, "Invalid directory '" + directory + "' specified");
notEmpty(filename, "Invalid filename '" + filename + "' specified");
isTrue(directory.isDirectory() && directory.exists(),
"Nonexistent directory '" + directory + "' specified");
File file = new File(directory, filename);
if (!file.exists() || file.isDirectory()) {
throw new FileNotFoundException(
"Unable to find PID file '" + filename + "' in directory '" + directory + "'");
}
this.pidFile = file;
}
内容来源于网络,如有侵权,请联系作者删除!