Skip to content
Permalink
Browse files

Improved: Inline ‘UtilGenerics#toList’

(OFBIZ-11141)


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1863498 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Jul 20, 2019
1 parent 365b044 commit 2f12b17663452651f7eac69e31a8bc1c6647ff2e
@@ -85,11 +85,4 @@ private UtilGenerics() {}
public static <T> Set<T> checkSet(Object object) {
return cast(object);
}

/** Returns the Object argument as a parameterized List if the Object argument
* is an instance of List. Otherwise returns null.
*/
public static <T> List<T> toList(Object obj) {
return (obj instanceof List) ? cast(obj) : null;
}
}
@@ -58,7 +58,8 @@ public void testJSONToList() throws Exception {
list.add("field1");
list.add("field2");
JSON json = JSON.from(list);
convertedList = UtilGenerics.toList(converter.convert(json));
Object obj = converter.convert(json);
convertedList = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
assertEquals("JSON to List", list, convertedList);
}

@@ -366,7 +366,8 @@ public static EntityCondition createSingleCondition(ModelField modelField, Strin
fieldOp = entityOperators.get(operation);
}
} else {
if (UtilValidate.isNotEmpty(UtilGenerics.toList(fieldValue))) {
List<Object> fieldList = (fieldValue instanceof List) ? UtilGenerics.cast(fieldValue) : null;
if (UtilValidate.isNotEmpty(fieldList)) {
fieldOp = EntityOperator.IN;
} else {
fieldOp = EntityOperator.EQUALS;
@@ -772,7 +772,8 @@ public void accept(ModelActionVisitor visitor) throws Exception {
public Object getInMemoryPersistedFromField(Object storeAgent, Map<String, Object> context) {
Object newValue = null;
String originalName = this.fromField.getOriginalName();
List<String> currentWidgetTrail = UtilGenerics.toList(context.get("_WIDGETTRAIL_"));
Object obj = context.get("_WIDGETTRAIL_");
List<String> currentWidgetTrail = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
List<String> trailList = new ArrayList<>();
if (currentWidgetTrail != null) {
trailList.addAll(currentWidgetTrail);
@@ -869,7 +870,8 @@ public void runAction(Map<String, Object> context) {
}
if (this.toScope != null && "user".equals(this.toScope)) {
String originalName = this.field.getOriginalName();
List<String> currentWidgetTrail = UtilGenerics.toList(context.get("_WIDGETTRAIL_"));
Object obj = context.get("_WIDGETTRAIL_");
List<String> currentWidgetTrail = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
String newKey = "";
if (currentWidgetTrail != null) {
newKey = StringUtil.join(currentWidgetTrail, "|");
@@ -885,7 +887,8 @@ public void runAction(Map<String, Object> context) {
}
} else if (this.toScope != null && "application".equals(this.toScope)) {
String originalName = this.field.getOriginalName();
List<String> currentWidgetTrail = UtilGenerics.toList(context.get("_WIDGETTRAIL_"));
Object obj = context.get("_WIDGETTRAIL_");
List<String> currentWidgetTrail = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
String newKey = "";
if (currentWidgetTrail != null) {
newKey = StringUtil.join(currentWidgetTrail, "|");
@@ -771,9 +771,10 @@ public void renderWidgetString(Appendable writer, Map<String, Object> context, S
}

UtilGenerics.<MapStack<String>>cast(context).push();
Object obj = context.get("_WIDGETTRAIL_");

// build the widgetpath
List<String> widgetTrail = UtilGenerics.toList(context.get("_WIDGETTRAIL_"));
List<String> widgetTrail = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
if (widgetTrail == null) {
widgetTrail = new LinkedList<>();
}
@@ -549,7 +549,8 @@ public void renderNodeString(Appendable writer, Map<String, Object> context, Tre
}
}
if (passed) {
List<String> currentNodeTrail = UtilGenerics.toList(context.get("currentNodeTrail"));
Object obj = context.get("currentNodeTrail");
List<String> currentNodeTrail = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
context.put("processChildren", Boolean.TRUE);
// this action will usually obtain the "current" entity
ModelTreeAction.runSubActions(this.actions, context);
@@ -273,13 +273,15 @@ public static void populateContextForRequest(MapStack<String> context, ScreenRen
String externalKeyParam = externalLoginKey == null ? "" : "&amp;externalLoginKey=" + externalLoginKey;
context.put("externalLoginKey", externalLoginKey);
context.put("externalKeyParam", externalKeyParam);
Object obj = request.getAttribute("eventMessageList");

// setup message lists
List<String> eventMessageList = UtilGenerics.toList(request.getAttribute("eventMessageList"));
List<String> eventMessageList = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
if (eventMessageList == null) {
eventMessageList = new LinkedList<>();
}
List<String> errorMessageList = UtilGenerics.toList(request.getAttribute("errorMessageList"));
Object obj1 = request.getAttribute("errorMessageList");
List<String> errorMessageList = (obj1 instanceof List) ? UtilGenerics.cast(obj1) : null;
if (errorMessageList == null) {
errorMessageList = new LinkedList<>();
}
@@ -288,7 +290,8 @@ public static void populateContextForRequest(MapStack<String> context, ScreenRen
eventMessageList.add(UtilFormatOut.replaceString((String) request.getAttribute("_EVENT_MESSAGE_"), "\n", "<br/>"));
request.removeAttribute("_EVENT_MESSAGE_");
}
List<String> msgList = UtilGenerics.toList(request.getAttribute("_EVENT_MESSAGE_LIST_"));
Object obj2 = request.getAttribute("_EVENT_MESSAGE_LIST_");
List<String> msgList = (obj2 instanceof List) ? UtilGenerics.cast(obj2) : null;
if (msgList != null) {
eventMessageList.addAll(msgList);
request.removeAttribute("_EVENT_MESSAGE_LIST_");
@@ -301,7 +304,8 @@ public static void populateContextForRequest(MapStack<String> context, ScreenRen
errorMessageList.add(UtilFormatOut.replaceString((String) session.getAttribute("_ERROR_MESSAGE_"), "\n", "<br/>"));
session.removeAttribute("_ERROR_MESSAGE_");
}
msgList = UtilGenerics.toList(request.getAttribute("_ERROR_MESSAGE_LIST_"));
Object obj3 = request.getAttribute("_ERROR_MESSAGE_LIST_");
msgList = (obj3 instanceof List) ? UtilGenerics.cast(obj3) : null;
if (msgList != null) {
errorMessageList.addAll(msgList);
request.removeAttribute("_ERROR_MESSAGE_LIST_");
@@ -57,7 +57,8 @@ public HtmlTreeRenderer() {}
@Override
public void renderNodeBegin(Appendable writer, Map<String, Object> context, ModelTree.ModelNode node, int depth) throws IOException {
String currentNodeTrailPiped = null;
List<String> currentNodeTrail = UtilGenerics.toList(context.get("currentNodeTrail"));
Object obj = context.get("currentNodeTrail");
List<String> currentNodeTrail = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
if (node.isRootNode()) {
appendWhitespace(writer);
this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context);
@@ -80,7 +81,8 @@ public void renderNodeBegin(Appendable writer, Map<String, Object> context, Mode
// check to see if this node needs to be expanded.
if (hasChildren && node.isExpandCollapse()) {
String targetEntityId = null;
List<String> targetNodeTrail = UtilGenerics.toList(context.get("targetNodeTrail"));
Object obj1 = context.get("targetNodeTrail");
List<String> targetNodeTrail = (obj1 instanceof List) ? UtilGenerics.cast(obj1) : null;
if (depth < targetNodeTrail.size()) {
targetEntityId = targetNodeTrail.get(depth);
}
@@ -118,7 +118,8 @@ public void renderEndingBoundaryComment(Appendable writer, String widgetType, Mo
@Override
public void renderNodeBegin(Appendable writer, Map<String, Object> context, ModelTree.ModelNode node, int depth) throws IOException {
String currentNodeTrailPiped = null;
List<String> currentNodeTrail = UtilGenerics.toList(context.get("currentNodeTrail"));
Object obj = context.get("currentNodeTrail");
List<String> currentNodeTrail = (obj instanceof List) ? UtilGenerics.cast(obj) : null;

String style = "";
if (node.isRootNode()) {
@@ -151,7 +152,8 @@ public void renderNodeBegin(Appendable writer, Map<String, Object> context, Mode
// FIXME: Using a widget model in this way is an ugly hack.
ModelTree.ModelNode.Link expandCollapseLink = null;
String targetEntityId = null;
List<String> targetNodeTrail = UtilGenerics.toList(context.get("targetNodeTrail"));
Object obj1 = context.get("targetNodeTrail");
List<String> targetNodeTrail = (obj1 instanceof List) ? UtilGenerics.cast(obj1) : null;
if (depth < targetNodeTrail.size()) {
targetEntityId = targetNodeTrail.get(depth);
}

0 comments on commit 2f12b17

Please sign in to comment.
You can’t perform that action at this time.