From 36ff1527c9cb20542d3097d123d221c40a356795 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 11 Nov 2014 15:32:10 +0200 Subject: java: reduce excessive code indentation levels by using early return in some methods Change-Id: I3611c8c89b3a94ef7e1772d178acf065fd7fcdc7 Reviewed-on: https://gerrit.libreoffice.org/12374 Reviewed-by: Noel Grandin Tested-by: Noel Grandin --- .../sun/star/lib/uno/helper/PropertySetMixin.java | 185 +++++++++++---------- .../bridges/java_remote/java_remote_bridge.java | 25 +-- jurt/com/sun/star/uno/WeakReference.java | 25 ++- .../net/adaptivebox/global/RandomGenerator.java | 114 ++++++------- .../ProtocolHandlerAddon.java | 48 +++--- .../tests/java/ifc/chart/_XChartDataArray.java | 29 ++-- .../framework/container/DeployedUnoPackagesDB.java | 29 ++-- swext/mediawiki/src/com/sun/star/wiki/Helper.java | 66 ++++---- .../src/com/sun/star/wiki/WikiDialog.java | 16 +- .../sun/star/wiki/WikiProtocolSocketFactory.java | 90 +++++----- toolkit/test/accessibility/TextUpdateListener.java | 36 ++-- .../xmerge/converter/xml/StyleCatalog.java | 47 +++--- .../openoffice/xmerge/converter/xml/TextStyle.java | 31 ++-- .../xmerge/converter/xml/sxc/RowStyle.java | 31 ++-- 14 files changed, 389 insertions(+), 383 deletions(-) diff --git a/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java b/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java index f3d9a8e907b2..7e2af48e1e56 100644 --- a/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java +++ b/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java @@ -563,106 +563,107 @@ public final class PropertySetMixin { { XInterfaceTypeDescription2 ifc = UnoRuntime.queryInterface( XInterfaceTypeDescription2.class, resolveTypedefs(type)); - if (seen.add(ifc.getName())) { - XTypeDescription[] bases = ifc.getBaseTypes(); - for (int i = 0; i < bases.length; ++i) { - initProperties(bases[i], map, handleNames, seen); - } - XInterfaceMemberTypeDescription[] members = ifc.getMembers(); - for (int i = 0; i < members.length; ++i) { - if (members[i].getTypeClass() == TypeClass.INTERFACE_ATTRIBUTE) - { - XInterfaceAttributeTypeDescription2 attr = - UnoRuntime.queryInterface( - XInterfaceAttributeTypeDescription2.class, - members[i]); - short attrAttribs = 0; - if (attr.isBound()) { - attrAttribs |= PropertyAttribute.BOUND; + if (!seen.add(ifc.getName())) { + return; + } + XTypeDescription[] bases = ifc.getBaseTypes(); + for (int i = 0; i < bases.length; ++i) { + initProperties(bases[i], map, handleNames, seen); + } + XInterfaceMemberTypeDescription[] members = ifc.getMembers(); + for (int i = 0; i < members.length; ++i) { + if (members[i].getTypeClass() == TypeClass.INTERFACE_ATTRIBUTE) + { + XInterfaceAttributeTypeDescription2 attr = + UnoRuntime.queryInterface( + XInterfaceAttributeTypeDescription2.class, + members[i]); + short attrAttribs = 0; + if (attr.isBound()) { + attrAttribs |= PropertyAttribute.BOUND; + } + boolean setUnknown = false; + if (attr.isReadOnly()) { + attrAttribs |= PropertyAttribute.READONLY; + setUnknown = true; + } + XCompoundTypeDescription[] excs = attr.getGetExceptions(); + boolean getUnknown = false; + //XXX Special interpretation of getter/setter exceptions + // only works if the specified exceptions are of the exact + // type, not of a supertype: + for (int j = 0; j < excs.length; ++j) { + if (excs[j].getName().equals( + "com.sun.star.beans.UnknownPropertyException")) + { + getUnknown = true; + break; } - boolean setUnknown = false; - if (attr.isReadOnly()) { - attrAttribs |= PropertyAttribute.READONLY; + } + excs = attr.getSetExceptions(); + for (int j = 0; j < excs.length; ++j) { + if (excs[j].getName().equals( + "com.sun.star.beans.UnknownPropertyException")) + { setUnknown = true; + } else if (excs[j].getName().equals( + "com.sun.star.beans." + + "PropertyVetoException")) + { + attrAttribs |= PropertyAttribute.CONSTRAINED; } - XCompoundTypeDescription[] excs = attr.getGetExceptions(); - boolean getUnknown = false; - //XXX Special interpretation of getter/setter exceptions - // only works if the specified exceptions are of the exact - // type, not of a supertype: - for (int j = 0; j < excs.length; ++j) { - if (excs[j].getName().equals( - "com.sun.star.beans.UnknownPropertyException")) - { - getUnknown = true; - break; - } - } - excs = attr.getSetExceptions(); - for (int j = 0; j < excs.length; ++j) { - if (excs[j].getName().equals( - "com.sun.star.beans.UnknownPropertyException")) - { - setUnknown = true; - } else if (excs[j].getName().equals( - "com.sun.star.beans." - + "PropertyVetoException")) - { - attrAttribs |= PropertyAttribute.CONSTRAINED; - } - } - if (getUnknown && setUnknown) { - attrAttribs |= PropertyAttribute.OPTIONAL; + } + if (getUnknown && setUnknown) { + attrAttribs |= PropertyAttribute.OPTIONAL; + } + XTypeDescription t = attr.getType(); + for (;;) { + t = resolveTypedefs(t); + short n; + if (t.getName().startsWith( + "com.sun.star.beans.Ambiguous<")) + { + n = PropertyAttribute.MAYBEAMBIGUOUS; + } else if (t.getName().startsWith( + "com.sun.star.beans.Defaulted<")) + { + n = PropertyAttribute.MAYBEDEFAULT; + } else if (t.getName().startsWith( + "com.sun.star.beans.Optional<")) + { + n = PropertyAttribute.MAYBEVOID; + } else { + break; } - XTypeDescription t = attr.getType(); - for (;;) { - t = resolveTypedefs(t); - short n; - if (t.getName().startsWith( - "com.sun.star.beans.Ambiguous<")) - { - n = PropertyAttribute.MAYBEAMBIGUOUS; - } else if (t.getName().startsWith( - "com.sun.star.beans.Defaulted<")) - { - n = PropertyAttribute.MAYBEDEFAULT; - } else if (t.getName().startsWith( - "com.sun.star.beans.Optional<")) - { - n = PropertyAttribute.MAYBEVOID; - } else { + attrAttribs |= n; + t = (UnoRuntime.queryInterface( + XStructTypeDescription.class, t)). + getTypeArguments()[0]; + } + String name = members[i].getMemberName(); + boolean present = true; + if (absentOptional != null) { + for (int j = 0; j < absentOptional.length; ++j) { + if (name.equals(absentOptional[j])) { + present = false; break; } - attrAttribs |= n; - t = (UnoRuntime.queryInterface( - XStructTypeDescription.class, t)). - getTypeArguments()[0]; - } - String name = members[i].getMemberName(); - boolean present = true; - if (absentOptional != null) { - for (int j = 0; j < absentOptional.length; ++j) { - if (name.equals(absentOptional[j])) { - present = false; - break; - } - } } - if (map.put( - name, - new PropertyData( - new Property( - name, handleNames.size(), - new Type(t.getName(), t.getTypeClass()), - attrAttribs), - present)) - != null) - { - throw new RuntimeException( - "inconsistent UNO type registry"); - } - handleNames.add(name); } + if (map.put( + name, + new PropertyData( + new Property( + name, handleNames.size(), + new Type(t.getName(), t.getTypeClass()), + attrAttribs), + present)) + != null) + { + throw new RuntimeException( + "inconsistent UNO type registry"); + } + handleNames.add(name); } } } diff --git a/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java b/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java index c9473eae9a87..722f825e6ba5 100644 --- a/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java +++ b/jurt/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge.java @@ -258,21 +258,22 @@ public class java_remote_bridge final void remRefHolder(Type type, String oid) { synchronized (refHolders) { LinkedList l = refHolders.get(oid); - if (l != null) { - for (RefHolder rh : l) { - if (rh.getType().equals(type)) { - try { - if (rh.release()) { - l.remove(rh); - if (l.isEmpty()) { - refHolders.remove(oid); - } + if (l == null) { + return; + } + for (RefHolder rh : l) { + if (rh.getType().equals(type)) { + try { + if (rh.release()) { + l.remove(rh); + if (l.isEmpty()) { + refHolders.remove(oid); } - } finally { - release(); } - break; + } finally { + release(); } + break; } } } diff --git a/jurt/com/sun/star/uno/WeakReference.java b/jurt/com/sun/star/uno/WeakReference.java index 261bc1a170a2..81c4cd4facaf 100644 --- a/jurt/com/sun/star/uno/WeakReference.java +++ b/jurt/com/sun/star/uno/WeakReference.java @@ -43,19 +43,18 @@ public class WeakReference */ public WeakReference(WeakReference obj) { - if (obj != null) - { - Object weakImpl= obj.get(); - if (weakImpl != null) - { - XWeak weak= UnoRuntime.queryInterface(XWeak.class, weakImpl); - if (weak != null) - { - XAdapter adapter= weak.queryAdapter(); - if (adapter != null) - m_listener= new OWeakRefListener(adapter); - } - } + if (obj == null) { + return; + } + Object weakImpl = obj.get(); + if (weakImpl == null) { + return; + } + XWeak weak = UnoRuntime.queryInterface(XWeak.class, weakImpl); + if (weak != null) { + XAdapter adapter = weak.queryAdapter(); + if (adapter != null) + m_listener = new OWeakRefListener(adapter); } } diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java index 448ae01d9d64..86103ee97b3f 100644 --- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java +++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java @@ -24,65 +24,67 @@ package net.adaptivebox.global; public class RandomGenerator { -/**This function returns a random integer number between the lowLimit and upLimit. - * @param lowLimit lower limits - * upLimit The upper limits (between which the random number is to be generated) - * @return int return value - * Example: for find [0,1,2] -*/ -public static int intRangeRandom(int lowLimit,int upLimit){ - int num = (int)Math.floor(doubleRangeRandom(lowLimit,upLimit+1)-1E-10); - return(num); -} - -/**This function returns a random float number between the lowLimit and upLimit. - * @param lowLimit lower limits - * upLimit The upper limits (between which the random number is to be generated) - * @return double return value -*/ -public static double doubleRangeRandom(double lowLimit,double upLimit){ - double num = lowLimit + Math.random()*(upLimit-lowLimit); - return(num); -} - - - - - - - - - - public static int[] randomSelection(int maxNum, int times) { - if(times<=0) return new int[0]; - int realTimes = Math.min(maxNum, times); - boolean[] flags = new boolean[maxNum]; - boolean isBelowHalf = times 0) ) - { + // if the change is to the first child of a DefaultMutableTreeNode + // with an XAccessibleText child, then we call updateText + int[] aIndices = e.getChildIndices(); + if (aIndices == null || aIndices.length >= 0) { + return; + } // we have a parent... lets check for XAccessibleText then - DefaultMutableTreeNode aParent = (DefaultMutableTreeNode) - (e.getTreePath().getLastPathComponent()); - DefaultMutableTreeNode aNode = (DefaultMutableTreeNode) - (aParent.getChildAt(aIndices[0])); - if( aParent.getUserObject() instanceof XAccessibleText) - { + DefaultMutableTreeNode aParent = (DefaultMutableTreeNode) (e + .getTreePath().getLastPathComponent()); + DefaultMutableTreeNode aNode = (DefaultMutableTreeNode) (aParent + .getChildAt(aIndices[0])); + if (aParent.getUserObject() instanceof XAccessibleText) { // aha! we have an xText. So we can now check for // the various cases we support - XAccessibleText xText = - (XAccessibleText)aParent.getUserObject(); + XAccessibleText xText = (XAccessibleText) aParent + .getUserObject(); - if( aIndices[0] == 0 ) - { + if (aIndices[0] == 0) { // first child! Then we call updateText - updateText( xText, aNode.toString() ); + updateText(xText, aNode.toString()); } } + } catch (com.sun.star.lang.IndexOutOfBoundsException aException) { } - } - catch (com.sun.star.lang.IndexOutOfBoundsException aException) - {} } // don't care: diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/StyleCatalog.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/StyleCatalog.java index ac66285b4e45..5c34c0ef9c36 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/StyleCatalog.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/StyleCatalog.java @@ -84,39 +84,42 @@ public class StyleCatalog { * there is a match in the families array. */ public void add(Node node, String families[], Class classes[], - Class defaultClass, boolean alwaysCreateDefault) { + Class defaultClass, boolean alwaysCreateDefault) { - if (node == null) + if (node == null) return; if (families == null) families = new String[0]; if (classes == null) classes = new Class[0]; - if (node.hasChildNodes()) { - NodeList children = node.getChildNodes(); - int len = children.getLength(); + if (!node.hasChildNodes()) { + return; + } + NodeList children = node.getChildNodes(); + int len = children.getLength(); - for (int i = 0; i < len; i++) { - boolean found = false; - Node child = children.item(i); - String name = child.getNodeName(); - if (name.equals("style:default-style") || name.equals("style:style")) { - String familyName = getFamilyName(child); - if (familyName == null) { - Debug.log(Debug.ERROR, "familyName is null!"); - continue; - } + for (int i = 0; i < len; i++) { + boolean found = false; + Node child = children.item(i); + String name = child.getNodeName(); + if (name.equals("style:default-style") + || name.equals("style:style")) { + String familyName = getFamilyName(child); + if (familyName == null) { + Debug.log(Debug.ERROR, "familyName is null!"); + continue; + } - for (int j = 0; j < families.length; j++) { - if (families[j].equals(familyName)) { - callConstructor(classes[j], child); - found = true; - } + for (int j = 0; j < families.length; j++) { + if (families[j].equals(familyName)) { + callConstructor(classes[j], child); + found = true; } - if ((!found || alwaysCreateDefault) && (defaultClass != null)) - callConstructor(defaultClass, child); } + if ((!found || alwaysCreateDefault) + && (defaultClass != null)) + callConstructor(defaultClass, child); } } } diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/TextStyle.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/TextStyle.java index 20ccd6e7d51e..26115d4084a5 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/TextStyle.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/TextStyle.java @@ -87,21 +87,22 @@ public class TextStyle extends Style implements Cloneable { // Look for children. Only ones we care about are "style:properties" // nodes. If any are found, recursively traverse them, passing // along the style element to add properties to. - if (node.hasChildNodes()) { - NodeList children = node.getChildNodes(); - int len = children.getLength(); - for (int i = 0; i < len; i++) { - Node child = children.item(i); - String nodeName = child.getNodeName(); - if (nodeName.equals("style:properties")) { - NamedNodeMap childAttrNodes = child.getAttributes(); - if (childAttrNodes != null) { - int nChildAttrNodes = childAttrNodes.getLength(); - for (int j = 0; j < nChildAttrNodes; j++) { - Node attr = childAttrNodes.item(j); - handleAttribute(attr.getNodeName(), - attr.getNodeValue()); - } + if (!node.hasChildNodes()) { + return; + } + NodeList children = node.getChildNodes(); + int len = children.getLength(); + for (int i = 0; i < len; i++) { + Node child = children.item(i); + String nodeName = child.getNodeName(); + if (nodeName.equals("style:properties")) { + NamedNodeMap childAttrNodes = child.getAttributes(); + if (childAttrNodes != null) { + int nChildAttrNodes = childAttrNodes.getLength(); + for (int j = 0; j < nChildAttrNodes; j++) { + Node attr = childAttrNodes.item(j); + handleAttribute(attr.getNodeName(), + attr.getNodeValue()); } } } diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/RowStyle.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/RowStyle.java index 6639ce13e787..97bf0c9a0884 100644 --- a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/RowStyle.java +++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/RowStyle.java @@ -60,21 +60,22 @@ public class RowStyle extends Style implements Cloneable { // Look for children. Only ones we care about are "style:properties" // nodes. If any are found, recursively traverse them, passing // along the style element to add properties to. - if (node.hasChildNodes()) { - NodeList children = node.getChildNodes(); - int len = children.getLength(); - for (int i = 0; i < len; i++) { - Node child = children.item(i); - String nodeName = child.getNodeName(); - if (nodeName.equals("style:properties")) { - NamedNodeMap childAttrNodes = child.getAttributes(); - if (childAttrNodes != null) { - int nChildAttrNodes = childAttrNodes.getLength(); - for (int j = 0; j < nChildAttrNodes; j++) { - Node attr = childAttrNodes.item(j); - handleAttribute(attr.getNodeName(), - attr.getNodeValue()); - } + if (!node.hasChildNodes()) { + return; + } + NodeList children = node.getChildNodes(); + int len = children.getLength(); + for (int i = 0; i < len; i++) { + Node child = children.item(i); + String nodeName = child.getNodeName(); + if (nodeName.equals("style:properties")) { + NamedNodeMap childAttrNodes = child.getAttributes(); + if (childAttrNodes != null) { + int nChildAttrNodes = childAttrNodes.getLength(); + for (int j = 0; j < nChildAttrNodes; j++) { + Node attr = childAttrNodes.item(j); + handleAttribute(attr.getNodeName(), + attr.getNodeValue()); } } } -- cgit v1.2.3