Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright sp42 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ajaxjs.util.map;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Stack;
import com.ajaxjs.util.map.ListMapConfig.Context;
/**
* 遍历 ListMap 或 MapList
*
* @author sp42 [email protected]
*
*/
public class ListMap {
/**
* 遍历一个 MapList
*
* @param map 输入的 MapList
* @param config 关于回调函数的配置
*/
public static void traveler(Map map, ListMapConfig config) {
traveler(map, new Context(), null, 0, config);
}
/**
* 遍历一个 MapList
*
* @param map 输入的 MapList
* @param fristCtx 用于是否退出遍历的变量
* @param superMap 父级 Map
* @param level 深度
* @param config 关于回调函数的配置
*/
@SuppressWarnings("unchecked")
public static void traveler(Map map, Context fristCtx, Map superMap, int level,
ListMapConfig config) {
if (config != null && config.mapHandler != null && !config.mapHandler.execute(map, superMap, level))
return;
for (String key : map.keySet()) {
if (fristCtx.isStop()) // 回调控制返回
return;
Object value = map.get(key);
if (config != null && config.mapEntryHandler != null
&& !config.mapEntryHandler.execute(key, value, map, superMap, level)) {
fristCtx.setStop(true);
return;
}
if (value != null && (value instanceof List || value instanceof Map)) {
if (config != null && config.newKey != null)
config.newKey.accept(key);
if (value instanceof Map)
traveler((Map) value, fristCtx, map, level + 1, config);
if (value instanceof List)
traveler((List