Please wait. This can take some minutes ...
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.
com.abubusoft.kripton.map.BindMapVisitor Maven / Gradle / Ivy
package com.abubusoft.kripton.map;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.abubusoft.kripton.exception.KriptonRuntimeException;
public abstract class BindMapVisitor {
public static enum VisitorStatusType {
RUN, STOP
}
@SuppressWarnings("unchecked")
static VisitorStatusType visitMap(String name, Map map, BindMapListener listener, VisitorStatusType status) {
for (Entry item : map.entrySet()) {
if (item.getValue() == null || item.getValue() instanceof String) {
visit(item.getKey(), (String) item.getValue(), listener, status);
} else if (item.getValue() instanceof List) {
visitList(item.getKey(), (List) item.getValue(), listener, status);
} else if (item.getValue() instanceof Map) {
visitMap(item.getKey(), (Map) item.getValue(), listener, status);
}
if (status == VisitorStatusType.STOP)
return status;
}
return status;
}
@SuppressWarnings("unchecked")
static VisitorStatusType visitList(String name, List list, BindMapListener listener, VisitorStatusType status) {
int i = 0;
for (Object item : list) {
if (item == null || item instanceof String) {
visit(name + "." + i, (String) item, listener, status);
} else if (item instanceof List) {
visitList(name + "." + i, (List) item, listener, status);
} else if (item instanceof Map) {
visitMap(name + "." + i, (Map) item, listener, status);
}
i++;
if (status == VisitorStatusType.STOP)
return status;
}
return status;
}
static void visit(String name, String value, BindMapListener listener, VisitorStatusType status) {
listener.onField(name, value, status);
}
@SuppressWarnings("unchecked")
public static void execute(Map map, BindMapListener listener) {
if (listener == null)
throw (new KriptonRuntimeException("listener can not be null"));
if (map == null)
throw (new KriptonRuntimeException("map can not be null"));
VisitorStatusType status = VisitorStatusType.RUN;
for (Entry item : map.entrySet()) {
if (item.getValue() == null || item.getValue() instanceof String) {
visit(item.getKey(), (String) item.getValue(), listener, status);
} else if (item.getValue() instanceof List) {
visitList(item.getKey(), (List) item.getValue(), listener, status);
} else if (item.getValue() instanceof Map) {
visitMap(item.getKey(), (Map) item.getValue(), listener, status);
}
if (status == VisitorStatusType.STOP)
return;
}
}
}