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


Java ObjectUtils.defaultIfNull方法代碼示例

本文整理匯總了Java中org.apache.commons.lang3.ObjectUtils.defaultIfNull方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectUtils.defaultIfNull方法的具體用法?Java ObjectUtils.defaultIfNull怎麽用?Java ObjectUtils.defaultIfNull使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.lang3.ObjectUtils的用法示例。


在下文中一共展示了ObjectUtils.defaultIfNull方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: upload

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
/**
 * Upload a file of quote in add mode.
 * 
 * @param subscription
 *            The subscription identifier, will be used to filter the locations
 *            from the associated provider.
 * @param uploadedFile
 *            Instance entries files to import. Currently support only CSV
 *            format.
 * @param columns
 *            the CSV header names.
 * @param term
 *            The default {@link ProvInstancePriceTerm} used when no one is
 *            defined in the CSV line
 * @param ramMultiplier
 *            The multiplier for imported RAM values. Default is 1.
 * @param encoding
 *            CSV encoding. Default is UTF-8.
 * @throws IOException
 *             When the CSV stream cannot be written.
 */
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("{subscription:\\d+}/upload")
public void upload(@PathParam("subscription") final int subscription, @Multipart(value = "csv-file") final InputStream uploadedFile,
		@Multipart(value = "columns", required = false) final String[] columns,
		@Multipart(value = "term", required = false) final String term,
		@Multipart(value = "memoryUnit", required = false) final Integer ramMultiplier,
		@Multipart(value = "encoding", required = false) final String encoding) throws IOException {
	subscriptionResource.checkVisibleSubscription(subscription).getNode().getId();

	// Check column's name validity
	final String[] sanitizeColumns = ArrayUtils.isEmpty(columns) ? DEFAULT_COLUMNS : columns;
	checkHeaders(ACCEPTED_COLUMNS, sanitizeColumns);

	// Build CSV header from array
	final String csvHeaders = StringUtils.chop(ArrayUtils.toString(sanitizeColumns)).substring(1).replace(',', ';') + "\n";

	// Build entries
	final String safeEncoding = ObjectUtils.defaultIfNull(encoding, StandardCharsets.UTF_8.name());
	csvForBean
			.toBean(InstanceUpload.class, new InputStreamReader(
					new SequenceInputStream(new ByteArrayInputStream(csvHeaders.getBytes(safeEncoding)), uploadedFile), safeEncoding))
			.stream().filter(Objects::nonNull).forEach(i -> persist(i, subscription, term, ramMultiplier));
}
 
開發者ID:ligoj,項目名稱:plugin-prov,代碼行數:46,代碼來源:ProvQuoteInstanceResource.java

示例2: getVersion

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public String getVersion(final Map<String, String> parameters) throws Exception {
	final FortifyCurlProcessor processor = new FortifyCurlProcessor();
	// Check the user can log-in to Fortify
	authenticate(parameters, processor);

	final String url = StringUtils.appendIfMissing(parameters.get(PARAMETER_URL), "/") + "api/v1/userSession/info";
	final CurlRequest request = new CurlRequest("POST", url, null, "Accept: application/json");
	request.setSaveResponse(true);
	processor.process(request);
	final String content = ObjectUtils.defaultIfNull(request.getResponse(), "{}");
	final ObjectMapper mapper = new ObjectMapper();
	final Map<String, ?> data = MapUtils
			.emptyIfNull((Map<String, ?>) mapper.readValue(content, Map.class).get("data"));
	final String version = (String) data.get("webappVersion");
	processor.close();
	return version;
}
 
開發者ID:ligoj,項目名稱:plugin-security-fortify,代碼行數:20,代碼來源:FortifyPluginResource.java

示例3: findAll

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
@Override
public Page<UserOrg> findAll(final Collection<GroupOrg> requiredGroups, final Set<String> companies, final String criteria,
		final Pageable pageable) {
	// Create the set with the right comparator
	final List<Sort.Order> orders = IteratorUtils.toList(ObjectUtils.defaultIfNull(pageable.getSort(), new ArrayList<Sort.Order>()).iterator());
	orders.add(DEFAULT_ORDER);
	final Sort.Order order = orders.get(0);
	Comparator<UserOrg> comparator = ObjectUtils.defaultIfNull(COMPARATORS.get(order.getProperty()), DEFAULT_COMPARATOR);
	if (order.getDirection() == Direction.DESC) {
		comparator = Collections.reverseOrder(comparator);
	}
	final Set<UserOrg> result = new TreeSet<>(comparator);

	// Filter the users traversing firstly the required groups and their members, the companies, then the criteria
	final Map<String, UserOrg> users = findAll();
	if (requiredGroups == null) {
		// No constraint on group
		addFilteredByCompaniesAndPattern(users.keySet(), companies, criteria, result, users);
	} else {
		// User must be within one the given groups
		for (final GroupOrg requiredGroup : requiredGroups) {
			addFilteredByCompaniesAndPattern(requiredGroup.getMembers(), companies, criteria, result, users);
		}
	}

	// Apply in-memory pagination
	return inMemoryPagination.newPage(result, pageable);
}
 
