001: package org.drools.eclipse.rulebuilder.modeldriven;
002:
003: import java.util.HashMap;
004: import java.util.Iterator;
005: import java.util.Map;
006: import java.util.Set;
007:
008: /**
009: * This contains some simple mappings between operators, conditional elements
010: * and the human readable equivalent.
011: *
012: * Yes, I am making the presumption that programmers are not human, but I think
013: * they (we) are cool with that.
014: *
015: * @author Michael Neale
016: */
017: public class HumanReadable {
018:
019: public static Map operatorDisplayMap = new HashMap();
020:
021: public static Map ceDisplayMap = new HashMap();
022:
023: public static Map actionDisplayMap = new HashMap();
024:
025: public static final String[] CONDITIONAL_ELEMENTS = new String[] {
026: "not", "exists", "or" };
027:
028: static {
029: operatorDisplayMap.put("==", "is equal to");
030: operatorDisplayMap.put("!=", "is not equal to");
031: operatorDisplayMap.put("<", "is less than");
032: operatorDisplayMap.put("<=", "less than or equal to");
033: operatorDisplayMap.put(">", "greater than");
034: operatorDisplayMap.put(">=", "greater than or equal to");
035:
036: operatorDisplayMap.put("|| ==", "or equal to");
037: operatorDisplayMap.put("|| !=", "or not equal to");
038: operatorDisplayMap.put("&& !=", "and not equal to");
039: operatorDisplayMap.put("&& >", "and greater than");
040: operatorDisplayMap.put("&& <", "and less than");
041: operatorDisplayMap.put("|| >", "or greater than");
042: operatorDisplayMap.put("|| <", "or less than");
043:
044: operatorDisplayMap
045: .put("|| >=", "or greater than (or equal to)");
046: operatorDisplayMap.put("|| <=", "or less than (or equal to)");
047: operatorDisplayMap.put("&& >=",
048: "and greater than (or equal to)");
049: operatorDisplayMap.put("&& <=", "or less than (or equal to)");
050: operatorDisplayMap.put("&& contains", "and contains");
051: operatorDisplayMap.put("|| contains", "or contains");
052: operatorDisplayMap.put("&& matches", "and matches");
053: operatorDisplayMap.put("|| matches", "or matches");
054: operatorDisplayMap.put("|| excludes", "or excludes");
055: operatorDisplayMap.put("&& excludes", "and excludes");
056:
057: ceDisplayMap.put("not", "There is no");
058: ceDisplayMap.put("exists", "There exists");
059: ceDisplayMap.put("or", "Any of");
060:
061: actionDisplayMap.put("assert", "Assert");
062: actionDisplayMap.put("assertLogical", "Logically assert");
063: actionDisplayMap.put("retract", "Retract");
064: actionDisplayMap.put("set", "Set");
065: actionDisplayMap.put("modify", "Modify");
066:
067: }
068:
069: public static String getActionDisplayName(String action) {
070: return lookup(action, actionDisplayMap);
071: }
072:
073: public static String getOperatorDisplayName(String op) {
074: return lookup(op, operatorDisplayMap);
075: }
076:
077: public static String getCEDisplayName(String ce) {
078: return lookup(ce, ceDisplayMap);
079: }
080:
081: private static String lookup(String ce, Map map) {
082: if (map.containsKey(ce)) {
083: return (String) map.get(ce);
084: } else {
085: return ce;
086: }
087: }
088:
089: /**
090: * get operator by its display name
091: *
092: * @param op
093: * operator display name
094: * @return operator
095: */
096: public static String getOperatorName(String op) {
097: Set keys = operatorDisplayMap.keySet();
098: for (Iterator iter = keys.iterator(); iter.hasNext();) {
099: String key = (String) iter.next();
100: if (op.equals(operatorDisplayMap.get(key))) {
101: return key;
102: }
103: }
104: throw new RuntimeException("No operator display name '" + op
105: + "' was found.");
106: }
107:
108: }
|