本文整理匯總了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));
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
示例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);
}
示例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 ~ ";
}
示例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);
}
示例11: setRegisteredServices
import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
public void setRegisteredServices(final List registeredServices) {
this.registeredServices = ObjectUtils.defaultIfNull(registeredServices, new ArrayList<>());
}
示例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());
}
示例13: getDeployVersion
import org.apache.commons.lang3.ObjectUtils; //導入方法依賴的package包/類
private String getDeployVersion(DeployExecution deployExecution) {
return ObjectUtils.defaultIfNull(deployExecution.getProductVersion(), "no-version-available");
}
示例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);
}
}
示例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);
}