當前位置: 首頁>>代碼示例>>Java>>正文


Java Validate類代碼示例

本文整理匯總了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 :)
}
 
開發者ID:BtoBastian,項目名稱:bStats-Metrics,代碼行數:32,代碼來源:MetricsLite.java

示例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);
}
 
開發者ID:magnusmickelsson,項目名稱:pokeraidbot,代碼行數:23,代碼來源:RaidRepository.java

示例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);
}
 
開發者ID:aws,項目名稱:amazon-kinesis-video-streams-parser-library,代碼行數:25,代碼來源:EBMLUtils.java

示例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();
    }
}
 
開發者ID:softelnet,項目名稱:sponge,代碼行數:19,代碼來源:DefaultProcessorManager.java

示例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;
}
 
開發者ID:domisum,項目名稱:ExZiff,代碼行數:18,代碼來源:FloatMapLocalized.java

示例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;
}
 
開發者ID:wxiaoqi,項目名稱:ace-cache,代碼行數:25,代碼來源:ReflectionUtils.java

示例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;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:24,代碼來源:Reflections.java

示例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;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:23,代碼來源:Reflections.java

示例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?
}
 
開發者ID:magnusmickelsson,項目名稱:pokeraidbot,代碼行數:23,代碼來源:RaidRepository.java

示例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;
}
 
開發者ID:endeavourhealth,項目名稱:HL7Receiver,代碼行數:24,代碼來源:HomertonMessageHeaderTransform.java

示例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);
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:27,代碼來源:MinecraftServer.java

示例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


注:本文中的org.apache.commons.lang3.Validate類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。