From: Julio G. <ju...@us...> - 2004-08-12 16:40:14
|
Update of /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/sfcore/common In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17903/common Modified Files: Context.java ContextImpl.java OrderedHashtable.java Log Message: New methods to get access to attributes/values - sfAttributes() - sfValues() -sfContainsAttibute(attribute) -sfContainsValue(value) Available in Context/Prim/ComponentDescription Index: Context.java =================================================================== RCS file: /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/sfcore/common/Context.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Context.java 6 Aug 2004 00:55:03 -0000 1.3 --- Context.java 12 Aug 2004 16:40:04 -0000 1.4 *************** *** 22,25 **** --- 22,26 ---- import java.util.Enumeration; + import java.util.Iterator; *************** *** 34,38 **** /** * Returns true if the context contains value. ! * * @param value object to check * --- 35,39 ---- /** * Returns true if the context contains value. ! * Deprecated: replaced by sfContainsValue() * @param value object to check * *************** *** 43,47 **** /** * Returns true if the context contains the key. ! * * @param key to check * --- 44,48 ---- /** * Returns true if the context contains the key. ! * Deprecated: replaced by sfContainsAttribute() * @param key to check * *************** *** 52,56 **** /** * Returns the values of the context. ! * * @return enumeration over the values of the context * --- 53,57 ---- /** * Returns the values of the context. ! * Deprecated: replaced by sfValues(); * @return enumeration over the values of the context * *************** *** 59,62 **** --- 60,64 ---- public Enumeration elements(); + /** * Returns object stored under given key, null if not found. *************** *** 77,85 **** /** * Returns an enumeration over the keys of the context. ! * * @return enumeration */ public Enumeration keys(); /** * Adds an object value under given key to context. --- 79,88 ---- /** * Returns an enumeration over the keys of the context. ! * Deprecated: replaced by sfAttributes(); * @return enumeration */ public Enumeration keys(); + /** * Adds an object value under given key to context. *************** *** 121,125 **** /** * Returns the first key which has a particular value in the table. ! * * @param value value to find in table * --- 124,128 ---- /** * Returns the first key which has a particular value in the table. ! * Deprecated: sfAttributeFor should be used instead. * @param value value to find in table * *************** *** 142,147 **** public Object clone(); - // Special methods that throw exception when something does not work /** * Add an attribute to context. Values should be --- 145,193 ---- public Object clone(); + /** + * Returns the first attribute which has a particular value in the table. + * + * @param value value to find in table + * + * @return attibute object for value or null if none + */ + public Object sfAttributeFor(Object value); + + /** + * Returns true if the context contains value. + * Replaces contains() + * + * @param value object to check + * + * @return true if context contains value, false otherwise + */ + public boolean sfContainsValue(Object value); + + + /** + * Returns true if the context contains attribute. + * Replaces containsKey() + * + * @param attribute to check + * + * @return true if context contains key, false otherwise + */ + public boolean sfContainsAttribute(Object attribute); + + + /** + * Returns an iterator over the attribute names of the context. + * + * @return iterator + */ + public Iterator sfAttributes(); + + /** + * Returns an iterator over the values of the context. + * + * @return iterator + */ + public Iterator sfValues(); /** * Add an attribute to context. Values should be Index: ContextImpl.java =================================================================== RCS file: /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/sfcore/common/ContextImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ContextImpl.java 6 Aug 2004 00:55:03 -0000 1.3 --- ContextImpl.java 12 Aug 2004 16:40:05 -0000 1.4 *************** *** 23,26 **** --- 23,27 ---- import java.io.Serializable; import java.util.Enumeration; + import java.util.Iterator; import org.smartfrog.sfcore.common.SmartFrogContextException; *************** *** 57,61 **** /** * Returns the first key for which the value is the given one. ! * * @param value value to look up * --- 58,62 ---- /** * Returns the first key for which the value is the given one. ! * Deprecated: replaced by sfAttributeFor(value); * @param value value to look up * *************** *** 63,66 **** --- 64,78 ---- */ public Object keyFor(Object value) { + return sfAttributeFor(value); + } + + /** + * Returns the first attribute which has a particular value in the table. + * + * @param value value to find in table + * + * @return attibute object for value or null if none + */ + public Object sfAttributeFor(Object value){ if (!contains(value)) { return null; *************** *** 76,79 **** --- 88,135 ---- } + /** + * Returns true if the context contains value. + * Replaces contains() + * @param value object to check + * + * @return true if context contains value, false otherwise + */ + public boolean sfContainsValue(Object value){ + return containsKey(value); + } + + + /** + * Returns true if the context contains attribute. + * Replaces containsKey() + * @param attribute to check + * + * @return true if context contains key, false otherwise + */ + public boolean sfContainsAttribute(Object attribute){ + return containsKey(attribute); + } + + + /** + * Returns an ordered iterator over the attribute names in the context. + * + * @return iterator + */ + public Iterator sfAttributes(){ + return orderedAttributes(); + + } + + /** + * Returns an ordered iterator over the values in the context. + * + * @return iterator + */ + public Iterator sfValues(){ + return orderedValues(); + } + + /** Index: OrderedHashtable.java =================================================================== RCS file: /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/sfcore/common/OrderedHashtable.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** OrderedHashtable.java 7 May 2004 11:20:41 -0000 1.3 --- OrderedHashtable.java 12 Aug 2004 16:40:05 -0000 1.4 *************** *** 28,31 **** --- 28,32 ---- import java.util.Enumeration; + import java.util.Iterator; import java.util.Hashtable; import java.util.Vector; *************** *** 119,152 **** if (value instanceof Copying) { value = ((Copying) value).copy(); ! } else if (value instanceof SFNull) { ! // do nothing... ! } else if (value instanceof Number) { ! if (value instanceof Integer) { ! value = new Integer(((Integer)value).intValue()); ! } else if (value instanceof Double) { ! value = new Double(((Double)value).doubleValue()); ! } else if (value instanceof Float) { ! value = new Float(((Float)value).floatValue()); ! } else if (value instanceof Long) { ! value = new Long(((Long)value).longValue()); ! } ! } else if (value instanceof String) { ! value = new String((String)value); ! } else if (value instanceof Boolean) { ! value = new Boolean(((Boolean) value).booleanValue()); ! } else if (value instanceof Serializable) { ! // copy by serialization and de-serialization ! try { ! ByteArrayOutputStream bos = new ByteArrayOutputStream(100); ! ObjectOutputStream oos = new ObjectOutputStream(bos); ! oos.writeObject(value); ! ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); ! ObjectInputStream ois = new ObjectInputStream(bis); ! value = ois.readObject(); ! } catch (Exception t) { ! throw new RuntimeException(MessageUtil.formatMessage(COPY_SERIALIZE_FAILED,value), t); ! } ! } else { ! throw new IllegalArgumentException(MessageUtil.formatMessage(COPY_FAILED, value)); } r.primPut(key, value); --- 120,153 ---- if (value instanceof Copying) { value = ((Copying) value).copy(); ! } else if (value instanceof SFNull) { ! // do nothing... ! } else if (value instanceof Number) { ! if (value instanceof Integer) { ! value = new Integer(((Integer)value).intValue()); ! } else if (value instanceof Double) { ! value = new Double(((Double)value).doubleValue()); ! } else if (value instanceof Float) { ! value = new Float(((Float)value).floatValue()); ! } else if (value instanceof Long) { ! value = new Long(((Long)value).longValue()); ! } ! } else if (value instanceof String) { ! value = new String((String)value); ! } else if (value instanceof Boolean) { ! value = new Boolean(((Boolean) value).booleanValue()); ! } else if (value instanceof Serializable) { ! // copy by serialization and de-serialization ! try { ! ByteArrayOutputStream bos = new ByteArrayOutputStream(100); ! ObjectOutputStream oos = new ObjectOutputStream(bos); ! oos.writeObject(value); ! ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); ! ObjectInputStream ois = new ObjectInputStream(bis); ! value = ois.readObject(); ! } catch (Exception t) { ! throw new RuntimeException(MessageUtil.formatMessage(COPY_SERIALIZE_FAILED,value), t); ! } ! } else { ! throw new IllegalArgumentException(MessageUtil.formatMessage(COPY_FAILED, value)); } r.primPut(key, value); *************** *** 247,251 **** /** * Returns the values of the hashtable in order. ! * * @return ordered enumeration over values */ --- 248,252 ---- /** * Returns the values of the hashtable in order. ! * Replaced by values() using Iterator. * @return ordered enumeration over values */ *************** *** 255,263 **** for (Enumeration e = keys(); e.hasMoreElements();) r.addElement(get(e.nextElement())); - return r.elements(); } /** * Does a shallow copy of the hashtable and the ordered keys. * --- 256,285 ---- for (Enumeration e = keys(); e.hasMoreElements();) r.addElement(get(e.nextElement())); return r.elements(); } /** + * Returns the attributes of the hashtable in order. + * + * @return ordered iterator over attributes + */ + public Iterator orderedAttributes() { + return orderedKeys.iterator(); + } + + /** + * Returns the values of the hashtable in order. + * + * @return ordered iterator over values + */ + public Iterator orderedValues() { + Vector r = new Vector(orderedKeys.size()); + for (Enumeration e = keys(); e.hasMoreElements();) + r.addElement(get(e.nextElement())); + return r.iterator(); + } + + + /** * Does a shallow copy of the hashtable and the ordered keys. * |