本文整理匯總了Java中org.apache.commons.collections.MapUtils.getString方法的典型用法代碼示例。如果您正苦於以下問題:Java MapUtils.getString方法的具體用法?Java MapUtils.getString怎麽用?Java MapUtils.getString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.collections.MapUtils
的用法示例。
在下文中一共展示了MapUtils.getString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: configRoleResources
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
/**
* 配置角色-資源關係
* @param request
* @param response
* @param parameter
* @return
*/
@RequestMapping(value="/admin/role/config/submit", method=POST, consumes=APPLICATION_JSON, produces=APPLICATION_JSON)
@HttpAccessLogging(title="係統管理/角色管理/配置角色資源關係")
public Object configRoleResources(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String,Object> parameter) {
List<Long> resourceIdList = new ArrayList<Long>();
String resourceIds = MapUtils.getString(parameter, "resourceIds");
Long roleId = MapUtils.getLong(parameter, "roleId");
if(!StringUtils.isEmpty(resourceIds)){
String[] resourceIdArray = resourceIds.split(",");
if(resourceIdArray != null && resourceIdArray.length > 0){
for(String resourceId : resourceIdArray){
resourceIdList.add(Long.valueOf(resourceId));
}
}
}
LoginToken<AdminUser> loginToken = ShiroUtils.getSessionAttribute(LoginToken.LOGIN_TOKEN_SESSION_KEY);
adminRoleService.configRoleResources(roleId, resourceIdList, loginToken.getLoginId(), DateTimeUtils.formatNow());
return genSuccessResult("配置成功!", null);
}
示例2: addUserRoles
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
/**
* 添加用戶-角色配置
* @param request
* @param response
* @param userId
* @param roleIds
* @return
*/
@RequestMapping(value="/admin/user/config/add", method=POST, consumes=APPLICATION_JSON, produces=APPLICATION_JSON)
@HttpAccessLogging(title="係統管理/用戶管理/添加用戶角色配置")
public Object addUserRoles(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String,Object> parameter) {
Long userId = MapUtils.getLong(parameter, "userId");
String roleIds = MapUtils.getString(parameter, "roleIds");
List<Long> roleIdList = new ArrayList<Long>();
if(!StringUtils.isEmpty(roleIds)){
String[] roleIdArray = roleIds.split(",");
if(roleIdArray != null && roleIdArray.length > 0){
for(String roleId : roleIdArray){
roleIdList.add(Long.valueOf(roleId));
}
}
}
LoginToken<AdminUser> loginToken = ShiroUtils.getSessionAttribute(LoginToken.LOGIN_TOKEN_SESSION_KEY);
AdminUser user = new AdminUser();
user.setUserId(userId);
adminUserService.addUserRoles(user, roleIdList, loginToken.getLoginId(), DateTimeUtils.formatNow());
return genSuccessResult("添加成功!", null);
}
示例3: delUserRoles
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
/**
* 刪除戶-角色配置
* @param request
* @param response
* @param userId
* @param roleIds
* @return
*/
@RequestMapping(value="/admin/user/config/del", method=POST, consumes=APPLICATION_JSON, produces=APPLICATION_JSON)
@HttpAccessLogging(title="係統管理/用戶管理/刪除用戶角色配置")
public Object delUserRoles(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String,Object> parameter) {
Long userId = MapUtils.getLong(parameter, "userId");
String roleIds = MapUtils.getString(parameter, "roleIds");
List<Long> roleIdList = new ArrayList<Long>();
if(!StringUtils.isEmpty(roleIds)){
String[] roleIdArray = roleIds.split(",");
if(roleIdArray != null && roleIdArray.length > 0){
for(String roleId : roleIdArray){
roleIdList.add(Long.valueOf(roleId));
}
}
}
AdminUser user = new AdminUser();
user.setUserId(userId);
adminUserService.delUserRoles(user, roleIdList);
return genSuccessResult("刪除成功!", null);
}
示例4: getMachineInstanceCountMap
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
@Override
public Map<String, Integer> getMachineInstanceCountMap() {
List<Map<String,Object>> mapList = instanceDao.getMachineInstanceCountMap();
if (CollectionUtils.isEmpty(mapList)) {
return Collections.emptyMap();
}
Map<String, Integer> resultMap = new HashMap<String, Integer>();
for(Map<String,Object> map : mapList) {
String ip = MapUtils.getString(map, "ip", "");
if (StringUtils.isBlank(ip)) {
continue;
}
int count = MapUtils.getIntValue(map, "count");
resultMap.put(ip, count);
}
return resultMap;
}
示例5: getMaster
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
@Override
public HostAndPort getMaster(String ip, int port, String password) {
JedisPool jedisPool = maintainJedisPool(ip, port, password);
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
String info = jedis.info(RedisConstant.Replication.getValue());
Map<RedisConstant, Map<String, Object>> infoMap = processRedisStats(info);
Map<String, Object> map = infoMap.get(RedisConstant.Replication);
if (map == null) {
return null;
}
String masterHost = MapUtils.getString(map, RedisInfoEnum.master_host.getValue(), null);
int masterPort = MapUtils.getInteger(map, RedisInfoEnum.master_port.getValue(), 0);
if (StringUtils.isNotBlank(masterHost) && masterPort > 0) {
return new HostAndPort(masterHost, masterPort);
}
return null;
} catch (Exception e) {
logger.error("{}:{} getMaster failed {}", ip, port, e.getMessage(), e);
return null;
} finally {
if (jedis != null)
jedis.close();
}
}
示例6: getInstanceSlowLogCountMapByAppId
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
@Override
public Map<String, Long> getInstanceSlowLogCountMapByAppId(Long appId, Date startDate, Date endDate) {
try {
List<Map<String, Object>> list = instanceSlowLogDao.getInstanceSlowLogCountMapByAppId(appId, startDate, endDate);
if (CollectionUtils.isEmpty(list)) {
return Collections.emptyMap();
}
Map<String, Long> resultMap = new LinkedHashMap<String, Long>();
for (Map<String, Object> map : list) {
long count = MapUtils.getLongValue(map, "count");
String hostPort = MapUtils.getString(map, "hostPort");
if (StringUtils.isNotBlank(hostPort)) {
resultMap.put(hostPort, count);
}
}
return resultMap;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return Collections.emptyMap();
}
}
示例7: keyList
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
/**
* 將列表轉換成Key - List<Map<String,Object>> 形式,方便取值,如果key值重複則在列表中添加,如果Key值取不到或者為空則使用默認值
*
* @param list 列表
* @param key 作為key 的屬性名稱
* @param defaultKey Key 的默認值
* @param <T> 任意類型
* @return Map
*/
public static <T> Map<String, List<Map<String, T>>> keyList(List<Map<String, T>> list, String key,
String defaultKey) {
Map<String, List<Map<String, T>>> result = new LinkedHashMap<String, List<Map<String, T>>>();
if (list == null || list.size() == 0)
return result;
for (Map<String, T> map : list) {
String keyValue = MapUtils.getString(map, key, defaultKey);
if (result.containsKey(keyValue)) {
result.get(keyValue).add(map);
} else {
List<Map<String, T>> tempList = new ArrayList<>();
tempList.add(map);
result.put(keyValue, tempList);
}
}
return result;
}
示例8: s3Endpoint
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
private URI s3Endpoint(String keyName) {
String endpoint = MapUtils.getString(copierOptions, keyName, null);
if (endpoint == null) {
return null;
}
return URI.create(endpoint);
}
示例9: error
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
/**
* 定義500的錯誤JSON信息
*/
@RequestMapping()
@ResponseBody
public ResponseEntity<RestResp> error(HttpServletRequest request) {
Map<String, Object> body = getErrorAttributes(request,
isIncludeStackTrace(request, MediaType.TEXT_HTML));
String path = MapUtils.getString(body, "path");
String message = MapUtils.getString(body, "message");
RestResp restResp = new RestResp(RestResp.ERROR, message, path);
if (MapUtils.getInteger(body, "status") == 404) {
restResp = new RestResp(RestResp.NOT_FOUND, "訪問的路徑不存在", path);
}
return new ResponseEntity<>(restResp, HttpStatus.OK);
}
示例10: action
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
@Override
public void action(JobExecutionContext context) {
try {
long start = System.currentTimeMillis();
SchedulerContext schedulerContext = context.getScheduler().getContext();
ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY);
// 應用相關
InspectHandler inspectHandler;
JobDataMap jobDataMap = context.getMergedJobDataMap();
String inspectorType = MapUtils.getString(jobDataMap, "inspectorType");
if (StringUtils.isBlank(inspectorType)) {
logger.error("=====================InspectorJob:inspectorType is null=====================");
return;
} else if (inspectorType.equals("host")) {
inspectHandler = applicationContext.getBean("hostInspectHandler", InspectHandler.class);
} else if (inspectorType.equals("app")) {
inspectHandler = applicationContext.getBean("appInspectHandler", InspectHandler.class);
} else {
logger.error("=====================InspectorJob:inspectorType not match:{}=====================", inspectorType);
return;
}
inspectHandler.handle();
long end = System.currentTimeMillis();
logger.info("=====================InspectorJob {} Done! cost={} ms=====================",
inspectHandler.getClass().getSimpleName(), (end - start));
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
示例11: getRedisVersion
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
@Override
public String getRedisVersion(long appId, String ip, int port) {
Map<RedisConstant, Map<String, Object>> infoAllMap = getInfoStats(appId, ip, port);
if (MapUtils.isEmpty(infoAllMap)) {
return null;
}
Map<String, Object> serverMap = infoAllMap.get(RedisConstant.Server);
if (MapUtils.isEmpty(serverMap)) {
return null;
}
return MapUtils.getString(serverMap, "redis_version");
}
示例12: keyMap
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
/**
* 將列表轉換成Key - Map 形式,方便取值,如果key值不唯一,則將會覆蓋原值,謹慎使用
*
* @param list 數據源
* @param key 作為Key的屬性名稱
* @param <T> 任意類型
* @return Map
*/
public static <T> Map<String, Map<String, T>> keyMap(List<Map<String, T>> list, String key) {
Map<String, Map<String, T>> result = new HashMap<String, Map<String, T>>();
if (list == null || list.size() == 0)
return result;
for (Map<String, T> map : list) {
String value = MapUtils.getString(map, key);
if (StringUtils.isNotBlank(value)) {
result.put(value, map);
}
}
return result;
}
示例13: inspect
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
@Override
public boolean inspect(Map<InspectParamEnum, Object> paramMap) {
final String host = MapUtils.getString(paramMap, InspectParamEnum.SPLIT_KEY);
List<InstanceInfo> list = (List<InstanceInfo>) paramMap.get(InspectParamEnum.INSTANCE_LIST);
outer:
for (InstanceInfo info : list) {
final int port = info.getPort();
final int type = info.getType();
final long appId = info.getAppId();
int status = info.getStatus();
//非正常節點
if (status != InstanceStatusEnum.GOOD_STATUS.getStatus()) {
continue;
}
if (TypeUtil.isRedisDataType(type)) {
Jedis jedis = redisCenter.getJedis(appId, host, port, REDIS_DEFAULT_TIME, REDIS_DEFAULT_TIME);
try {
Map<String, String> persistenceMap = parseMap(jedis);
if (persistenceMap.isEmpty()) {
logger.error("{}:{} get persistenceMap failed", host, port);
continue;
}
if (!isAofEnabled(persistenceMap)) {
continue;
}
long aofCurrentSize = MapUtils.getLongValue(persistenceMap, RedisInfoEnum.aof_current_size.getValue());
long aofBaseSize = MapUtils.getLongValue(persistenceMap, RedisInfoEnum.aof_base_size.getValue());
//閥值大於60%
long aofThresholdSize = (long) (aofBaseSize * 1.6);
double percentage = getPercentage(aofCurrentSize, aofBaseSize);
if (aofCurrentSize >= aofThresholdSize
//大於64Mb
&& aofCurrentSize > (64 * 1024 * 1024)) {
//bgRewriteAof
boolean isInvoke = invokeBgRewriteAof(jedis);
if (!isInvoke) {
logger.error("{}:{} invokeBgRewriteAof failed", host, port);
continue;
} else {
logger.warn("{}:{} invokeBgRewriteAof started percentage={}", host, port, percentage);
}
while (true) {
try {
//before wait 1s
TimeUnit.SECONDS.sleep(1);
Map<String, String> loopMap = parseMap(jedis);
Integer aofRewriteInProgress = MapUtils.getInteger(loopMap, "aof_rewrite_in_progress", null);
if (aofRewriteInProgress == null) {
logger.error("loop watch:{}:{} return failed", host, port);
break;
} else if (aofRewriteInProgress <= 0) {
//bgrewriteaof Done
logger.warn("{}:{} bgrewriteaof Done lastSize:{}Mb,currentSize:{}Mb", host, port, getMb(aofCurrentSize), getMb(MapUtils.getLongValue(loopMap, "aof_current_size")));
break;
} else {
//wait 1s
TimeUnit.SECONDS.sleep(1);
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
} else {
if (percentage > 50D) {
long currentSize = getMb(aofCurrentSize);
logger.info("checked {}:{} aof increase percentage:{}% currentSize:{}Mb", host, port, percentage, currentSize > 0 ? currentSize : "<1");
}
}
} finally {
jedis.close();
}
}
}
return true;
}
示例14: generate
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
private AppClientValueDistriStatTotal generate(long collectTime, long reportTime, Map<String, Object> map) {
String valueDistri = MapUtils.getString(map, ClientReportConstant.VALUE_DISTRI, "");
ValueSizeDistriEnum valueSizeDistriEnum = ValueSizeDistriEnum.getByValue(valueDistri);
if (valueSizeDistriEnum == null) {
logger.warn("valueDistri {} is wrong, not in enums {}", valueDistri, ValueSizeDistriEnum.values());
}
// 次數
Integer count = MapUtils.getInteger(map, ClientReportConstant.VALUE_COUNT, 0);
// 命令
String command = MapUtils.getString(map, ClientReportConstant.VALUE_COMMAND, "");
if (StringUtils.isBlank(command)) {
logger.warn("command is empty!");
return null;
}
if (excludeCommands.contains(command)) {
return null;
}
// 實例host:port
String hostPort = MapUtils.getString(map, ClientReportConstant.VALUE_HOST_PORT, "");
if (StringUtils.isEmpty(hostPort)) {
logger.warn("hostPort is empty", hostPort);
return null;
}
int index = hostPort.indexOf(":");
if (index <= 0) {
logger.warn("hostPort {} format is wrong", hostPort);
return null;
}
String host = hostPort.substring(0, index);
int port = NumberUtils.toInt(hostPort.substring(index + 1));
// 實例信息
InstanceInfo instanceInfo = clientReportInstanceService.getInstanceInfoByHostPort(host, port);
if (instanceInfo == null) {
// logger.warn("instanceInfo is empty, host is {}, port is {}",
// host, port);
return null;
}
AppClientValueDistriStatTotal stat = new AppClientValueDistriStatTotal();
stat.setAppId(instanceInfo.getAppId());
stat.setCollectTime(collectTime);
stat.setUpdateTime(new Date());
stat.setCommand(command);
stat.setDistributeType(valueSizeDistriEnum.getType());
stat.setCount(count);
return stat;
}
示例15: generate
import org.apache.commons.collections.MapUtils; //導入方法依賴的package包/類
private AppClientExceptionStat generate(String clientIp, long collectTime, long reportTime, Map<String, Object> map) {
// 異常信息
String exceptionClass = MapUtils.getString(map, ClientReportConstant.EXCEPTION_CLASS, "");
Long exceptionCount = MapUtils.getLong(map, ClientReportConstant.EXCEPTION_COUNT, 0L);
int exceptionType = MapUtils.getInteger(map, ClientReportConstant.EXCEPTION_TYPE, ClientExceptionType.REDIS_TYPE.getType());
String host = null;
Integer port = null;
Integer instanceId = null;
long appId;
if (ClientExceptionType.REDIS_TYPE.getType() == exceptionType) {
// 實例host:port
String hostPort = MapUtils.getString(map, ClientReportConstant.EXCEPTION_HOST_PORT, "");
if (StringUtils.isEmpty(hostPort)) {
logger.warn("hostPort is empty", hostPort);
return null;
}
int index = hostPort.indexOf(":");
if (index <= 0) {
logger.warn("hostPort {} format is wrong", hostPort);
return null;
}
host = hostPort.substring(0, index);
port = NumberUtils.toInt(hostPort.substring(index + 1));
// 實例信息
InstanceInfo instanceInfo = clientReportInstanceService.getInstanceInfoByHostPort(host, port);
if (instanceInfo == null) {
// logger.warn("instanceInfo is empty, host is {}, port is {}", host, port);
return null;
}
// 實例id
instanceId = instanceInfo.getId();
// 應用id
appId = instanceInfo.getAppId();
} else {
List<AppClientVersion> appClientVersion = appClientVersionDao.getByClientIp(clientIp);
if (CollectionUtils.isNotEmpty(appClientVersion)) {
appId = appClientVersion.get(0).getAppId();
} else {
appId = 0;
}
}
// 組裝AppClientExceptionStat
AppClientExceptionStat stat = new AppClientExceptionStat();
stat.setAppId(appId);
stat.setClientIp(clientIp);
stat.setReportTime(new Date(reportTime));
stat.setCollectTime(collectTime);
stat.setCreateTime(new Date());
stat.setExceptionClass(exceptionClass);
stat.setExceptionCount(exceptionCount);
stat.setInstanceHost(host);
stat.setInstancePort(port);
stat.setInstanceId(instanceId);
stat.setType(exceptionType);
return stat;
}