Author: doogie
Date: Wed Oct 17 16:19:44 2007 New Revision: 585752 URL: http://svn.apache.org/viewvc?rev=585752&view=rev Log: Java 1.5 markup. Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/FlexibleServletAccessor.java ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/MapStack.java ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java?rev=585752&r1=585751&r2=585752&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java Wed Oct 17 16:19:44 2007 @@ -74,7 +74,7 @@ * Create a combined map from servlet context, session, attributes and parameters * @return The resulting Map */ - public static Map getCombinedMap(HttpServletRequest request) { + public static Map<String, Object> getCombinedMap(HttpServletRequest request) { return getCombinedMap(request, null); } @@ -83,8 +83,8 @@ * -- this method will only use the skip names for session and servlet context attributes * @return The resulting Map */ - public static Map getCombinedMap(HttpServletRequest request, Set namesToSkip) { - FastMap combinedMap = FastMap.newInstance(); + public static Map<String, Object> getCombinedMap(HttpServletRequest request, Set<String> namesToSkip) { + FastMap<String, Object> combinedMap = FastMap.newInstance(); combinedMap.putAll(getServletContextMap(request, namesToSkip)); // bottom level application attributes combinedMap.putAll(getSessionMap(request, namesToSkip)); // session overrides application combinedMap.putAll(getParameterMap(request)); // parameters override session @@ -97,7 +97,7 @@ * Create a map from a HttpServletRequest (parameters) object * @return The resulting Map */ - public static Map getParameterMap(HttpServletRequest request) { + public static Map<String, Object> getParameterMap(HttpServletRequest request) { return getParameterMap(request, null); } @@ -105,8 +105,8 @@ * Create a map from a HttpServletRequest (parameters) object * @return The resulting Map */ - public static Map getParameterMap(HttpServletRequest request, Set<String> namesToSkip) { - Map paramMap = FastMap.newInstance(); + public static Map<String, Object> getParameterMap(HttpServletRequest request, Set<String> namesToSkip) { + Map<String, Object> paramMap = FastMap.newInstance(); // add all the actual HTTP request parameters Enumeration e = request.getParameterNames(); @@ -146,9 +146,9 @@ String value = element.substring(element.indexOf('=') + 1); Object curValue = paramMap.get(name); if (curValue != null) { - List paramList = null; + List<String> paramList = null; if (curValue instanceof List) { - paramList = (List) curValue; + paramList = UtilGenerics.checkList(curValue); paramList.add(value); } else { String paramString = (String) curValue; @@ -166,7 +166,7 @@ if (paramMap.size() == 0) { // nothing found in the parameters; maybe we read the stream instead - Map multiPartMap = (Map) request.getAttribute("multiPartMap"); + Map<String, Object> multiPartMap = UtilGenerics.checkMap(request.getAttribute("multiPartMap")); if (multiPartMap != null && multiPartMap.size() > 0) { paramMap.putAll(multiPartMap); } @@ -184,7 +184,7 @@ * Create a map from a HttpRequest (attributes) object * @return The resulting Map */ - public static Map getAttributeMap(HttpServletRequest request) { + public static Map<String, Object> getAttributeMap(HttpServletRequest request) { return getAttributeMap(request, null); } @@ -192,8 +192,8 @@ * Create a map from a HttpRequest (attributes) object * @return The resulting Map */ - public static Map getAttributeMap(HttpServletRequest request, Set<String> namesToSkip) { - Map attributeMap = FastMap.newInstance(); + public static Map<String, Object> getAttributeMap(HttpServletRequest request, Set<String> namesToSkip) { + Map<String, Object> attributeMap = FastMap.newInstance(); // look at all request attributes Enumeration requestAttrNames = request.getAttributeNames(); @@ -218,7 +218,7 @@ * Create a map from a HttpSession object * @return The resulting Map */ - public static Map getSessionMap(HttpServletRequest request) { + public static Map<String, Object> getSessionMap(HttpServletRequest request) { return getSessionMap(request, null); } @@ -226,8 +226,8 @@ * Create a map from a HttpSession object * @return The resulting Map */ - public static Map getSessionMap(HttpServletRequest request, Set<String> namesToSkip) { - Map sessionMap = FastMap.newInstance(); + public static Map<String, Object> getSessionMap(HttpServletRequest request, Set<String> namesToSkip) { + Map<String, Object> sessionMap = FastMap.newInstance(); HttpSession session = request.getSession(); // look at all the session attributes @@ -253,7 +253,7 @@ * Create a map from a ServletContext object * @return The resulting Map */ - public static Map getServletContextMap(HttpServletRequest request) { + public static Map<String, Object> getServletContextMap(HttpServletRequest request) { return getServletContextMap(request, null); } @@ -261,8 +261,8 @@ * Create a map from a ServletContext object * @return The resulting Map */ - public static Map getServletContextMap(HttpServletRequest request, Set<String> namesToSkip) { - Map servletCtxMap = FastMap.newInstance(); + public static Map<String, Object> getServletContextMap(HttpServletRequest request, Set<String> namesToSkip) { + Map<String, Object> servletCtxMap = FastMap.newInstance(); // look at all servlet context attributes ServletContext servletContext = (ServletContext) request.getAttribute("servletContext"); @@ -284,12 +284,12 @@ return servletCtxMap; } - public static Map makeParamMapWithPrefix(HttpServletRequest request, String prefix, String suffix) { + public static Map<String, Object> makeParamMapWithPrefix(HttpServletRequest request, String prefix, String suffix) { return makeParamMapWithPrefix(request, null, prefix, suffix); } - public static Map makeParamMapWithPrefix(HttpServletRequest request, Map additionalFields, String prefix, String suffix) { - Map paramMap = new HashMap(); + public static Map<String, Object> makeParamMapWithPrefix(HttpServletRequest request, Map<String, Object> additionalFields, String prefix, String suffix) { + Map<String, Object> paramMap = new HashMap<String, Object>(); Enumeration parameterNames = request.getParameterNames(); while (parameterNames.hasMoreElements()) { String parameterName = (String) parameterNames.nextElement(); @@ -308,14 +308,13 @@ } } if (additionalFields != null) { - Iterator i = additionalFields.keySet().iterator(); - while (i.hasNext()) { - String fieldName = (String) i.next(); + for (Map.Entry<String, Object> entry: additionalFields.entrySet()) { + String fieldName = entry.getKey(); if (fieldName.startsWith(prefix)) { if (suffix != null && suffix.length() > 0) { if (fieldName.endsWith(suffix)) { String key = fieldName.substring(prefix.length(), fieldName.length() - (suffix.length() - 1)); - Object value = additionalFields.get(fieldName); + Object value = entry.getValue(); paramMap.put(key, value); // check for image upload data @@ -341,7 +340,7 @@ } } else { String key = fieldName.substring(prefix.length()); - Object value = additionalFields.get(fieldName); + Object value = entry.getValue(); paramMap.put(key, value); // check for image upload data @@ -371,12 +370,12 @@ return paramMap; } - public static List makeParamListWithSuffix(HttpServletRequest request, String suffix, String prefix) { + public static List<Object> makeParamListWithSuffix(HttpServletRequest request, String suffix, String prefix) { return makeParamListWithSuffix(request, null, suffix, prefix); } - public static List makeParamListWithSuffix(HttpServletRequest request, Map additionalFields, String suffix, String prefix) { - List paramList = new ArrayList(); + public static List<Object> makeParamListWithSuffix(HttpServletRequest request, Map<String, Object> additionalFields, String suffix, String prefix) { + List<Object> paramList = new ArrayList<Object>(); Enumeration parameterNames = request.getParameterNames(); while (parameterNames.hasMoreElements()) { String parameterName = (String) parameterNames.nextElement(); @@ -393,18 +392,15 @@ } } if (additionalFields != null) { - Iterator i = additionalFields.keySet().iterator(); - while (i.hasNext()) { - String fieldName = (String) i.next(); + for (Map.Entry<String, Object> entry: additionalFields.entrySet()) { + String fieldName = entry.getKey(); if (fieldName.endsWith(suffix)) { if (prefix != null && prefix.length() > 0) { if (fieldName.startsWith(prefix)) { - Object value = additionalFields.get(fieldName); - paramList.add(value); + paramList.add(entry.getValue()); } } else { - Object value = additionalFields.get(fieldName); - paramList.add(value); + paramList.add(entry.getValue()); } } } @@ -629,18 +625,16 @@ } /** URL Encodes a Map of arguements */ - public static String urlEncodeArgs(Map args) { + public static String urlEncodeArgs(Map<String, Object> args) { return urlEncodeArgs(args, true); } /** URL Encodes a Map of arguements */ - public static String urlEncodeArgs(Map args, boolean useExpandedEntites) { + public static String urlEncodeArgs(Map<String, Object> args, boolean useExpandedEntites) { StringBuilder buf = new StringBuilder(); if (args != null) { - Iterator i = args.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry entry = (Map.Entry) i.next(); - String name = (String) entry.getKey(); + for (Map.Entry<String, Object> entry: args.entrySet()) { + String name = entry.getKey(); Object value = entry.getValue(); String valueStr = null; if (name != null && value != null) { @@ -866,7 +860,7 @@ } public static String stripViewParamsFromQueryString(String queryString) { - Set paramNames = new HashSet(); + Set<String> paramNames = new HashSet<String>(); paramNames.add("VIEW_INDEX"); paramNames.add("VIEW_SIZE"); paramNames.add("viewIndex"); @@ -874,7 +868,7 @@ return stripNamedParamsFromQueryString(queryString, paramNames); } - public static String stripNamedParamsFromQueryString(String queryString, Collection paramNames) { + public static String stripNamedParamsFromQueryString(String queryString, Collection<String> paramNames) { String retStr = null; if (UtilValidate.isNotEmpty(queryString)) { StringTokenizer queryTokens = new StringTokenizer(queryString, "&"); @@ -908,14 +902,11 @@ * There is an additionaly key "row" for each Map that holds the * index of the row. */ - public static Collection parseMultiFormData(Map parameters) { - FastMap rows = new FastMap(); // stores the rows keyed by row number + public static Collection<Map<String, Object>> parseMultiFormData(Map<String, Object> parameters) { + FastMap<Integer, Map<String, Object>> rows = FastMap.newInstance(); // stores the rows keyed by row number // first loop through all the keys and create a hashmap for each ${ROW_SUBMIT_PREFIX}${N} = Y - Iterator keys = parameters.keySet().iterator(); - while (keys.hasNext()) { - String key = (String) keys.next(); - + for (String key: parameters.keySet()) { // skip everything that is not ${ROW_SUBMIT_PREFIX}N if (key == null || key.length() <= ROW_SUBMIT_PREFIX_LENGTH) continue; if (key.indexOf(MULTI_ROW_DELIMITER) <= 0) continue; @@ -924,16 +915,13 @@ // decode the value of N and create a new map for it Integer n = Integer.decode(key.substring(ROW_SUBMIT_PREFIX_LENGTH, key.length())); - Map m = new FastMap(); + Map<String, Object> m = FastMap.newInstance(); m.put("row", n); // special "row" = N tuple rows.put(n, m); // key it to N } // next put all parameters with matching N in the right map - keys = parameters.keySet().iterator(); - while (keys.hasNext()) { - String key = (String) keys.next(); - + for (String key: parameters.keySet()) { // skip keys without DELIMITER and skip ROW_SUBMIT_PREFIX if (key == null) continue; int index = key.indexOf(MULTI_ROW_DELIMITER); @@ -942,7 +930,7 @@ // get the map with index N Integer n = Integer.decode(key.substring(index + MULTI_ROW_DELIMITER_LENGTH, key.length())); // N from ${param}${DELIMITER}${N} - Map map = (Map) rows.get(n); + Map<String, Object> map = rows.get(n); if (map == null) continue; // get the key without the <DELIMITER>N suffix and store it and its value @@ -957,12 +945,9 @@ * Returns a new map containing all the parameters from the input map except for the * multi form parameters (usually named according to the ${param}_o_N notation). */ - public static Map removeMultiFormParameters(Map parameters) { - FastMap filteredParameters = new FastMap(); - Iterator keys = parameters.keySet().iterator(); - while (keys.hasNext()) { - String key = (String) keys.next(); - + public static <V> Map<String, V> removeMultiFormParameters(Map<String, V> parameters) { + FastMap<String, V> filteredParameters = new FastMap<String, V>(); + for (String key: parameters.keySet()) { if (key != null && (key.indexOf(MULTI_ROW_DELIMITER) != -1 || key.indexOf("_useRowSubmit") != -1 || key.indexOf("_rowCount") != -1)) { continue; } @@ -1010,7 +995,7 @@ if (compositeType == null || compositeType.length() == 0) return null; // collect the composite fields into a map - Map data = FastMap.newInstance(); + Map<String, String> data = FastMap.newInstance(); for (Enumeration names = request.getParameterNames(); names.hasMoreElements(); ) { String name = (String) names.nextElement(); if (!name.startsWith(prefix + COMPOSITE_DELIMITER)) continue; @@ -1019,7 +1004,7 @@ String suffix = name.substring(name.indexOf(COMPOSITE_DELIMITER) + COMPOSITE_DELIMITER_LENGTH); // and the value of this parameter - Object value = request.getParameter(name); + String value = request.getParameter(name); // key = suffix, value = parameter data data.put(suffix, value); @@ -1028,10 +1013,10 @@ // handle recomposition of data into the compositeType if ("Timestamp".equals(compositeType)) { - String date = (String) data.get("date"); - String hour = (String) data.get("hour"); - String minutes = (String) data.get("minutes"); - String ampm = (String) data.get("ampm"); + String date = data.get("date"); + String hour = data.get("hour"); + String minutes = data.get("minutes"); + String ampm = data.get("ampm"); if (date == null || date.length() < 10) return null; if (hour == null || hour.length() == 0) return null; if (minutes == null || minutes.length() == 0) return null; @@ -1084,12 +1069,10 @@ } }else{ String initialUserAgent = request.getHeader("User-Agent") != null ? request.getHeader("User-Agent") : ""; - List spiderList = StringUtil.split(UtilProperties.getPropertyValue("url", "link.remove_lsessionid.user_agent_list"), ","); + List<String> spiderList = StringUtil.split(UtilProperties.getPropertyValue("url", "link.remove_lsessionid.user_agent_list"), ","); if (UtilValidate.isNotEmpty(spiderList)) { - Iterator spiderListIter = spiderList.iterator(); - while (spiderListIter.hasNext()) { - String spiderNameElement = (String) spiderListIter.next(); - Pattern p = Pattern.compile("^.*" + spiderNameElement + ".*$", Pattern.CASE_INSENSITIVE); + for (String spiderNameElement: spiderList) { + Pattern p = Pattern.compile("^.*" + spiderNameElement + ".*$", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(initialUserAgent); if (m.find()){ request.setAttribute("_REQUEST_FROM_SPIDER_", "Y"); Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/FlexibleServletAccessor.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/FlexibleServletAccessor.java?rev=585752&r1=585751&r2=585752&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/FlexibleServletAccessor.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/FlexibleServletAccessor.java Wed Oct 17 16:19:44 2007 @@ -25,6 +25,7 @@ import javax.servlet.ServletRequest; import javax.servlet.http.HttpSession; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.string.FlexibleStringExpander; /** @@ -91,7 +92,7 @@ * @param expandContext the context to use for name expansion * @return the object corresponding to this getter class */ - public Object get(ServletRequest request, Map expandContext) { + public Object get(ServletRequest request, Map<String, Object> expandContext) { AttributeAccessor aa = new AttributeAccessor(name, expandContext, this.attributeName, this.fma, this.needsExpand); return aa.get(request); } @@ -101,7 +102,7 @@ * @param expandContext * @return */ - public Object get(HttpSession session, Map expandContext) { + public Object get(HttpSession session, Map<String, Object> expandContext) { AttributeAccessor aa = new AttributeAccessor(name, expandContext, this.attributeName, this.fma, this.needsExpand); return aa.get(session); } @@ -115,7 +116,7 @@ * @param value * @param expandContext */ - public void put(ServletRequest request, Object value, Map expandContext) { + public void put(ServletRequest request, Object value, Map<String, Object> expandContext) { AttributeAccessor aa = new AttributeAccessor(name, expandContext, this.attributeName, this.fma, this.needsExpand); aa.put(request, value); } @@ -129,7 +130,7 @@ * @param value * @param expandContext */ - public void put(HttpSession session, Object value, Map expandContext) { + public void put(HttpSession session, Object value, Map<String, Object> expandContext) { AttributeAccessor aa = new AttributeAccessor(name, expandContext, this.attributeName, this.fma, this.needsExpand); aa.put(session, value); } @@ -139,7 +140,7 @@ * @param expandContext * @return */ - public Object remove(ServletRequest request, Map expandContext) { + public Object remove(ServletRequest request, Map<String, Object> expandContext) { AttributeAccessor aa = new AttributeAccessor(name, expandContext, this.attributeName, this.fma, this.needsExpand); return aa.remove(request); } @@ -149,7 +150,7 @@ * @param expandContext * @return */ - public Object remove(HttpSession session, Map expandContext) { + public Object remove(HttpSession session, Map<String, Object> expandContext) { AttributeAccessor aa = new AttributeAccessor(name, expandContext, this.attributeName, this.fma, this.needsExpand); return aa.remove(session); } @@ -189,7 +190,7 @@ } protected static class AttributeAccessor implements Serializable { - protected Map expandContext; + protected Map<String, Object> expandContext; protected String attributeName; protected FlexibleMapAccessor fma; protected boolean isListReference; @@ -199,7 +200,7 @@ protected int openBrace; protected int closeBrace; - public AttributeAccessor(String origName, Map expandContext, String defAttributeName, FlexibleMapAccessor defFma, boolean needsExpand) { + public AttributeAccessor(String origName, Map<String, Object> expandContext, String defAttributeName, FlexibleMapAccessor defFma, boolean needsExpand) { attributeName = defAttributeName; fma = defFma; @@ -273,7 +274,7 @@ } } - protected void putInList(List lst, Object value) { + protected <T> void putInList(List<T> lst, T value) { //if brackets are empty, append to list if (isAddAtEnd) { lst.add(value); @@ -286,10 +287,10 @@ } } - public void put(ServletRequest request, Object value) { + public <T> void put(ServletRequest request, T value) { if (fma == null) { if (isListReference) { - List lst = (List) request.getAttribute(attributeName); + List<T> lst = UtilGenerics.checkList(request.getAttribute(attributeName)); putInList(lst, value); } else { request.setAttribute(attributeName, value); @@ -297,18 +298,18 @@ } else { Object theObj = request.getAttribute(attributeName); if (isListReference) { - List lst = (List) theObj; - fma.put((Map) lst.get(listIndex), value); + List<T> lst = UtilGenerics.checkList(theObj); + fma.put(UtilGenerics.checkMap(lst.get(listIndex), String.class, Object.class), value); } else { - fma.put((Map) theObj, value); + fma.put(UtilGenerics.checkMap(theObj, String.class, Object.class), value); } } } - public void put(HttpSession session, Object value) { + public <T> void put(HttpSession session, T value) { if (fma == null) { if (isListReference) { - List lst = (List) session.getAttribute(attributeName); + List<T> lst = UtilGenerics.checkList(session.getAttribute(attributeName)); putInList(lst, value); } else { session.setAttribute(attributeName, value); @@ -316,10 +317,10 @@ } else { Object theObj = session.getAttribute(attributeName); if (isListReference) { - List lst = (List) theObj; - fma.put((Map) lst.get(listIndex), value); + List<T> lst = UtilGenerics.checkList(theObj); + fma.put(UtilGenerics.checkMap(lst.get(listIndex), String.class, Object.class), value); } else { - fma.put((Map) theObj, value); + fma.put(UtilGenerics.checkMap(theObj, String.class, Object.class), value); } } } @@ -328,14 +329,14 @@ if (fma != null) { Object theObj = request.getAttribute(attributeName); if (isListReference) { - List lst = (List) theObj; - return fma.remove((Map) lst.get(listIndex)); + List<?> lst = UtilGenerics.checkList(theObj); + return fma.remove(UtilGenerics.checkMap(lst.get(listIndex), String.class, Object.class)); } else { - return fma.remove((Map) theObj); + return fma.remove(UtilGenerics.checkMap(theObj, String.class, Object.class)); } } else { if (isListReference) { - List lst = (List) request.getAttribute(attributeName); + List<?> lst = UtilGenerics.checkList(request.getAttribute(attributeName)); return lst.remove(listIndex); } else { Object theValue = request.getAttribute(attributeName); @@ -349,14 +350,14 @@ if (fma != null) { Object theObj = session.getAttribute(attributeName); if (isListReference) { - List lst = (List) theObj; - return fma.remove((Map) lst.get(listIndex)); + List<?> lst = UtilGenerics.checkList(theObj); + return fma.remove(UtilGenerics.checkMap(lst.get(listIndex), String.class, Object.class)); } else { - return fma.remove((Map) theObj); + return fma.remove(UtilGenerics.checkMap(theObj, String.class, Object.class)); } } else { if (isListReference) { - List lst = (List) session.getAttribute(attributeName); + List<?> lst = UtilGenerics.checkList(session.getAttribute(attributeName)); return lst.remove(listIndex); } else { Object theValue = session.getAttribute(attributeName); Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/MapStack.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/MapStack.java?rev=585752&r1=585751&r2=585752&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/MapStack.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/MapStack.java Wed Oct 17 16:19:44 2007 @@ -33,38 +33,43 @@ import javolution.util.FastSet; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilGenerics; /** * Map Stack * */ -public class MapStack implements Map, Reusable, LocalizedMap { +public class MapStack<K> implements Map<K, Object>, Reusable, LocalizedMap<Object> { public static final String module = MapStack.class.getName(); - protected static final ObjectFactory mapStackFactory = new ObjectFactory() { - protected Object create() { + protected static final ObjectFactory<MapStack<?>> mapStackFactory = new ObjectFactory<MapStack<?>>() { + protected MapStack<?> create() { return new MapStack(); } }; - - public static MapStack create() { - MapStack newValue = (MapStack) mapStackFactory.object(); + + protected static final <K> MapStack<K> getMapStack() { + return (MapStack<K>) UtilGenerics.<K, Object>checkMap(mapStackFactory.object()); + } + + public static <K> MapStack<K> create() { + MapStack<K> newValue = MapStack.getMapStack(); // initialize with a single entry newValue.push(); return newValue; } - public static MapStack create(Map baseMap) { - MapStack newValue = (MapStack) mapStackFactory.object(); + public static <K> MapStack<K> create(Map<K, Object> baseMap) { + MapStack<K> newValue = MapStack.getMapStack(); newValue.stackList.add(0, baseMap); return newValue; } /** Does a shallow copy of the internal stack of the passed MapStack; enables simultaneous stacks that share common parent Maps */ - public static MapStack create(MapStack source) { - MapStack newValue = (MapStack) mapStackFactory.object(); + public static <K> MapStack<K> create(MapStack<K> source) { + MapStack<K> newValue = MapStack.getMapStack(); newValue.stackList.addAll(source.stackList); return newValue; } @@ -73,7 +78,7 @@ super(); } - protected List stackList = FastList.newInstance(); + protected List<Map<K, Object>> stackList = FastList.newInstance(); public void reset() { stackList = FastList.newInstance(); @@ -81,11 +86,12 @@ /** Puts a new Map on the top of the stack */ public void push() { - this.stackList.add(0, FastMap.newInstance()); + Map<K, Object> newMap = FastMap.newInstance(); + this.stackList.add(0,newMap); } /** Puts an existing Map on the top of the stack (top meaning will override lower layers on the stack) */ - public void push(Map existingMap) { + public void push(Map<K, Object> existingMap) { if (existingMap == null) { throw new IllegalArgumentException("Error: cannot push null existing Map onto a MapStack"); } @@ -93,7 +99,7 @@ } /** Puts an existing Map on the BOTTOM of the stack (bottom meaning will be overriden by lower layers on the stack, ie everything else already there) */ - public void addToBottom(Map existingMap) { + public void addToBottom(Map<K, Object> existingMap) { if (existingMap == null) { throw new IllegalArgumentException("Error: cannot add null existing Map to bottom of a MapStack"); } @@ -101,10 +107,10 @@ } /** Remove and returns the Map from the top of the stack; if there is only one Map on the stack it returns null and does not remove it */ - public Map pop() { + public Map<K, Object> pop() { // always leave at least one Map in the List, ie never pop off the last Map if (this.stackList.size() > 1) { - return (Map) stackList.remove(0); + return stackList.remove(0); } else { return null; } @@ -116,8 +122,8 @@ * situation where a parent and child context are operating simultaneously * using two different MapStack objects, but sharing the Maps in common */ - public MapStack standAloneStack() { - MapStack standAlone = MapStack.create(this); + public MapStack<K> standAloneStack() { + MapStack<K> standAlone = MapStack.create(this); return standAlone; } @@ -127,8 +133,8 @@ * situation where a parent and child context are operating simultaneously * using two different MapStack objects, but sharing the Maps in common */ - public MapStack standAloneChildStack() { - MapStack standAloneChild = MapStack.create(this); + public MapStack<K> standAloneChildStack() { + MapStack<K> standAloneChild = MapStack.create(this); standAloneChild.push(); return standAloneChild; } @@ -139,7 +145,7 @@ public int size() { // a little bit tricky; to represent the apparent size we need to aggregate all keys and get a count of unique keys // this is a bit of a slow way, but gets the best number possible - Set keys = this.keySet(); + Set<K> keys = this.keySet(); return keys.size(); } @@ -148,9 +154,7 @@ */ public boolean isEmpty() { // walk the stackList and if any is not empty, return false; otherwise return true - Iterator stackIter = this.stackList.iterator(); - while (stackIter.hasNext()) { - Map curMap = (Map) stackIter.next(); + for (Map<K, Object> curMap: this.stackList) { if (!curMap.isEmpty()) { return false; } @@ -163,9 +167,7 @@ */ public boolean containsKey(Object key) { // walk the stackList and for the first place it is found return true; otherwise refurn false - Iterator stackIter = this.stackList.iterator(); - while (stackIter.hasNext()) { - Map curMap = (Map) stackIter.next(); + for (Map<K, Object> curMap: this.stackList) { if (curMap.containsKey(key)) { return true; } @@ -178,13 +180,9 @@ */ public boolean containsValue(Object value) { // walk the stackList and the entries for each Map and if nothing is in for the current key, consider it an option, otherwise ignore - Set resultKeySet = FastSet.newInstance(); - Iterator stackIter = this.stackList.iterator(); - while (stackIter.hasNext()) { - Map curMap = (Map) stackIter.next(); - Iterator curEntrySetIter = curMap.entrySet().iterator(); - while (curEntrySetIter.hasNext()) { - Map.Entry curEntry = (Map.Entry) curEntrySetIter.next(); + Set<K> resultKeySet = FastSet.newInstance(); + for (Map<K, Object> curMap: this.stackList) { + for (Map.Entry<K, Object> curEntry: curMap.entrySet()) { if (!resultKeySet.contains(curEntry.getKey())) { resultKeySet.add(curEntry.getKey()); if (value == null) { @@ -211,9 +209,7 @@ } // walk the stackList and for the first place it is found return true; otherwise refurn false - Iterator stackIter = this.stackList.iterator(); - while (stackIter.hasNext()) { - Map curMap = (Map) stackIter.next(); + for (Map<K, Object> curMap: this.stackList) { // only return if the curMap contains the key, rather than checking for null; this allows a null at a lower level to override a value at a higher level if (curMap.containsKey(key)) { return curMap.get(key); @@ -231,9 +227,7 @@ } // walk the stackList and for the first place it is found return true; otherwise refurn false - Iterator stackIter = this.stackList.iterator(); - while (stackIter.hasNext()) { - Map curMap = (Map) stackIter.next(); + for (Map<K, Object> curMap: this.stackList) { // only return if the curMap contains the key, rather than checking for null; this allows a null at a lower level to override a value at a higher level if (curMap.containsKey(name)) { if (curMap instanceof LocalizedMap) { @@ -250,7 +244,7 @@ /* (non-Javadoc) * @see java.util.Map#put(java.lang.Object, java.lang.Object) */ - public Object put(Object key, Object value) { + public Object put(K key, Object value) { if ("context".equals(key)) { if (value == null || this != value) { Debug.logWarning("WARNING: Putting a value in a MapStack with key [context] that is not this MapStack, will be hidden by the current MapStack self-reference: " + value, module); @@ -258,7 +252,7 @@ } // all write operations are local: only put in the Map on the top of the stack - Map currentMap = (Map) this.stackList.get(0); + Map<K, Object> currentMap = this.stackList.get(0); return currentMap.put(key, value); } @@ -267,16 +261,16 @@ */ public Object remove(Object key) { // all write operations are local: only remove from the Map on the top of the stack - Map currentMap = (Map) this.stackList.get(0); + Map<K, Object> currentMap = this.stackList.get(0); return currentMap.remove(key); } /* (non-Javadoc) * @see java.util.Map#putAll(java.util.Map) */ - public void putAll(Map arg0) { + public void putAll(Map<? extends K, ? extends Object> arg0) { // all write operations are local: only put in the Map on the top of the stack - Map currentMap = (Map) this.stackList.get(0); + Map<K, Object> currentMap = this.stackList.get(0); currentMap.putAll(arg0); } @@ -292,12 +286,10 @@ /* (non-Javadoc) * @see java.util.Map#keySet() */ - public Set keySet() { + public Set<K> keySet() { // walk the stackList and aggregate all keys - Set resultSet = FastSet.newInstance(); - Iterator stackIter = this.stackList.iterator(); - while (stackIter.hasNext()) { - Map curMap = (Map) stackIter.next(); + Set<K> resultSet = FastSet.newInstance(); + for (Map<K, Object> curMap: this.stackList) { resultSet.addAll(curMap.keySet()); } return Collections.unmodifiableSet(resultSet); @@ -306,16 +298,12 @@ /* (non-Javadoc) * @see java.util.Map#values() */ - public Collection values() { + public Collection<Object> values() { // walk the stackList and the entries for each Map and if nothing is in for the current key, put it in - Set resultKeySet = FastSet.newInstance(); - List resultValues = FastList.newInstance(); - Iterator stackIter = this.stackList.iterator(); - while (stackIter.hasNext()) { - Map curMap = (Map) stackIter.next(); - Iterator curEntrySetIter = curMap.entrySet().iterator(); - while (curEntrySetIter.hasNext()) { - Map.Entry curEntry = (Map.Entry) curEntrySetIter.next(); + Set<K> resultKeySet = FastSet.newInstance(); + List<Object> resultValues = FastList.newInstance(); + for (Map<K, Object> curMap: this.stackList) { + for (Map.Entry<K, Object> curEntry: curMap.entrySet()) { if (!resultKeySet.contains(curEntry.getKey())) { resultKeySet.add(curEntry.getKey()); resultValues.add(curEntry.getValue()); @@ -328,16 +316,12 @@ /* (non-Javadoc) * @see java.util.Map#entrySet() */ - public Set entrySet() { + public Set<Map.Entry<K, Object>> entrySet() { // walk the stackList and the entries for each Map and if nothing is in for the current key, put it in - Set resultKeySet = FastSet.newInstance(); - Set resultEntrySet = FastSet.newInstance(); - Iterator stackIter = this.stackList.iterator(); - while (stackIter.hasNext()) { - Map curMap = (Map) stackIter.next(); - Iterator curEntrySetIter = curMap.entrySet().iterator(); - while (curEntrySetIter.hasNext()) { - Map.Entry curEntry = (Map.Entry) curEntrySetIter.next(); + Set<K> resultKeySet = FastSet.newInstance(); + Set<Map.Entry<K, Object>> resultEntrySet = FastSet.newInstance(); + for (Map<K, Object> curMap: this.stackList) { + for (Map.Entry<K, Object> curEntry: curMap.entrySet()) { if (!resultKeySet.contains(curEntry.getKey())) { resultKeySet.add(curEntry.getKey()); resultEntrySet.add(curEntry); @@ -350,13 +334,9 @@ public String toString() { StringBuilder fullMapString = new StringBuilder(); int curLevel = 0; - Iterator stackIter = this.stackList.iterator(); - while (stackIter.hasNext()) { - Map curMap = (Map) stackIter.next(); + for (Map<K, Object> curMap: this.stackList) { fullMapString.append("============================== Start stack level " + curLevel + "\n"); - Iterator curEntrySetIter = curMap.entrySet().iterator(); - while (curEntrySetIter.hasNext()) { - Map.Entry curEntry = (Map.Entry) curEntrySetIter.next(); + for (Map.Entry<K, Object> curEntry: curMap.entrySet()) { fullMapString.append("==>["); fullMapString.append(curEntry.getKey()); Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java?rev=585752&r1=585751&r2=585752&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/collections/ResourceBundleMapWrapper.java Wed Oct 17 16:19:44 2007 @@ -34,9 +34,9 @@ * Generic ResourceBundle Map Wrapper, given ResourceBundle allows it to be used as a Map * */ -public class ResourceBundleMapWrapper implements Map, Serializable { +public class ResourceBundleMapWrapper implements Map<String, Object>, Serializable { - protected MapStack rbmwStack; + protected MapStack<String> rbmwStack; protected ResourceBundle initialResourceBundle; protected ResourceBundleMapWrapper() { @@ -100,7 +100,7 @@ public boolean containsValue(Object arg0) { return this.rbmwStack.containsValue(arg0); } - public Set entrySet() { + public Set<Map.Entry<String, Object>> entrySet() { return this.rbmwStack.entrySet(); } public Object get(Object arg0) { @@ -113,13 +113,13 @@ public boolean isEmpty() { return this.rbmwStack.isEmpty(); } - public Set keySet() { + public Set<String> keySet() { return this.keySet(); } - public Object put(Object key, Object value) { + public Object put(String key, Object value) { return this.rbmwStack.put(key, value); } - public void putAll(Map arg0) { + public void putAll(Map<? extends String, ? extends Object> arg0) { this.rbmwStack.putAll(arg0); } public Object remove(Object arg0) { @@ -128,25 +128,25 @@ public int size() { return this.rbmwStack.size(); } - public Collection values() { + public Collection<Object> values() { return this.rbmwStack.values(); } - public static class InternalRbmWrapper implements Map, Serializable { + public static class InternalRbmWrapper implements Map<String, Object>, Serializable { protected ResourceBundle resourceBundle; - protected Map topLevelMap; + protected Map<String, Object> topLevelMap; public InternalRbmWrapper(ResourceBundle resourceBundle) { if (resourceBundle == null) { throw new IllegalArgumentException("Cannot create InternalRbmWrapper with a null ResourceBundle."); } this.resourceBundle = resourceBundle; - topLevelMap = new HashMap(); + topLevelMap = new HashMap<String, Object>(); // NOTE: this does NOT return all keys, ie keys from parent ResourceBundles, so we keep the resourceBundle object to look at when the main Map doesn't have a certain value if (resourceBundle != null) { - Enumeration keyNum = resourceBundle.getKeys(); + Enumeration<String> keyNum = resourceBundle.getKeys(); while (keyNum.hasMoreElements()) { - String key = (String) keyNum.nextElement(); + String key = keyNum.nextElement(); //resourceBundleMap.put(key, bundle.getObject(key)); Object value = resourceBundle.getObject(key); topLevelMap.put(key, value); @@ -229,7 +229,7 @@ /* (non-Javadoc) * @see java.util.Map#put(java.lang.Object, java.lang.Object) */ - public Object put(Object arg0, Object arg1) { + public Object put(String arg0, Object arg1) { throw new RuntimeException("Not implemented/allowed for ResourceBundleMapWrapper"); } @@ -257,21 +257,21 @@ /* (non-Javadoc) * @see java.util.Map#keySet() */ - public Set keySet() { + public Set<String> keySet() { return this.topLevelMap.keySet(); } /* (non-Javadoc) * @see java.util.Map#values() */ - public Collection values() { + public Collection<Object> values() { return this.topLevelMap.values(); } /* (non-Javadoc) * @see java.util.Map#entrySet() */ - public Set entrySet() { + public Set<Map.Entry<String, Object>> entrySet() { return this.topLevelMap.entrySet(); } |
Free forum by Nabble | Edit this page |