本文整理汇总了Java中org.apache.commons.lang3.Validate类的典型用法代码示例。如果您正苦于以下问题:Java Validate类的具体用法?Java Validate怎么用?Java Validate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Validate类属于org.apache.commons.lang3包,在下文中一共展示了Validate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendData
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
/**
* Sends the data to the bStats server.
*
* @param data The data to send.
* @throws Exception If the request failed.
*/
private static void sendData(JsonObject data) throws Exception {
Validate.notNull(data, "Data cannot be null");
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
// Compress the data to save bandwidth
byte[] compressedData = compress(data.toString());
// Add headers
connection.setRequestMethod("POST");
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
// Send data
connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.write(compressedData);
outputStream.flush();
outputStream.close();
connection.getInputStream().close(); // We don't care about the response - Just send our data :)
}
示例2: removeAllSignUpsAt
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Raid removeAllSignUpsAt(String raidId, LocalDateTime startAt) {
Validate.notNull(raidId, "Raid ID cannot be null");
Validate.notNull(startAt, "Start time cannot be null");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("About to remove signups for raid " + raidId + " at " + printTimeIfSameDay(startAt));
}
RaidEntity entity = findEntityByRaidId(raidId);
if (entity != null) {
for (RaidEntitySignUp signUp : entity.getSignUpsAsSet()) {
if (signUp.getArrivalTime().equals(startAt.toLocalTime())) {
RaidEntitySignUp removed = entity.removeSignUp(signUp);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Removed signup: " + removed);
}
}
}
entity = raidEntityRepository.save(entity);
}
return getRaidInstance(entity);
}
示例3: unmarshalExtensionInfo
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
@Nullable
private ExtensionInfo unmarshalExtensionInfo(@NotNull final File file) {
Validate.notNull(file);
try {
if (null == EXTENSION_INFO_JAXB_CONTEXT) {
LOG.error(String.format(
"Can not unmarshal '%s' because JAXBContext has not been created.", file.getAbsolutePath()
));
return null;
}
final Unmarshaller jaxbUnmarshaller = EXTENSION_INFO_JAXB_CONTEXT.createUnmarshaller();
return (ExtensionInfo) jaxbUnmarshaller.unmarshal(file);
} catch (JAXBException e) {
LOG.error("Can not unmarshal " + file.getAbsolutePath(), e);
}
return null;
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:23,代码来源:RegularHybrisModuleDescriptor.java
示例4: readId
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
static void readId(final TrackingReplayableIdAndSizeByteSource source, IdConsumer resultAcceptor) {
if (!isEnoughBytes(source, 1)) {
return;
}
final int firstByte = readByte(source);
if (firstByte == -1) {
resultAcceptor.accept(firstByte, 1);
}
Validate.isTrue(firstByte >= 0, "EBML Id has negative firstByte" + firstByte);
final int numAdditionalBytes = getNumLeadingZeros(firstByte);
if (!isEnoughBytes(source, numAdditionalBytes)) {
return;
}
Validate.isTrue(numAdditionalBytes <= (EBML_ID_MAX_BYTES - 1),
"Trying to decode an EBML ID and it wants " + numAdditionalBytes
+ " more bytes, but IDs max out at 4 bytes. firstByte was " + firstByte);
final int rest = (int) readEbmlValueNumber(source, numAdditionalBytes);
resultAcceptor.accept(firstByte << (numAdditionalBytes * Byte.SIZE) | rest, numAdditionalBytes + 1);
}
示例5: initializeProcessor
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
protected void initializeProcessor(ProcessorInstanceHolder instanceHolder, BaseProcessorAdapter adapter) {
Processor processor = instanceHolder.getProcessor();
processor.onConfigure();
// Must be verified after onConfigure, because onConfigure may change for example the name of the processor.
Optional<Map.Entry<ProcessorType, RegistrationHandler>> alreadyRegistered = findAlreadyRegisteredByDifferentType(adapter);
if (alreadyRegistered.isPresent()) {
Validate.isTrue(false, "% named '%' has already been registered as % type", adapter.getType().getDisplayName(),
adapter.getName(), alreadyRegistered.get().getKey().getDisplayName());
}
processor.getAdapter().validate();
if (processor.getAdapter().getDefinition().isSingleton()) {
processor.onInit();
}
}
示例6: get
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
@Override public float get(int x, int y)
{
Validate.inclusiveBetween(0, width-1, x);
Validate.inclusiveBetween(0, height-1, y);
if(region == null)
return 0;
int inRegionX = x-regionPosition.x;
int inRegionY = y-regionPosition.y;
if(inRegionX >= 0 && inRegionX < region.getWidth())
if(inRegionY >= 0 && inRegionY < region.getHeight())
return region.get(inRegionX, inRegionY);
return 0;
}
示例7: getAccessibleMethod
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
/**
* 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
* 如向上转型到Object仍无法找到, 返回null.
* 匹配函数名+参数类型。
* <p/>
* 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args)
*/
public static Method getAccessibleMethod(final Object obj, final String methodName,
final Class<?>... parameterTypes) {
Validate.notNull(obj, "object can't be null");
Validate.notBlank(methodName, "methodName can't be blank");
for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) {
try {
Method method = searchType.getDeclaredMethod(methodName, parameterTypes);
makeAccessible(method);
return method;
} catch (NoSuchMethodException e) {
// Method不在当前类定义,继续向上转型
continue;// new add
}
}
return null;
}
示例8: getAccessibleMethod
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
/**
* 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
* 如向上转型到Object仍无法找到, 返回null.
* 匹配函数名+参数类型。
* <p>
* 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args)
*/
public static Method getAccessibleMethod(final Object obj, final String methodName, final Class<?>... parameterTypes) {
Validate.notNull(obj, "object can't be null");
Validate.notBlank(methodName, "methodName can't be blank");
for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) {
try {
Method method = searchType.getDeclaredMethod(methodName, parameterTypes);
makeAccessible(method);
return method;
} catch (NoSuchMethodException e) {
// Method不在当前类定义,继续向上转型
continue;// new add
}
}
return null;
}
示例9: getAccessibleMethodByName
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
/**
* 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
* 如向上转型到Object仍无法找到, 返回null.
* 只匹配函数名。
* <p>
* 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args)
*/
public static Method getAccessibleMethodByName(final Object obj, final String methodName) {
Validate.notNull(obj, "object can't be null");
Validate.notBlank(methodName, "methodName can't be blank");
for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) {
Method[] methods = searchType.getDeclaredMethods();
for (Method method : methods) {
if (method.getName().equals(methodName)) {
makeAccessible(method);
return method;
}
}
}
return null;
}
示例10: moveAllSignUpsForTimeToNewTime
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
public void moveAllSignUpsForTimeToNewTime(String raidId, LocalDateTime currentStartAt, LocalDateTime newDateTime, User user) {
Validate.notNull(raidId, "Raid ID cannot be null");
Validate.notNull(currentStartAt, "Current start time cannot be null");
Validate.notNull(newDateTime, "New start time cannot be null");
Validate.notNull(user, "User cannot be null");
RaidEntity entity = raidEntityRepository.findOne(raidId);
if (entity != null) {
for (RaidEntitySignUp signUp : entity.getSignUpsAsSet()) {
if (signUp.getArrivalTime().equals(currentStartAt.toLocalTime())) {
signUp.setEta(Utils.printTime(newDateTime.toLocalTime()));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Changed ETA for signup: " + signUp);
}
}
}
raidEntityRepository.save(entity);
} else {
throw new UserMessedUpException(user,
localeService.getMessageFor(LocaleService.NO_RAID_AT_GYM, localeService.getLocaleForUser(user)));
}
// todo: throw error if problem?
}
示例11: configurePlatformRoots
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
protected void configurePlatformRoots(
@NotNull final HybrisModuleDescriptor moduleDescriptor,
@NotNull final ContentEntry contentEntry
) {
Validate.notNull(moduleDescriptor);
Validate.notNull(contentEntry);
if (!HybrisConstants.PLATFORM_EXTENSION_NAME.equalsIgnoreCase(moduleDescriptor.getName())) {
return;
}
final File rootDirectory = moduleDescriptor.getRootDirectory();
final File platformBootstrapDirectory = new File(rootDirectory, PLATFORM_BOOTSTRAP_DIRECTORY);
if (!moduleDescriptor.getRootProjectDescriptor().isImportOotbModulesInReadOnlyMode()) {
final File platformBootstrapResourcesDirectory = new File(platformBootstrapDirectory, RESOURCES_DIRECTORY);
contentEntry.addSourceFolder(
VfsUtil.pathToUrl(platformBootstrapResourcesDirectory.getAbsolutePath()),
JavaResourceRootType.RESOURCE
);
}
excludeDirectory(contentEntry, new File(platformBootstrapDirectory, PLATFORM_MODEL_CLASSES_DIRECTORY));
excludeDirectory(contentEntry, new File(rootDirectory, PLATFORM_TOMCAT_DIRECTORY));
contentEntry.addExcludePattern("apache-ant-*");
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:27,代码来源:RegularContentRootConfigurator.java
示例12: transform
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
public MessageHeader transform(AdtMessage sourceMessage) throws ParseException, MapperException, TransformException {
Validate.notNull(sourceMessage);
Validate.notNull(sourceMessage.getMshSegment());
Validate.notNull(sourceMessage.getEvnSegment());
MshSegment mshSegment = sourceMessage.getMshSegment();
EvnSegment evnSegment = sourceMessage.getEvnSegment();
MessageHeader target = new MessageHeader();
setId(sourceMessage, target);
setTimestamp(mshSegment, target);
setEvent(mshSegment, target);
setSource(mshSegment, target);
setDestination(mshSegment, target);
setResponsible(target);
setMessageControlId(mshSegment, target);
setSequenceNumber(mshSegment, target);
setEnterer(evnSegment, target);
setData(target);
return target;
}
示例13: callFromMainThread
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
public <V> ListenableFuture<V> callFromMainThread(Callable<V> callable)
{
Validate.notNull(callable);
if (!this.isCallingFromMinecraftThread() && !this.isServerStopped())
{
ListenableFutureTask<V> listenablefuturetask = ListenableFutureTask.<V>create(callable);
synchronized (this.futureTaskQueue)
{
this.futureTaskQueue.add(listenablefuturetask);
return listenablefuturetask;
}
}
else
{
try
{
return Futures.<V>immediateFuture(callable.call());
}
catch (Exception exception)
{
return Futures.immediateFailedCheckedFuture(exception);
}
}
}
示例14: getPlaceholder
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
@NotNull
@Override
public String getPlaceholder(@NotNull final PsiElement psiElement) {
Validate.notNull(psiElement);
if (ImpexPsiUtils.isImpexAttribute(psiElement)) {
final ImpexAttribute attribute = (ImpexAttribute) psiElement;
return this.getPlaceholder(attribute);
}
if (ImpexPsiUtils.isImpexParameters(psiElement)) {
return IMPEX_PARAMETERS_PLACEHOLDER;
}
return psiElement.getText();
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:18,代码来源:SmartImpexFoldingPlaceholderBuilder.java
示例15: unmarshallBusinessProcessXml
import org.apache.commons.lang3.Validate; //导入依赖的package包/类
@Nonnull
@Override
public Process unmarshallBusinessProcessXml(@NotNull final File file) throws UnmarshalException {
Validate.notNull(file);
try {
if (null == this.jaxbContext) {
LOG.error(String.format(
"Can not unmarshall '%s' because JAXBContext has not been created.", file.getAbsolutePath()
));
return null;
}
final Unmarshaller jaxbUnmarshaller = this.jaxbContext.get().createUnmarshaller();
return (Process) jaxbUnmarshaller.unmarshal(file);
} catch (Exception e) {
throw new UnmarshalException("Can not unmarshall " + file.getAbsolutePath(), e);
}
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:22,代码来源:DefaultBpJaxbService.java