Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/container/ContainerPointerFactory.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/container/ContainerPointerFactory.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/container/ContainerPointerFactory.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/container/ContainerPointerFactory.java Mon Feb 19 15:24:43 2007 @@ -42,10 +42,7 @@ Object bean, Locale locale) { - if (bean instanceof Container) { - return new ContainerPointer((Container) bean, locale); - } - return null; + return bean instanceof Container ? new ContainerPointer((Container) bean, locale) : null; } public NodePointer createNodePointer( @@ -53,9 +50,6 @@ QName name, Object bean) { - if (bean instanceof Container) { - return new ContainerPointer(parent, (Container) bean); - } - return null; + return bean instanceof Container ? new ContainerPointer(parent, (Container) bean) : null; } }
Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java Mon Feb 19 15:24:43 2007 @@ -100,13 +100,7 @@ } private static boolean equalStrings(String s1, String s2) { - if (s1 == null && s2 != null) { - return false; - } - if (s1 != null && !s1.equals(s2)) { - return false; - } - return true; + return s1 == s2 || s1 != null && s1.equals(s2); } private Attr getAttribute(Element element, QName name) { @@ -135,9 +129,7 @@ } return null; } - else { - return element.getAttributeNode(name.getName()); - } + return element.getAttributeNode(name.getName()); } public NodePointer getNodePointer() { Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributePointer.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributePointer.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributePointer.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributePointer.java Mon Feb 19 15:24:43 2007 @@ -46,23 +46,17 @@ public String getNamespaceURI() { String prefix = DOMNodePointer.getPrefix(attr); - if (prefix == null) { - return null; - } - return parent.getNamespaceURI(prefix); + return prefix == null ? null : parent.getNamespaceURI(prefix); } public Object getValue() { String value = attr.getValue(); - if (value == null) { - return null; - } - if (value.equals("") && !attr.getSpecified()) { + if (value == null || (value.equals("") && !attr.getSpecified())) { return null; } return value; } - + public Object getBaseValue() { return attr; } @@ -90,8 +84,7 @@ public boolean testNode(NodeTest nodeTest) { return nodeTest == null || ((nodeTest instanceof NodeTypeTest) - && ((NodeTypeTest) nodeTest).getNodeType() - == Compiler.NODE_TYPE_NODE); + && ((NodeTypeTest) nodeTest).getNodeType() == Compiler.NODE_TYPE_NODE); } /** @@ -126,16 +119,8 @@ } public boolean equals(Object object) { - if (object == this) { - return true; - } - - if (!(object instanceof DOMAttributePointer)) { - return false; - } - - DOMAttributePointer other = (DOMAttributePointer) object; - return attr == other.attr; + return object == this || object instanceof DOMAttributePointer + && attr == ((DOMAttributePointer) object).attr; } public int compareChildNodePointers( Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodeIterator.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodeIterator.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodeIterator.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodeIterator.java Mon Feb 19 15:24:43 2007 @@ -54,10 +54,7 @@ if (position == 0) { setPosition(1); } - if (child == null) { - return null; - } - return new DOMNodePointer(parent, child); + return child == null ? null : new DOMNodePointer(parent, child); } public int getPosition() { Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java Mon Feb 19 15:24:43 2007 @@ -88,7 +88,7 @@ if (test == null) { return true; } - else if (test instanceof NodeNameTest) { + if (test instanceof NodeNameTest) { if (node.getNodeType() != Node.ELEMENT_NODE) { return false; } @@ -108,8 +108,9 @@ String nodeNS = DOMNodePointer.getNamespaceURI(node); return equalStrings(namespaceURI, nodeNS); } + return false; } - else if (test instanceof NodeTypeTest) { + if (test instanceof NodeTypeTest) { int nodeType = node.getNodeType(); switch (((NodeTypeTest) test).getNodeType()) { case Compiler.NODE_TYPE_NODE : @@ -125,7 +126,7 @@ } return false; } - else if (test instanceof ProcessingInstructionTest) { + if (test instanceof ProcessingInstructionTest) { if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { String testPI = ((ProcessingInstructionTest) test).getTarget(); String nodePI = ((ProcessingInstruction) node).getTarget(); @@ -136,19 +137,12 @@ } private static boolean equalStrings(String s1, String s2) { - if (s1 == null) { - return s2 == null || s2.trim().length() == 0; - } - - if (s2 == null) { - return s1 == null || s1.trim().length() == 0; - } - - if (s1 != null && !s1.trim().equals(s2.trim())) { - return false; + if (s1 == s2) { + return true; } - - return true; + s1 = s1 == null ? "" : s1.trim(); + s2 = s2 == null ? "" : s2.trim(); + return s1.equals(s2); } public QName getName() { @@ -295,10 +289,8 @@ */ public boolean isLanguage(String lang) { String current = getLanguage(); - if (current == null) { - return super.isLanguage(lang); - } - return current.toUpperCase().startsWith(lang.toUpperCase()); + return current == null ? super.isLanguage(lang) + : current.toUpperCase().startsWith(lang.toUpperCase()); } protected String getLanguage() { @@ -582,16 +574,7 @@ } public boolean equals(Object object) { - if (object == this) { - return true; - } - - if (!(object instanceof DOMNodePointer)) { - return false; - } - - DOMNodePointer other = (DOMNodePointer) object; - return node == other.node; + return object == this || object instanceof DOMNodePointer && node == ((DOMNodePointer) object).node; } public static String getPrefix(Node node) { @@ -602,11 +585,7 @@ String name = node.getNodeName(); int index = name.lastIndexOf(':'); - if (index == -1) { - return null; - } - - return name.substring(0, index); + return index < 0 ? null : name.substring(0, index); } public static String getLocalName(Node node) { @@ -617,11 +596,7 @@ String name = node.getNodeName(); int index = name.lastIndexOf(':'); - if (index == -1) { - return name; - } - - return name.substring(index + 1); + return index < 0 ? name : name.substring(index + 1); } public static String getNamespaceURI(Node node) { @@ -636,14 +611,8 @@ return uri; } - String qname; String prefix = getPrefix(node); - if (prefix == null) { - qname = "xmlns"; - } - else { - qname = "xmlns:" + prefix; - } + String qname = prefix == null ? "xmlns" : "xmlns:" + prefix; Node aNode = node; while (aNode != null) { @@ -668,50 +637,39 @@ String text = ((Comment) node).getData(); return text == null ? "" : text.trim(); } - else if ( + if ( nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) { String text = node.getNodeValue(); return text == null ? "" : text.trim(); } - else if (nodeType == Node.PROCESSING_INSTRUCTION_NODE) { + if (nodeType == Node.PROCESSING_INSTRUCTION_NODE) { String text = ((ProcessingInstruction) node).getData(); return text == null ? "" : text.trim(); } - else { - NodeList list = node.getChildNodes(); - StringBuffer buf = new StringBuffer(16); - for (int i = 0; i < list.getLength(); i++) { - Node child = list.item(i); - if (child.getNodeType() == Node.TEXT_NODE) { - buf.append(child.getNodeValue()); - } - else { - buf.append(stringValue(child)); - } + NodeList list = node.getChildNodes(); + StringBuffer buf = new StringBuffer(16); + for (int i = 0; i < list.getLength(); i++) { + Node child = list.item(i); + if (child.getNodeType() == Node.TEXT_NODE) { + buf.append(child.getNodeValue()); + } + else { + buf.append(stringValue(child)); } - return buf.toString().trim(); } + return buf.toString().trim(); } /** * Locates a node by ID. */ public Pointer getPointerByID(JXPathContext context, String id) { - Document document; - if (node.getNodeType() == Node.DOCUMENT_NODE) { - document = (Document) node; - } - else { - document = node.getOwnerDocument(); - } + Document document = node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node + : node.getOwnerDocument(); Element element = document.getElementById(id); - if (element != null) { - return new DOMNodePointer(element, getLocale(), id); - } - else { - return new NullPointer(getLocale(), id); - } + return element == null ? new NullPointer(getLocale(), id) + : new DOMNodePointer(element, getLocale(), id); } private AbstractFactory getAbstractFactory(JXPathContext context) { @@ -739,10 +697,10 @@ if (t1 == Node.ATTRIBUTE_NODE && t2 != Node.ATTRIBUTE_NODE) { return -1; } - else if (t1 != Node.ATTRIBUTE_NODE && t2 == Node.ATTRIBUTE_NODE) { + if (t1 != Node.ATTRIBUTE_NODE && t2 == Node.ATTRIBUTE_NODE) { return 1; } - else if (t1 == Node.ATTRIBUTE_NODE && t2 == Node.ATTRIBUTE_NODE) { + if (t1 == Node.ATTRIBUTE_NODE && t2 == Node.ATTRIBUTE_NODE) { NamedNodeMap map = ((Node) getNode()).getAttributes(); int length = map.getLength(); for (int i = 0; i < length; i++) { @@ -750,7 +708,7 @@ if (n == node1) { return -1; } - else if (n == node2) { + if (n == node2) { return 1; } } @@ -762,12 +720,11 @@ if (current == node1) { return -1; } - else if (current == node2) { + if (current == node2) { return 1; } current = current.getNextSibling(); } - return 0; } } Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMPointerFactory.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMPointerFactory.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMPointerFactory.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMPointerFactory.java Mon Feb 19 15:24:43 2007 @@ -42,10 +42,7 @@ Object bean, Locale locale) { - if (bean instanceof Node) { - return new DOMNodePointer((Node) bean, locale); - } - return null; + return bean instanceof Node ? new DOMNodePointer((Node) bean, locale) : null; } public NodePointer createNodePointer( @@ -53,9 +50,6 @@ QName name, Object bean) { - if (bean instanceof Node) { - return new DOMNodePointer(parent, (Node) bean); - } - return null; + return bean instanceof Node ? new DOMNodePointer(parent, (Node) bean) : null; } } Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPointer.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPointer.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPointer.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPointer.java Mon Feb 19 15:24:43 2007 @@ -98,33 +98,23 @@ } DynaBeanPointer other = (DynaBeanPointer) object; - if (parent != other.parent) { - if (parent == null || !parent.equals(other.parent)) { - return false; - } - } - - if ((name == null && other.name != null) - || (name != null && !name.equals(other.name))) { + if (!(equalObjects(parent, other.parent) && equalObjects(name, other.name))) { return false; } int iThis = (index == WHOLE_COLLECTION ? 0 : index); int iOther = (other.index == WHOLE_COLLECTION ? 0 : other.index); - if (iThis != iOther) { - return false; - } - - return dynaBean == other.dynaBean; + return iThis == iOther && dynaBean == other.dynaBean; } /** * If there's a parent - parent's path, otherwise "/". */ public String asPath() { - if (parent != null) { - return super.asPath(); - } - return "/"; + return parent == null ? "/" : super.asPath(); + } + + private static boolean equalObjects(Object o1, Object o2) { + return o1 == o2 || o1 != null && o1.equals(o2); } } Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPointerFactory.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPointerFactory.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPointerFactory.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPointerFactory.java Mon Feb 19 15:24:43 2007 @@ -43,18 +43,12 @@ public NodePointer createNodePointer( QName name, Object bean, Locale locale) { - if (bean instanceof DynaBean) { - return new DynaBeanPointer(name, (DynaBean) bean, locale); - } - return null; + return bean instanceof DynaBean ? new DynaBeanPointer(name, (DynaBean) bean, locale) : null; } public NodePointer createNodePointer( NodePointer parent, QName name, Object bean) { - if (bean instanceof DynaBean) { - return new DynaBeanPointer(parent, name, (DynaBean) bean); - } - return null; + return bean instanceof DynaBean ? new DynaBeanPointer(parent, name, (DynaBean) bean) : null; } } Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer.java Mon Feb 19 15:24:43 2007 @@ -94,12 +94,7 @@ public String getPropertyName() { if (name == null) { String names[] = getPropertyNames(); - if (propertyIndex >= 0 && propertyIndex < names.length) { - name = names[propertyIndex]; - } - else { - name = "*"; - } + name = propertyIndex >= 0 && propertyIndex < names.length ? names[propertyIndex] : "*"; } return name; } Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPointer.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPointer.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPointer.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPointer.java Mon Feb 19 15:24:43 2007 @@ -89,8 +89,7 @@ public boolean isLeaf() { Object value = getNode(); - return value == null - || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); + return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); } public boolean isCollection() { @@ -105,10 +104,7 @@ } public String asPath() { - if (parent != null) { - return super.asPath(); - } - return "/"; + return parent == null ? "/" : super.asPath(); } public int hashCode() { Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertyPointer.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertyPointer.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertyPointer.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertyPointer.java Mon Feb 19 15:24:43 2007 @@ -97,12 +97,7 @@ public String getPropertyName() { if (name == null) { String names[] = getPropertyNames(); - if (propertyIndex >= 0 && propertyIndex < names.length) { - name = names[propertyIndex]; - } - else { - name = "*"; - } + name = propertyIndex >= 0 && propertyIndex < names.length ? names[propertyIndex] : "*"; } return name; } Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java Mon Feb 19 15:24:43 2007 @@ -35,13 +35,11 @@ */ public class JDOMAttributeIterator implements NodeIterator { private NodePointer parent; -// private QName name; private List attributes; private int position = 0; public JDOMAttributeIterator(NodePointer parent, QName name) { this.parent = parent; -// this.name = name; if (parent.getNode() instanceof Element) { Element element = (Element) parent.getNode(); String prefix = name.getPrefix(); @@ -86,80 +84,6 @@ } } - /* - private boolean testAttr(Attr attr, QName testName) { - String nodePrefix = DOMNodePointer.getPrefix(attr); - String nodeLocalName = DOMNodePointer.getLocalName(attr); - - if (nodePrefix != null && nodePrefix.equals("xmlns")) { - return false; - } - - if (nodePrefix == null && nodeLocalName.equals("xmlns")) { - return false; - } - - String testLocalName = name.getName(); - if (testLocalName.equals("*") || testLocalName.equals(nodeLocalName)) { - String testPrefix = testName.getPrefix(); - - if (equalStrings(testPrefix, nodePrefix)) { - return true; - } - - String testNS = null; - if (testPrefix != null) { - testNS = parent.getNamespaceURI(testPrefix); - } - - String nodeNS = null; - if (nodePrefix != null) { - nodeNS = parent.getNamespaceURI(nodePrefix); - } - return equalStrings(testNS, nodeNS); - } - return false; - } - - private static boolean equalStrings(String s1, String s2) { - if (s1 == null && s2 != null) { - return false; - } - if (s1 != null && !s1.equals(s2)) { - return false; - } - return true; - } - - private Attr getAttribute(Element element, QName name) { - String testPrefix = name.getPrefix(); - String testNS = null; - - if (testPrefix != null) { - testNS = parent.getNamespaceURI(testPrefix); - } - - if (testNS != null) { - Attr attr = element.getAttributeNodeNS(testNS, name.getName()); - if (attr == null) { - // This may mean that the parser does not support NS for - // attributes, example - the version of Crimson bundled - // with JDK 1.4.0 - NamedNodeMap nnm = element.getAttributes(); - for (int i = 0; i < nnm.getLength(); i++) { - attr = (Attr)nnm.item(i); - if (testAttr(attr, name)) { - return attr; - } - } - } - return attr; - } - else { - return element.getAttributeNode(name.getName()); - } - } -*/ public NodePointer getNodePointer() { if (position == 0) { if (!setPosition(1)) { Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributePointer.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributePointer.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributePointer.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributePointer.java Mon Feb 19 15:24:43 2007 @@ -109,16 +109,8 @@ } public boolean equals(Object object) { - if (object == this) { - return true; - } - - if (!(object instanceof JDOMAttributePointer)) { - return false; - } - - JDOMAttributePointer other = (JDOMAttributePointer) object; - return attr == other.attr; + return object == this || object instanceof JDOMAttributePointer + && ((JDOMAttributePointer) object).attr == attr; } public int compareChildNodePointers( Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNamespacePointer.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNamespacePointer.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNamespacePointer.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNamespacePointer.java Mon Feb 19 15:24:43 2007 @@ -101,16 +101,7 @@ } public boolean equals(Object object) { - if (object == this) { - return true; - } - - if (!(object instanceof JDOMNamespacePointer)) { - return false; - } - - JDOMNamespacePointer other = (JDOMNamespacePointer) object; - return prefix.equals(other.prefix); + return object == this || object instanceof JDOMNamespacePointer && prefix.equals(((JDOMNamespacePointer) object).prefix); } public int compareChildNodePointers( Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java Mon Feb 19 15:24:43 2007 @@ -141,11 +141,11 @@ if ((node1 instanceof Attribute) && !(node2 instanceof Attribute)) { return -1; } - else if ( + if ( !(node1 instanceof Attribute) && (node2 instanceof Attribute)) { return 1; } - else if ( + if ( (node1 instanceof Attribute) && (node2 instanceof Attribute)) { List list = ((Element) getNode()).getAttributes(); int length = list.size(); @@ -175,7 +175,7 @@ if (n == node1) { return -1; } - else if (n == node2) { + if (n == node2) { return 1; } } @@ -203,7 +203,7 @@ if (node instanceof Element) { return ((Element) node).getContent().size() == 0; } - else if (node instanceof Document) { + if (node instanceof Document) { return ((Document) node).getContent().size() == 0; } return true; @@ -239,20 +239,20 @@ if (node instanceof Element) { return ((Element) node).getTextTrim(); } - else if (node instanceof Comment) { + if (node instanceof Comment) { String text = ((Comment) node).getText(); if (text != null) { text = text.trim(); } return text; } - else if (node instanceof Text) { + if (node instanceof Text) { return ((Text) node).getTextTrim(); } - else if (node instanceof CDATA) { + if (node instanceof CDATA) { return ((CDATA) node).getTextTrim(); } - else if (node instanceof ProcessingInstruction) { + if (node instanceof ProcessingInstruction) { String text = ((ProcessingInstruction) node).getData(); if (text != null) { text = text.trim(); @@ -348,7 +348,7 @@ if (test == null) { return true; } - else if (test instanceof NodeNameTest) { + if (test instanceof NodeNameTest) { if (!(node instanceof Element)) { return false; } @@ -368,9 +368,9 @@ String nodeNS = JDOMNodePointer.getNamespaceURI(node); return equalStrings(namespaceURI, nodeNS); } - + return false; } - else if (test instanceof NodeTypeTest) { + if (test instanceof NodeTypeTest) { switch (((NodeTypeTest) test).getNodeType()) { case Compiler.NODE_TYPE_NODE : return (node instanceof Element) || (node instanceof Document); @@ -383,30 +383,21 @@ } return false; } - else if (test instanceof ProcessingInstructionTest) { - if (node instanceof ProcessingInstruction) { - String testPI = ((ProcessingInstructionTest) test).getTarget(); - String nodePI = ((ProcessingInstruction) node).getTarget(); - return testPI.equals(nodePI); - } + if (test instanceof ProcessingInstructionTest && node instanceof ProcessingInstruction) { + String testPI = ((ProcessingInstructionTest) test).getTarget(); + String nodePI = ((ProcessingInstruction) node).getTarget(); + return testPI.equals(nodePI); } - return false; } private static boolean equalStrings(String s1, String s2) { - if (s1 == null && s2 != null) { - return false; - } - if (s1 != null && s2 == null) { - return false; - } - - if (s1 != null && !s1.trim().equals(s2.trim())) { - return false; + if (s1 == s2) { + return true; } - - return true; + s1 = s1 == null ? "" : s1.trim(); + s2 = s2 == null ? "" : s2.trim(); + return s1.equals(s2); } public static String getPrefix(Object node) { @@ -414,7 +405,7 @@ String prefix = ((Element) node).getNamespacePrefix(); return (prefix == null || prefix.equals("")) ? null : prefix; } - else if (node instanceof Attribute) { + if (node instanceof Attribute) { String prefix = ((Attribute) node).getNamespacePrefix(); return (prefix == null || prefix.equals("")) ? null : prefix; } @@ -425,7 +416,7 @@ if (node instanceof Element) { return ((Element) node).getName(); } - else if (node instanceof Attribute) { + if (node instanceof Attribute) { return ((Attribute) node).getName(); } return null; @@ -438,10 +429,7 @@ */ public boolean isLanguage(String lang) { String current = getLanguage(); - if (current == null) { - return super.isLanguage(lang); - } - return current.toUpperCase().startsWith(lang.toUpperCase()); + return current == null ? super.isLanguage(lang) : current.toUpperCase().startsWith(lang.toUpperCase()); } protected String getLanguage() { @@ -463,20 +451,18 @@ private Element nodeParent(Object node) { if (node instanceof Element) { Object parent = ((Element) node).getParent(); - if (parent instanceof Element) { - return (Element) parent; - } + return parent instanceof Element ? (Element) parent : null; } - else if (node instanceof Text) { + if (node instanceof Text) { return (Element) ((Text) node).getParent(); } - else if (node instanceof CDATA) { + if (node instanceof CDATA) { return (Element) ((CDATA) node).getParent(); } - else if (node instanceof ProcessingInstruction) { + if (node instanceof ProcessingInstruction) { return (Element) ((ProcessingInstruction) node).getParent(); } - else if (node instanceof Comment) { + if (node instanceof Comment) { return (Element) ((Comment) node).getParent(); } return null; Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMPointerFactory.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMPointerFactory.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMPointerFactory.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMPointerFactory.java Mon Feb 19 15:24:43 2007 @@ -44,7 +44,7 @@ if (bean instanceof Document) { return new JDOMNodePointer(bean, locale); } - else if (bean instanceof Element) { + if (bean instanceof Element) { return new JDOMNodePointer(bean, locale); } return null; @@ -56,7 +56,7 @@ if (bean instanceof Document) { return new JDOMNodePointer(parent, bean); } - else if (bean instanceof Element) { + if (bean instanceof Element) { return new JDOMNodePointer(parent, bean); } return null; Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/servlet/KeywordVariables.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/servlet/KeywordVariables.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/servlet/KeywordVariables.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/servlet/KeywordVariables.java Mon Feb 19 15:24:43 2007 @@ -40,10 +40,7 @@ } public Object getVariable(String variable) { - if (variable.equals(keyword)) { - return object; - } - return null; + return isDeclaredVariable(variable) ? object : null; } public void declareVariable(String variable, Object value) { Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/servlet/ServletRequestAndContext.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/servlet/ServletRequestAndContext.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/servlet/ServletRequestAndContext.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/servlet/ServletRequestAndContext.java Mon Feb 19 15:24:43 2007 @@ -39,14 +39,11 @@ this.request = request; } - public HttpSession getSession() { - if (request instanceof HttpServletRequest) { - return ((HttpServletRequest)request).getSession(false); - } - return null; + return request instanceof HttpServletRequest + ? ((HttpServletRequest) request).getSession(false) : null; } - + public ServletRequest getServletRequest() { return request; } Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/util/BasicTypeConverter.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/util/BasicTypeConverter.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/util/BasicTypeConverter.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/util/BasicTypeConverter.java Mon Feb 19 15:24:43 2007 @@ -25,6 +25,7 @@ import java.util.Iterator; import java.util.List; import java.util.Set; +import java.util.SortedSet; import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.beanutils.Converter; @@ -73,18 +74,18 @@ return true; } } - else if (object instanceof Number) { + if (object instanceof Number) { if (toType.isPrimitive() || Number.class.isAssignableFrom(toType)) { return true; } } - else if (object instanceof Character) { + if (object instanceof Character) { if (toType == char.class) { return true; } } - else if (object instanceof String) { + if (object instanceof String) { if (toType.isPrimitive()) { return true; } @@ -99,7 +100,7 @@ return true; } } - else if (fromType.isArray()) { + if (fromType.isArray()) { // Collection -> array if (toType.isArray()) { Class cType = toType.getComponentType(); @@ -112,20 +113,16 @@ } return true; } - else if (Collection.class.isAssignableFrom(toType)) { + if (Collection.class.isAssignableFrom(toType)) { return canCreateCollection(toType); } - else { - if (Array.getLength(object) > 0) { - Object value = Array.get(object, 0); - return canConvert(value, toType); - } - else { - return canConvert("", toType); - } + if (Array.getLength(object) > 0) { + Object value = Array.get(object, 0); + return canConvert(value, toType); } + return canConvert("", toType); } - else if (object instanceof Collection) { + if (object instanceof Collection) { // Collection -> array if (toType.isArray()) { Class cType = toType.getComponentType(); @@ -138,30 +135,26 @@ } return true; } - else if (Collection.class.isAssignableFrom(toType)) { + if (Collection.class.isAssignableFrom(toType)) { return canCreateCollection(toType); } - else { - if (((Collection) object).size() > 0) { - Object value; - if (object instanceof List) { - value = ((List) object).get(0); - } - else { - Iterator it = ((Collection) object).iterator(); - value = it.next(); - } - return canConvert(value, toType); + if (((Collection) object).size() > 0) { + Object value; + if (object instanceof List) { + value = ((List) object).get(0); } else { - return canConvert("", toType); + Iterator it = ((Collection) object).iterator(); + value = it.next(); } + return canConvert(value, toType); } + return canConvert("", toType); } - else if (object instanceof NodeSet) { + if (object instanceof NodeSet) { return canConvert(((NodeSet) object).getValues(), toType); } - else if (object instanceof Pointer) { + if (object instanceof Pointer) { return canConvert(((Pointer) object).getValue(), toType); } return ConvertUtils.lookup(toType) != null; @@ -174,17 +167,14 @@ */ public Object convert(Object object, Class toType) { if (object == null) { - if (toType.isPrimitive()) { - return convertNullToPrimitive(toType); - } - return null; + return toType.isPrimitive() ? convertNullToPrimitive(toType) : null; } if (toType == Object.class) { if (object instanceof NodeSet) { return convert(((NodeSet) object).getValues(), toType); } - else if (object instanceof Pointer) { + if (object instanceof Pointer) { return convert(((Pointer) object).getValue(), toType); } return object; @@ -207,24 +197,20 @@ } return array; } - else if (Collection.class.isAssignableFrom(toType)) { + if (Collection.class.isAssignableFrom(toType)) { Collection collection = allocateCollection(toType); for (int i = 0; i < length; i++) { collection.add(Array.get(object, i)); } return unmodifiableCollection(collection); } - else { - if (length > 0) { - Object value = Array.get(object, 0); - return convert(value, toType); - } - else { - return convert("", toType); - } + if (length > 0) { + Object value = Array.get(object, 0); + return convert(value, toType); } + return convert("", toType); } - else if (object instanceof Collection) { + if (object instanceof Collection) { int length = ((Collection) object).size(); if (toType.isArray()) { Class cType = toType.getComponentType(); @@ -236,66 +222,63 @@ } return array; } - else if (Collection.class.isAssignableFrom(toType)) { + if (Collection.class.isAssignableFrom(toType)) { Collection collection = allocateCollection(toType); collection.addAll((Collection) object); return unmodifiableCollection(collection); } - else { - if (length > 0) { - Object value; - if (object instanceof List) { - value = ((List) object).get(0); - } - else { - Iterator it = ((Collection) object).iterator(); - value = it.next(); - } - return convert(value, toType); + if (length > 0) { + Object value; + if (object instanceof List) { + value = ((List) object).get(0); } else { - return convert("", toType); + Iterator it = ((Collection) object).iterator(); + value = it.next(); } + return convert(value, toType); } + return convert("", toType); } - else if (object instanceof NodeSet) { + if (object instanceof NodeSet) { return convert(((NodeSet) object).getValues(), toType); } - else if (object instanceof Pointer) { + if (object instanceof Pointer) { return convert(((Pointer) object).getValue(), toType); } - else if (toType == String.class) { + if (toType == String.class) { return object.toString(); } - else if (object instanceof Boolean) { + if (object instanceof Boolean) { if (toType == boolean.class) { return object; } - boolean value = ((Boolean) object).booleanValue(); - return allocateNumber(toType, value ? 1 : 0); + if (toType.isPrimitive() || Number.class.isAssignableFrom(toType)) { + boolean value = ((Boolean) object).booleanValue(); + return allocateNumber(toType, value ? 1 : 0); + } } - else if (object instanceof Number) { + if (object instanceof Number) { double value = ((Number) object).doubleValue(); if (toType == boolean.class || toType == Boolean.class) { return value == 0.0 ? Boolean.FALSE : Boolean.TRUE; } - if (toType.isPrimitive() - || Number.class.isAssignableFrom(toType)) { + if (toType.isPrimitive() || Number.class.isAssignableFrom(toType)) { return allocateNumber(toType, value); } } - else if (object instanceof Character) { + if (object instanceof Character) { if (toType == char.class) { return object; } } - else if (object instanceof String) { + if (object instanceof String) { Object value = convertStringToPrimitive(object, toType); if (value != null) { return value; } } - + Converter converter = ConvertUtils.lookup(toType); if (converter != null) { return converter.convert(toType, object); @@ -411,7 +394,7 @@ } } - if (type == List.class) { + if (type == List.class || type == Collection.class) { return new ArrayList(); } if (type == Set.class) { @@ -420,19 +403,20 @@ throw new JXPathInvalidAccessException( "Cannot create collection of type: " + type); } - + protected Collection unmodifiableCollection(Collection collection) { if (collection instanceof List) { return Collections.unmodifiableList((List) collection); } - else if (collection instanceof Set) { + if (collection instanceof SortedSet) { + return Collections.unmodifiableSortedSet((SortedSet) collection); + } + if (collection instanceof Set) { return Collections.unmodifiableSet((Set) collection); } - // Cannot wrap it into a proper unmodifiable collection, - // so we just return the original collection itself - return collection; + return Collections.unmodifiableCollection(collection); } - + static final class ValueNodeSet implements NodeSet { private List values; private List pointers; @@ -496,17 +480,17 @@ if (bean == null) { return "null()"; } - else if (bean instanceof Number) { + if (bean instanceof Number) { String string = bean.toString(); if (string.endsWith(".0")) { string = string.substring(0, string.length() - 2); } return string; } - else if (bean instanceof Boolean) { + if (bean instanceof Boolean) { return ((Boolean) bean).booleanValue() ? "true()" : "false()"; } - else if (bean instanceof String) { + if (bean instanceof String) { return "'" + bean + "'"; } return "{object of type " + bean.getClass().getName() + "}"; Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/util/ValueUtils.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/util/ValueUtils.java?view=diff&rev=509378&r1=509377&r2=509378 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/util/ValueUtils.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/util/ValueUtils.java Mon Feb 19 15:24:43 2007 @@ -55,7 +55,7 @@ if (value.getClass().isArray()) { return true; } - else if (value instanceof Collection) { + if (value instanceof Collection) { return true; } return false; @@ -138,12 +138,10 @@ if (collection.getClass().isArray()) { return Array.getLength(collection); } - else if (collection instanceof Collection) { + if (collection instanceof Collection) { return ((Collection) collection).size(); } - else { - return 1; - } + return 1; } /** @@ -166,12 +164,10 @@ } return list.iterator(); } - else if (collection instanceof Collection) { + if (collection instanceof Collection) { return ((Collection) collection).iterator(); } - else { - return Collections.singletonList(collection).iterator(); - } + return Collections.singletonList(collection).iterator(); } /** @@ -182,7 +178,7 @@ if (collection == null) { return null; } - else if (collection.getClass().isArray()) { + if (collection.getClass().isArray()) { Object bigger = Array.newInstance( collection.getClass().getComponentType(), @@ -195,19 +191,17 @@ Array.getLength(collection)); return bigger; } - else if (collection instanceof Collection) { + if (collection instanceof Collection) { while (((Collection) collection).size() < size) { ((Collection) collection).add(null); } return collection; } - else { - throw new JXPathException( - "Cannot turn " - + collection.getClass().getName() - + " into a collection of size " - + size); - } + throw new JXPathException( + "Cannot turn " + + collection.getClass().getName() + + " into a collection of size " + + size); } /** @@ -218,7 +212,7 @@ if (collection == null) { return null; } - else if (collection.getClass().isArray()) { + if (collection.getClass().isArray()) { int length = Array.getLength(collection); Object smaller = Array.newInstance( @@ -237,14 +231,14 @@ } return smaller; } - else if (collection instanceof List) { + if (collection instanceof List) { int size = ((List) collection).size(); if (index < size) { ((List) collection).remove(index); } return collection; } - else if (collection instanceof Collection) { + if (collection instanceof Collection) { Iterator it = ((Collection) collection).iterator(); for (int i = 0; i < index; i++) { if (!it.hasNext()) { @@ -258,14 +252,12 @@ } return collection; } - else { - throw new JXPathException( - "Cannot remove " - + collection.getClass().getName() - + "[" - + index - + "]"); - } + throw new JXPathException( + "Cannot remove " + + collection.getClass().getName() + + "[" + + index + + "]"); } /** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]