svn commit: r713233 - /xml/xindice/trunk/java/src/org/apache/xindice/core/meta/MetaData.java

[email protected]
Newsgroups gmane.text.xml.xindice.devel
Message-ID <[email protected]>
Author: vgritsenko
Date: Tue Nov 11 17:01:36 2008
New Revision: 713233

URL: http://svn.apache.org/viewvc?rev=713233&view=rev
Log:
cleanup

Modified:
    xml/xindice/trunk/java/src/org/apache/xindice/core/meta/MetaData.java

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/meta/MetaData.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/meta/MetaData.java?rev=713233&r1=713232&r2=713233&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/meta/MetaData.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/meta/MetaData.java Tue Nov 11 17:01:36 2008
@@ -53,21 +53,20 @@
  * </pre>
  *
  * @author ku
- * @author Dave Viner <[email protected]>
+ * @author Dave Viner &lt;[email protected]&gt;
  * @version $Revision$, $Date$
  */
 public class MetaData implements XMLSerializable {
 
-    private static Log log = LogFactory.getLog(MetaData.class);
+    private static final Log log = LogFactory.getLog(MetaData.class);
 
-    public final static short UNKNOWN = 0;
-    public final static short COLLECTION = 1;
-    public final static short DOCUMENT = 2;
-    public final static short LINK = 3;
-
-    public final static String NS_URI = "http://apache.org/xindice/metadata";
-    //public final static String NS_PREFIX    = "md";
-    public final static boolean USE_NS = true;
+    public static final short UNKNOWN    = 0;
+    public static final short COLLECTION = 1;
+    public static final short DOCUMENT   = 2;
+    public static final short LINK       = 3;
+
+    public static final String NS_URI = "http://apache.org/xindice/metadata";
+    public static final boolean USE_NS = true;
 
     private static final String E_META = "meta";
     private static final String E_SYSTEM = "system";
@@ -82,8 +81,7 @@
     private static final String A_TYPE = "type";
     private static final String A_HREF = "href";
 
-    private static final Enumeration EMPTY =
-            (new Vector()).elements();
+    private static final Enumeration EMPTY = new Vector().elements();
 
     private transient boolean dirty;
     private transient long created;
@@ -183,7 +181,7 @@
      * @return Enumeration of attributes
      */
     public Enumeration getAttributeKeys() {
-        if (null == attrs) {
+        if (attrs == null) {
             return EMPTY;
         }
 
@@ -196,7 +194,7 @@
      * @return String the value of attribute, or null if not found
      */
     public Object getAttribute(final Object name) {
-        if (null == attrs) {
+        if (attrs == null) {
             return null;
         }
 
@@ -205,7 +203,7 @@
 
     public Boolean getAttributeAsBoolean(final Object name) {
         Object o = getAttribute(name);
-        if (null == o) {
+        if (o == null) {
             return null;
         }
 
@@ -215,7 +213,7 @@
 
         if (o instanceof Number) {
             Number n = (Number) o;
-            return new Boolean(n.intValue() != 0);
+            return n.intValue() != 0 ? Boolean.TRUE : Boolean.FALSE;
         }
 
         return Boolean.valueOf(o.toString());
@@ -223,7 +221,7 @@
 
     public Integer getAttributeAsInteger(final Object name) {
         Object o = getAttribute(name);
-        if (null == o) {
+        if (o == null) {
             return null;
         }
 
@@ -237,8 +235,7 @@
         }
 
         try {
-            int v = Integer.parseInt(o.toString());
-            return new Integer(v);
+            return new Integer(o.toString());
         } catch (Exception e) {
             return null;
         }
@@ -246,7 +243,7 @@
 
     public Long getAttributeAsLong(final Object name) {
         Object o = getAttribute(name);
-        if (null == o) {
+        if (o == null) {
             return null;
         }
 
@@ -260,8 +257,7 @@
         }
 
         try {
-            long v = Long.parseLong(o.toString());
-            return new Long(v);
+            return new Long(o.toString());
         } catch (Exception e) {
             return null;
         }
@@ -269,7 +265,7 @@
 
     public Short getAttributeAsShort(final Object name) {
         Object o = getAttribute(name);
-        if (null == o) {
+        if (o == null) {
             return null;
         }
 
@@ -283,8 +279,7 @@
         }
 
         try {
-            short v = Short.parseShort(o.toString());
-            return new Short(v);
+            return new Short(o.toString());
         } catch (Exception e) {
             return null;
         }
@@ -297,10 +292,11 @@
      * @return Object the old value, if any
      */
     public Object setAttribute(final Object name, final Object value) {
-        if (null == attrs) {
+        if (attrs == null) {
             attrs = new Hashtable();
             dirty = true;
         }
+
         Object prev = attrs.put(name, value);
         if (prev == null || !prev.equals(value)) {
             dirty = true;
@@ -315,12 +311,12 @@
      * @return Object the removed value
      */
     public Object removeAttribute(final Object name) {
-        if (null == attrs) {
+        if (attrs == null) {
             return null;
         }
 
         Object prev = attrs.remove(name);
-        if (null != prev) {
+        if (prev != null) {
             dirty = true;
         }
 
@@ -366,7 +362,7 @@
         for (Enumeration e = meta.getAttributeKeys(); e.hasMoreElements();) {
             Object key = e.nextElement();
             Object value = meta.getAttribute(key);
-            if (null == this.attrs) {
+            if (this.attrs == null) {
                 this.attrs = new Hashtable();
             }
             this.attrs.put(key, value);
@@ -374,11 +370,12 @@
 
         this.custom = null;
         Document doc = meta.getCustomDocument();
-        if (null != doc) {
+        if (doc != null) {
             this.custom = new DocumentImpl();
             this.custom.appendChild(
                     this.custom.importNode(doc.getDocumentElement(), true));
         }
+
         this.dirty = false;
     }
 
@@ -399,7 +396,6 @@
      * @param doc the xml document to be populated.
      */
     public final Element streamToXML(Document doc) throws DOMException {
-
         return streamToXML(doc, true);
     }
 
@@ -412,7 +408,7 @@
     public final Element streamToXML(Document doc, boolean includeTime)
             throws DOMException {
 
-        Element root = null;
+        Element root;
         if (!USE_NS) {
             root = doc.createElement(E_META);
         } else {
@@ -420,7 +416,7 @@
             root.setAttribute("xmlns", NS_URI);
         }
 
-        Element systemElement = null;
+        Element systemElement;
         if (!USE_NS) {
             systemElement = doc.createElement(E_SYSTEM);
         } else {
@@ -429,7 +425,7 @@
         systemElement.setAttribute(A_TYPE, getTypeString(type));
         root.appendChild(systemElement);
         if (includeTime) {
-            Element timeElement = null;
+            Element timeElement;
             if (!USE_NS) {
                 timeElement = doc.createElement(E_ATTR);
             } else {
@@ -448,12 +444,12 @@
             timeElement.setAttribute(A_VALUE, Long.toString(modified));
             systemElement.appendChild(timeElement);
         }
-        if (null != link) {
+        if (link != null) {
             systemElement.setAttribute(A_HREF, link);
         }
 
-        if (null != attrs && attrs.size() > 0) {
-            Element attrsElement = null;
+        if (attrs != null && attrs.size() > 0) {
+            Element attrsElement;
             if (!USE_NS) {
                 attrsElement = doc.createElement(E_ATTRS);
             } else {
@@ -464,12 +460,11 @@
             for (Enumeration e = attrs.keys(); e.hasMoreElements();) {
                 Object key = e.nextElement();
                 Object value = attrs.get(key);
-
-                if (null == key) {
+                if (key == null) {
                     continue;
                 }
 
-                Element attrElement = null;
+                Element attrElement;
                 if (!USE_NS) {
                     attrElement = doc.createElement(E_ATTR);
                 } else {
@@ -478,14 +473,14 @@
                 attrsElement.appendChild(attrElement);
 
                 attrElement.setAttribute(A_NAME, key.toString());
-                if (null != value) {
+                if (value != null) {
                     attrElement.setAttribute(A_VALUE, value.toString());
                 }
             }
         }
 
-        if (null != custom) {
-            Element customElement = null;
+        if (custom != null) {
+            Element customElement;
             if (!USE_NS) {
                 customElement = doc.createElement(E_CUSTOM);
             } else {
@@ -533,7 +528,7 @@
 
             if (E_SYSTEM.equals(elementName)) {
                 String attrStr = element.getAttribute(A_TYPE);
-                if (null != attrStr) {
+                if (attrStr != null) {
                     this.type = parseTypeString(attrStr);
                 }
 
@@ -556,7 +551,7 @@
                         if (E_ATTR.equals(childName)) {
                             String nameStr = child.getAttribute(A_NAME);
                             String valueStr = child.getAttribute(A_VALUE);
-                            if (null != nameStr && null != valueStr) {
+                            if (nameStr != null && valueStr != null) {
                                 if (E_CREATED.equals(nameStr)) {
                                     this.created = Long.parseLong(valueStr);
                                 } else if (E_MODIFIED.equals(nameStr)) {
@@ -576,11 +571,11 @@
                     Element e = (Element) attrList.item(j);
 
                     String attrName = e.getAttribute(A_NAME);
-                    if (null == attrName) {
+                    if (attrName == null) {
                         continue;
                     }
 
-                    if (null == this.attrs) {
+                    if (this.attrs == null) {
                         this.attrs = new Hashtable();
                     }
                     this.attrs.put(attrName, e.getAttribute(A_VALUE));
@@ -744,4 +739,3 @@
         return buffer.toString();
     }
 }
-
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.