開發者ID:ligoj,項目名稱:plugin-id-ldap,代碼行數:29,代碼來源:UserLdapRepository.java

示例4: Entry

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
private Entry(Object message, Profiler.Entry parentEntry, Profiler.Entry firstEntry) {
    this.subEntries = new ArrayList(4);
    this.message = message;
    this.startTime = System.currentTimeMillis();
    this.parentEntry = parentEntry;
    this.firstEntry = (Profiler.Entry)ObjectUtils.defaultIfNull(firstEntry, this);
    this.baseTime = firstEntry == null ? 0L : firstEntry.startTime;
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:9,代碼來源:Profiler.java

示例5: addCost

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
/**
 * Add a cost to the quote related to given resource entity. The global cost is
 * not deeply computed, only delta is applied.
 * 
 * @param entity
 *            The configured entity, related to a quote.
 * @param costUpdater
 *            The function used to compute the new cost.
 * @param <T>
 *            The entity type holding the cost.
 * @return The new computed cost.
 */
default <T extends Costed> FloatingCost addCost(final T entity, final Function<T, FloatingCost> costUpdater) {
	// Save the previous costs
	final double oldCost = ObjectUtils.defaultIfNull(entity.getCost(), 0d);
	final double oldMaxCost = ObjectUtils.defaultIfNull(entity.getMaxCost(), 0d);

	// Process the update of this entity
	final FloatingCost newCost = costUpdater.apply(entity);

	// Report the delta to the quote
	final ProvQuote configuration = entity.getConfiguration();
	configuration.setCost(round(configuration.getCost() + entity.getCost() - oldCost));
	configuration.setMaxCost(round(configuration.getMaxCost() + entity.getMaxCost() - oldMaxCost));
	return newCost;
}
 
開發者ID:ligoj,項目名稱:plugin-prov,代碼行數:27,代碼來源:QuoteRelated.java

示例6: handleException

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
@Override
public void handleException(Throwable exception, ExceptionContext context) {
    String message = "Error" + ((context.getSourceName() != null) ? (" in " + context.getSourceName()) : "") + ": ";

    System.err.println(message);
    Throwable cause = ObjectUtils.defaultIfNull(context.getEngine().getKnowledgeBaseManager().unwrapKnowledgeBaseException(exception),
            ExceptionUtils.getRootCause(exception));
    if (cause != null) {
        cause.printStackTrace();
    } else {
        exception.printStackTrace();
    }
}
 
開發者ID:softelnet,項目名稱:sponge,代碼行數:14,代碼來源:SystemErrExceptionHandler.java

示例7: getCommandWithDefaults

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
private String getCommandWithDefaults(AquaRevengArgs args, String username, String password, String dbHost, String dbSchema, String outputFile) {
    return "    SqlServerDdlReveng " +
            " " + ObjectUtils.defaultIfNull(args.getOutputPath(), outputFile) +
            " " + ObjectUtils.defaultIfNull(args.getDbHost(), dbHost) +
            " " + ObjectUtils.defaultIfNull(args.getDbSchema(), dbSchema) +
            " " + ObjectUtils.defaultIfNull(args.getUsername(), username) +
            " " + ObjectUtils.defaultIfNull(args.getPassword(), password);
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:9,代碼來源:MsSqlReveng.java

示例8: getPhysicalSchemaPrefixInternal

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
public String getPhysicalSchemaPrefixInternal(String schema) {
    Validate.isTrue(getAllSchemas().collect(Schema.TO_NAME).contains(schema),
            "Schema does not exist in the environment. Requested schema: " + schema
                    + "; available schemas: " + getSchemaNames().makeString(","));

    return ObjectUtils.defaultIfNull(this.schemaNameOverrides.get(schema), schema);
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:8,代碼來源:Environment.java

示例9: getCommandWithDefaults

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
private String getCommandWithDefaults(AquaRevengArgs args, String username, String password, String dbServer, String dbSchema, String outputFile) {
    return "    db2look " +
            "-d " + ObjectUtils.defaultIfNull(args.getDbServer(), dbServer) + " " +
            "-z " + ObjectUtils.defaultIfNull(args.getDbSchema(), dbSchema) + " " +
            "-i " + ObjectUtils.defaultIfNull(args.getUsername(), username) + " " +
            "-w " + ObjectUtils.defaultIfNull(args.getPassword(), password) + " " +
            "-o " + ObjectUtils.defaultIfNull(args.getOutputPath(), outputFile) + " " +
            "-cor -e -td ~ ";
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:10,代碼來源:Db2lookReveng.java

示例10: getCommandWithDefaults

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
private String getCommandWithDefaults(AquaRevengArgs args, String username, String password, String dbHost, String dbPort, String dbSchema, String outputDirectory) {
    return "    C:\\Sybase_15_5_x64\\ASEP\\bin\\ddlgen " +
            "-U " + ObjectUtils.defaultIfNull(args.getUsername(), username) + " " +
            "-P " + ObjectUtils.defaultIfNull(args.getPassword(), password) + " " +
            "-S " + ObjectUtils.defaultIfNull(args.getDbHost(), dbHost) + ":" + ObjectUtils.defaultIfNull(args.getDbPort(), dbPort) + " " +
            "-D " + ObjectUtils.defaultIfNull(args.getDbSchema(), dbSchema) + " " +
            "-O " + ObjectUtils.defaultIfNull(args.getOutputDir(), outputDirectory);
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:9,代碼來源:AseDdlgenReveng.java

示例11: setRegisteredServices

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
public void setRegisteredServices(final List registeredServices) {
    this.registeredServices = ObjectUtils.defaultIfNull(registeredServices, new ArrayList<>());
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:4,代碼來源:InMemoryServiceRegistry.java

示例12: getValue

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
@Override
public Object getValue(final CustomField customField, final CustomFieldValue value) {
	return ObjectUtils.defaultIfNull(value.getStringValue(), value.getTextValue());
}
 
開發者ID:ligoj,項目名稱:plugin-bt-jira,代碼行數:5,代碼來源:IdentityEditor.java

示例13: getDeployVersion

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
private String getDeployVersion(DeployExecution deployExecution) {
    return ObjectUtils.defaultIfNull(deployExecution.getProductVersion(), "no-version-available");
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:4,代碼來源:DefaultRollbackDetector.java

示例14: persist

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
private void persist(final InstanceUpload upload, final int subscription, final String defaultTerm, final Integer ramMultiplier) {
	final QuoteInstanceEditionVo vo = new QuoteInstanceEditionVo();
	vo.setCpu(round(ObjectUtils.defaultIfNull(upload.getCpu(), 0d)));
	vo.setEphemeral(upload.isEphemeral());
	vo.setInternet(upload.getInternet());
	vo.setMaxVariableCost(upload.getMaxVariableCost());
	vo.setMaxQuantity(Optional.ofNullable(upload.getMaxQuantity()).map(q -> q <= 0 ? null : q).orElse(null));
	vo.setMinQuantity(upload.getMinQuantity());
	vo.setName(upload.getName());
	vo.setLocation(upload.getLocation());
	vo.setUsage(upload.getUsage() == null ? null : resource.findConfigured(usageRepository, upload.getUsage()).getName());
	vo.setRam(ObjectUtils.defaultIfNull(ramMultiplier, 1) * ObjectUtils.defaultIfNull(upload.getRam(), 0).intValue());
	vo.setSubscription(subscription);

	// Choose the required term
	final String term = upload.getTerm() == null ? defaultTerm : upload.getTerm();

	// Find the lowest price
	final ProvInstancePrice instancePrice = validateLookup("instance",
			lookup(subscription, vo.getCpu(), vo.getRam(), upload.getConstant(), upload.getOs(), upload.getType(), term,
					upload.isEphemeral(), upload.getLocation(), upload.getUsage()),
			upload.getName());

	vo.setPrice(instancePrice.getId());
	final UpdatedCost newInstance = create(vo);
	final int qi = newInstance.getId();

	// Storage part
	final Integer size = Optional.ofNullable(upload.getDisk()).map(Double::intValue).orElse(0);
	if (size > 0) {
		// Size is provided
		final QuoteStorageEditionVo svo = new QuoteStorageEditionVo();

		// Default the storage latency to HOT when not specified
		final ProvStorageLatency latency = ObjectUtils.defaultIfNull(upload.getLatency(), ProvStorageLatency.LOW);

		// Find the nicest storage
		svo.setType(storageResource.lookup(subscription, size, latency, qi, upload.getOptimized(), upload.getLocation()).stream()
				.findFirst().orElseThrow(() -> new ValidationJsonException("storage", "NotNull")).getPrice().getType().getName());

		// Default the storage name to the instance name
		svo.setName(vo.getName());
		svo.setQuoteInstance(qi);
		svo.setSize(size);
		svo.setSubscription(subscription);
		storageResource.create(svo);
	}

}
 
開發者ID:ligoj,項目名稱:plugin-prov,代碼行數:50,代碼來源:ProvQuoteInstanceResource.java

示例15: get

import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> T get(String name, T defaultValue) {
    return (T) ObjectUtils.defaultIfNull(doGet(name, false), defaultValue);
}
 
開發者ID:softelnet,項目名稱:sponge,代碼行數:6,代碼來源:MapVariables.java


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