diff options
author | Noel Grandin <noel@peralex.com> | 2014-11-11 15:32:10 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2014-11-12 08:01:55 +0000 |
commit | 36ff1527c9cb20542d3097d123d221c40a356795 (patch) | |
tree | 52590ce642803a862bc331b3eae2e2b100b8e85f /xmerge | |
parent | 1eb31467a5af90fe41dc646dd716bdb7d3e5db45 (diff) |
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 <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'xmerge')
3 files changed, 57 insertions, 52 deletions
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()); } } } |