本文整理汇总了Java中org.apache.commons.collections4.MapUtils类的典型用法代码示例。如果您正苦于以下问题:Java MapUtils类的具体用法?Java MapUtils怎么用?Java MapUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MapUtils类属于org.apache.commons.collections4包,在下文中一共展示了MapUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addDefaultParams
import org.apache.commons.collections4.MapUtils; //导入依赖的package包/类
private void addDefaultParams(SolrQuery solrQuery, SolrEndpointConfiguration config) {
if(MapUtils.isNotEmpty(config.getDefaults())){
config.getDefaults().entrySet().stream()
.filter(e -> StringUtils.isNoneBlank(e.getKey()) && e.getValue() != null)
.forEach(e -> {
String param = e.getKey();
Collection<?> values;
if(e.getValue() instanceof Collection){
values = (Collection<?>)e.getValue();
} else if(e.getValue().getClass().isArray()) {
values = Arrays.asList((Object[])e.getValue());
} else {
values = Collections.singleton(e.getValue());
}
Collection<String> strValues = StreamSupport.stream(values.spliterator(), false)
.map(Objects::toString) //convert values to strings
.filter(StringUtils::isNoneBlank) //filter blank values
.collect(Collectors.toList());
if(!strValues.isEmpty()){
solrQuery.add(param, strValues.toArray(new String[strValues.size()]));
}
});
}
}
示例2: setApplicationContext
import org.apache.commons.collections4.MapUtils; //导入依赖的package包/类
@Override
public void setApplicationContext(ApplicationContext ctx) throws BeansException {
if (useRpc) {
// 扫描带有 RpcService 注解的类并初始化 handlerMap 对象
Map<String, Object> serviceBeanMap = ctx.getBeansWithAnnotation(RpcService.class);
if (MapUtils.isNotEmpty(serviceBeanMap)) {
for (Object serviceBean : serviceBeanMap.values()) {
RpcService rpcService = serviceBean.getClass().getAnnotation(RpcService.class);
String serviceName = rpcService.value().getName();
String serviceVersion = rpcService.version();
if (StringUtil.isNotEmpty(serviceVersion)) {
serviceName += "-" + serviceVersion;
}
handlerMap.put(serviceName, serviceBean);
}
}
}
if (useRestFul) {
if (restfulServer == null) {
throw new RuntimeException("restful server bean not be set ,please check it ");
}
}
}
示例3: checkDbMap
import org.apache.commons.collections4.MapUtils; //导入依赖的package包/类
/**
* Checks that mapped stage physical instnames are nonblank and are different from live physical instnames.
* Returns silently if ok.
*/
private void checkDbMap()
{
final String liveLogicalName = liveLogicalDatabase.getLogicalName();
if (MapUtils.isEmpty(dbMap) || !dbMap.containsKey(liveLogicalName))
{
throw new IllegalArgumentException("Live logical database '" + liveLogicalName
+ "' is unmapped, don't know what stage physical instname to create");
}
final String stagePhysicalInstanceName = dbMap.get(liveLogicalName);
if (StringUtils.isBlank(stagePhysicalInstanceName))
{
throw new IllegalArgumentException("You have mapped live logical database '" + liveLogicalName
+ "' to a blank string, we don't know what stage physical instname to create");
}
if (StringUtils.equals(stagePhysicalInstanceName, livePhysicalDatabase.getInstanceName()))
{
throw new IllegalArgumentException("You have mapped live logical database '" + liveLogicalName
+ "' to stage physical instname '" + stagePhysicalInstanceName
+ "', but live physical database is already using that instname");
}
}
示例4: setVariables
import org.apache.commons.collections4.MapUtils; //导入依赖的package包/类
@Override
@SuppressWarnings({ CompilerWarnings.UNCHECKED })
public T setVariables(@Nullable Map<QName, XdmValue> vars) {
this.vars.clear();
if (!MapUtils.isEmpty(vars)) {
this.vars.putAll(vars);
}
return ((T) this);
}
示例5: getVersion
import org.apache.commons.collections4.MapUtils; //导入依赖的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;
}
示例6: init
import org.apache.commons.collections4.MapUtils; //导入依赖的package包/类
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
routerNodes = new ArrayList<>();
mFiler = processingEnv.getFiler();
types = processingEnv.getTypeUtils();
elements = processingEnv.getElementUtils();
typeUtils = new TypeUtils(types, elements);
type_String = elements.getTypeElement("java.lang.String").asType();
logger = new Logger(processingEnv.getMessager());
Map<String, String> options = processingEnv.getOptions();
if (MapUtils.isNotEmpty(options)) {
host = options.get(KEY_HOST_NAME);
logger.info(">>> host is " + host + " <<<");
}
if (host == null || host.equals("")) {
host = "default";
}
logger.info(">>> RouteProcessor init. <<<");
}
示例7: generateRouterTable
import org.apache.commons.collections4.MapUtils; //导入依赖的package包/类
/**
* generate HostRouterTable.txt
*/
private void generateRouterTable() {
String fileName = RouteUtils.genRouterTable(host);
if (FileUtils.createFile(fileName)) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("auto generated, do not change !!!! \n\n");
stringBuilder.append("HOST : " + host + "\n\n");
for (Node node : routerNodes) {
stringBuilder.append(node.getDesc() + "\n");
stringBuilder.append(node.getPath() + "\n");
Map<String, String> paramsType = node.getParamsDesc();
if (MapUtils.isNotEmpty(paramsType)) {
for (Map.Entry<String, String> types : paramsType.entrySet()) {
stringBuilder.append(types.getKey() + ":" + types.getValue() + "\n");
}
}
stringBuilder.append("\n");
}
FileUtils.writeStringToFile(fileName, stringBuilder.toString(), false);
}
}
示例8: main
import org.apache.commons.collections4.MapUtils; //导入依赖的package包/类
public static void main(String[] args) {
// Loader
JsonLoader jsonLoader = new JsonLoader();
// Decoding some examples
HashMap<String, ?> result1 = new JsonDecoder().decode(jsonLoader.getJsonFromResources("example1.json"));
HashMap<String, ?> result2 = new JsonDecoder().decode(jsonLoader.getJsonFromResources("example2.json"));
HashMap<String, ?> result3 = new JsonDecoder().decode(jsonLoader.getJsonFromResources("example3.json"));
// Displaying them
MapUtils.debugPrint(System.out, "0", result1);
System.out.println("-----------------------");
MapUtils.debugPrint(System.out, "0", result2);
System.out.println("-----------------------");
MapUtils.debugPrint(System.out, "0", result3);
}
示例9: getObject
import org.apache.commons.collections4.MapUtils; //导入依赖的package包/类
@Override
public TransportClient getObject() throws Exception {
checkNotNull(settings);
checkArgument(MapUtils.isNotEmpty(inetAddresses));
PreBuiltTransportClient client = new PreBuiltTransportClient(Settings.builder().put(settings).build());
inetAddresses.forEach((key, value) -> {
try {
client.addTransportAddress(
new InetSocketTransportAddress(InetAddress.getByName(key), value));
log.info("add socket transport address [{}:{}] to client", key, value);
} catch (UnknownHostException e) {
throw new IllegalStateException(e);
}
});
this.client = client;
log.info("successful create transport client instance ...");
return client;
}
示例10: parseCommand
import org.apache.commons.collections4.MapUtils; //导入依赖的package包/类
private InstanceCommandStats parseCommand(long instanceId, String command,
Map<String, Object> commandMap, boolean isCommand, int type) {
Long collectTime = MapUtils.getLong(commandMap, ConstUtils.COLLECT_TIME, null);
if (collectTime == null) {
return null;
}
Long count;
if (isCommand) {
count = MapUtils.getLong(commandMap, "cmdstat_" + command.toLowerCase(), null);
} else {
count = MapUtils.getLong(commandMap, command.toLowerCase(), null);
}
if (count == null) {
return null;
}
InstanceCommandStats stats = new InstanceCommandStats();
stats.setCommandCount(count);
stats.setCommandName(command);
stats.setCollectTime(collectTime);
stats.setCreateTime(DateUtil.getDateByFormat(String.valueOf(collectTime), "yyyyMMddHHmm"));
stats.setModifyTime(DateUtil.getDateByFormat(String.valueOf(collectTime), "yyyyMMddHHmm"));
stats.setInstanceId(instanceId);
return stats;
}
示例11: saveStandardStats
import org.apache.commons.collections4.MapUtils; //导入依赖的package包/类
@Override
public boolean saveStandardStats(Map<String, Object> infoMap, Map<String, Object> clusterInfoMap, String ip, int port, String dbType) {
Assert.isTrue(infoMap != null && infoMap.size() > 0);
Assert.isTrue(StringUtils.isNotBlank(ip));
Assert.isTrue(port > 0);
Assert.isTrue(infoMap.containsKey(ConstUtils.COLLECT_TIME), ConstUtils.COLLECT_TIME + " not in infoMap");
long collectTime = MapUtils.getLong(infoMap, ConstUtils.COLLECT_TIME);
StandardStats ss = new StandardStats();
ss.setCollectTime(collectTime);
ss.setIp(ip);
ss.setPort(port);
ss.setDbType(dbType);
if (infoMap.containsKey(RedisConstant.DIFF.getValue())) {
Map<String, Object> diffMap = (Map<String, Object>) infoMap.get(RedisConstant.DIFF.getValue());
ss.setDiffMap(diffMap);
infoMap.remove(RedisConstant.DIFF.getValue());
} else {
ss.setDiffMap(new HashMap<String, Object>(0));
}
ss.setInfoMap(infoMap);
ss.setClusterInfoMap(clusterInfoMap);
int mergeCount = instanceStatsDao.mergeStandardStats(ss);
return mergeCount > 0;
}
示例12: testMaps
import org.apache.commons.collections4.MapUtils; //导入依赖的package包/类
@Test
public void testMaps() {
Map<String, Long> map = new HashMap<String, Long>();
map.put("first", 10L);
map.put("second", 20L);
map.put("third", null);
logger.info("third from map: {}", map.get("third"));
try {
ImmutableMap<String, Long> readMap = ImmutableMap.copyOf(map);
logger.info("third from readMap: {}", readMap.get("third"));
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
logger.info("third from MapUtils: {}", MapUtils.getLong(map, "third", 1000L));
}
示例13: sendSupportEmail
import org.apache.commons.collections4.MapUtils; //导入依赖的package包/类
public void sendSupportEmail(String message, String stackTrace) {
try {
User user = userSessionSource.getUserSession().getUser();
String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timeSource.currentTimestamp());
Map<String, Object> binding = new HashMap<>();
binding.put("timestamp", date);
binding.put("errorMessage", message);
binding.put("stacktrace", stackTrace);
binding.put("systemId", clientConfig.getSystemID());
binding.put("userLogin", user.getLogin());
if (MapUtils.isNotEmpty(additionalExceptionReportBinding)) {
binding.putAll(additionalExceptionReportBinding);
}
reportService.sendExceptionReport(clientConfig.getSupportEmail(), MapUtils.unmodifiableMap(binding));
Notification.show(messages.getMainMessage("exceptionDialog.emailSent"));
} catch (Throwable e) {
log.error("Error sending exception report", e);
Notification.show(messages.getMainMessage("exceptionDialog.emailSendingErr"));
}
}
示例14: loadCaseConversion
import org.apache.commons.collections4.MapUtils; //导入依赖的package包/类
protected void loadCaseConversion(TextInputField.CaseConversionSupported component, Element element) {
final String caseConversion = element.attributeValue("caseConversion");
if (StringUtils.isNotEmpty(caseConversion)) {
component.setCaseConversion(TextInputField.CaseConversion.valueOf(caseConversion));
return;
}
if (resultComponent.getMetaPropertyPath() != null) {
Map<String, Object> annotations = resultComponent.getMetaPropertyPath().getMetaProperty().getAnnotations();
//noinspection unchecked
Map<String, Object> conversion = (Map<String, Object>) annotations.get(CaseConversion.class.getName());
if (MapUtils.isNotEmpty(conversion)) {
ConversionType conversionType = (ConversionType) conversion.get("type");
TextInputField.CaseConversion tfCaseConversion = TextInputField.CaseConversion.valueOf(conversionType.name());
component.setCaseConversion(tfCaseConversion);
}
}
}
示例15: updateSession
import org.apache.commons.collections4.MapUtils; //导入依赖的package包/类
@Override
public void updateSession(Map<String, Object> attributesToUpdate, Set<String> attributesToRemove, String namespace, String id) {
StringBuilder statement = new StringBuilder("UPDATE `").append(bucket).append("` USE KEYS $1");
List<Object> parameters = new ArrayList<>(attributesToUpdate.size() + attributesToRemove.size() + 1);
parameters.add(id);
int parameterIndex = 2;
if (MapUtils.isNotEmpty(attributesToUpdate)) {
statement.append(" SET ");
for (Entry<String, Object> attribute : attributesToUpdate.entrySet()) {
parameters.add(attribute.getValue());
statement.append("data.`").append(namespace).append("`.`").append(attribute.getKey()).append("` = $").append(parameterIndex++).append(",");
}
deleteLastCharacter(statement);
}
if (CollectionUtils.isNotEmpty(attributesToRemove)) {
statement.append(" UNSET ");
attributesToRemove.forEach(name -> statement.append("data.`").append(namespace).append("`.`").append(name).append("`,"));
deleteLastCharacter(statement);
}
executeQuery(statement.toString(), from(parameters));
}