001: package org.drools.brms.client.modeldriven;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.util.HashMap;
020: import java.util.Map;
021:
022: /**
023: * This contains some simple mappings between operators, conditional elements and the human readable
024: * equivalent.
025: *
026: * Yes, I am making the presumption that programmers are not human,
027: * but I think they (we) are cool with that.
028: *
029: * @author Michael Neale
030: */
031: public class HumanReadable {
032:
033: public static Map operatorDisplayMap = new HashMap();
034: public static Map ceDisplayMap = new HashMap();
035: public static Map actionDisplayMap = new HashMap();
036: public static final String[] CONDITIONAL_ELEMENTS = new String[] {
037: "not", "exists", "or" };
038:
039: static {
040: operatorDisplayMap.put("==", "is equal to");
041: operatorDisplayMap.put("!=", "is not equal to");
042: operatorDisplayMap.put("<", "is less than");
043: operatorDisplayMap.put("<=", "less than or equal to");
044: operatorDisplayMap.put(">", "greater than");
045: operatorDisplayMap.put(">=", "greater than or equal to");
046:
047: operatorDisplayMap.put("|| ==", "or equal to");
048: operatorDisplayMap.put("|| !=", "or not equal to");
049: operatorDisplayMap.put("&& !=", "and not equal to");
050: operatorDisplayMap.put("&& >", "and greater than");
051: operatorDisplayMap.put("&& <", "and less than");
052: operatorDisplayMap.put("|| >", "or greater than");
053: operatorDisplayMap.put("|| <", "or less than");
054: operatorDisplayMap.put("&& <", "and less than");
055:
056: operatorDisplayMap
057: .put("|| >=", "or greater than (or equal to)");
058: operatorDisplayMap.put("|| <=", "or less than (or equal to)");
059: operatorDisplayMap.put("&& >=",
060: "and greater than (or equal to)");
061: operatorDisplayMap.put("&& <=", "or less than (or equal to)");
062: operatorDisplayMap.put("&& contains", "and contains");
063: operatorDisplayMap.put("|| contains", "or contains");
064: operatorDisplayMap.put("&& matches", "and matches");
065: operatorDisplayMap.put("|| matches", "or matches");
066: operatorDisplayMap.put("|| excludes", "or excludes");
067: operatorDisplayMap.put("&& excludes", "and excludes");
068:
069: ceDisplayMap.put("not", "There is no");
070: ceDisplayMap.put("exists", "There exists");
071: ceDisplayMap.put("or", "Any of");
072:
073: actionDisplayMap.put("assert", "Assert");
074: actionDisplayMap.put("assertLogical", "Logically assert");
075: actionDisplayMap.put("retract", "Retract");
076: actionDisplayMap.put("set", "Set");
077: actionDisplayMap.put("modify", "Modify");
078:
079: }
080:
081: public static String getOperatorDisplayName(String op) {
082: return lookup(op, operatorDisplayMap);
083: }
084:
085: public static String getCEDisplayName(String ce) {
086: return lookup(ce, ceDisplayMap);
087: }
088:
089: private static String lookup(String ce, Map map) {
090: if (map.containsKey(ce)) {
091: return (String) map.get(ce);
092: } else {
093: return ce;
094: }
095: }
096:
097: public static String getActionDisplayName(String action) {
098: return lookup(action, actionDisplayMap);
099: }
100:
101: }
|