Kaydet (Commit) 36ff1527 authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Noel Grandin

java: reduce excessive code indentation levels

by using early return in some methods

Change-Id: I3611c8c89b3a94ef7e1772d178acf065fd7fcdc7
Reviewed-on: https://gerrit.libreoffice.org/12374Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
Tested-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst 1eb31467
......@@ -563,7 +563,9 @@ public final class PropertySetMixin {
{
XInterfaceTypeDescription2 ifc = UnoRuntime.queryInterface(
XInterfaceTypeDescription2.class, resolveTypedefs(type));
if (seen.add(ifc.getName())) {
if (!seen.add(ifc.getName())) {
return;
}
XTypeDescription[] bases = ifc.getBaseTypes();
for (int i = 0; i < bases.length; ++i) {
initProperties(bases[i], map, handleNames, seen);
......@@ -665,7 +667,6 @@ public final class PropertySetMixin {
}
}
}
}
private String translateHandle(int handle) throws UnknownPropertyException {
if (handle < 0 || handle >= handleMap.length) {
......
......@@ -258,7 +258,9 @@ public class java_remote_bridge
final void remRefHolder(Type type, String oid) {
synchronized (refHolders) {
LinkedList<RefHolder> l = refHolders.get(oid);
if (l != null) {
if (l == null) {
return;
}
for (RefHolder rh : l) {
if (rh.getType().equals(type)) {
try {
......@@ -276,7 +278,6 @@ public class java_remote_bridge
}
}
}
}
final void freeHolders() {
synchronized (refHolders) {
......
......@@ -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);
}
}
......
......@@ -24,62 +24,64 @@ 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 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)
/**
* 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 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];
if (times <= 0)
return new int[0];
int realTimes = Math.min(maxNum, times);
boolean[] flags = new boolean[maxNum];
boolean isBelowHalf = times<maxNum*0.5;
boolean isBelowHalf = times < maxNum * 0.5;
int virtualTimes = realTimes;
if(!isBelowHalf) {
virtualTimes = maxNum-realTimes;
if (!isBelowHalf) {
virtualTimes = maxNum - realTimes;
}
int i = 0;
int upper = maxNum-1;
int upper = maxNum - 1;
int[] indices = new int[realTimes];
while(i<virtualTimes) {
while (i < virtualTimes) {
indices[i] = intRangeRandom(0, upper);
if(!flags[indices[i]]) {
if (!flags[indices[i]]) {
flags[indices[i]] = true;
i++;
}
}
if(!isBelowHalf) {
int j=0;
for(i=0; i<maxNum; i++) {
if(flags[i]==isBelowHalf) {
if (!isBelowHalf) {
int j = 0;
for (i = 0; i < maxNum; i++) {
if (flags[i] == isBelowHalf) {
indices[j] = i;
j++;
if(j==realTimes) break;
if (j == realTimes)
break;
}
}
}
......
......@@ -201,8 +201,9 @@ public class ProtocolHandlerAddon {
}
public void showMessageBox(String sTitle, String sMessage) {
if ( null != m_xFrame && null != m_xToolkit ) {
if ( null == m_xFrame || null == m_xToolkit ) {
return;
}
// describe window properties.
WindowDescriptor aDescriptor = new WindowDescriptor();
aDescriptor.Type = WindowClass.MODALTOP;
......@@ -228,7 +229,6 @@ public class ProtocolHandlerAddon {
}
}
}
}
/** Gives a factory for creating the service.
......
......@@ -56,7 +56,9 @@ public class _XChartDataArray extends MultiMethodTest {
mbExcludeSetRowAndSetColumn = true;
msExcludeMessage = (String)o;
}
if (!mbExcludeSetRowAndSetColumn) {
if (mbExcludeSetRowAndSetColumn) {
return;
}
XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, oObj);
if(xProp != null) {
try {
......@@ -74,7 +76,6 @@ public class _XChartDataArray extends MultiMethodTest {
}
}
}
}
/**
* Test calls the method and restores new values. <p>
......
......@@ -118,7 +118,6 @@ public class DeployedUnoPackagesDB {
Element langNode = null;
int len = 0;
NodeList langNodes = null;
boolean result = false;
if ((langNodes = main.getElementsByTagName("language")) != null &&
(len = langNodes.getLength()) != 0) {
......@@ -132,9 +131,12 @@ public class DeployedUnoPackagesDB {
}
}
if (langNode != null) {
if (langNode == null) {
return false;
}
len = 0;
NodeList packages = null;
boolean result = false;
if ((packages = langNode.getElementsByTagName("package")) != null &&
(len = packages.getLength()) != 0) {
......@@ -150,7 +152,6 @@ public class DeployedUnoPackagesDB {
}
}
}
}
return result;
}
......
......@@ -466,10 +466,11 @@ public class Helper
protected static String GetFilterName( XComponentContext xContext, String aTypeName, String aDocServiceName )
{
if ( xContext == null || aTypeName == null || aTypeName.length() == 0
|| aDocServiceName == null || aDocServiceName.length() == 0 ) {
return "";
}
String aFilterName = "";
if ( xContext != null && aTypeName != null && aTypeName.length() != 0
&& aDocServiceName != null && aDocServiceName.length() != 0 )
{
try
{
Object oFilterFactory = xContext.getServiceManager().createInstanceWithContext( "com.sun.star.document.FilterFactory", xContext );
......@@ -511,7 +512,6 @@ public class Helper
{
e.printStackTrace();
}
}
return aFilterName;
}
......
......@@ -125,8 +125,9 @@ public class WikiDialog implements XDialogEventHandler, XTopWindowListener
private static void SetTitle( XDialog xDialog, String sTitle )
throws Exception
{
if ( xDialog != null && sTitle != null )
{
if ( xDialog == null || sTitle == null ) {
return;
}
XControl xDialogControl = UnoRuntime.queryInterface( XControl.class, xDialog );
if ( xDialogControl != null )
{
......@@ -135,7 +136,6 @@ public class WikiDialog implements XDialogEventHandler, XTopWindowListener
xPropSet.setPropertyValue( "Title", sTitle );
}
}
}
protected XPropertySet GetPropSet(String sControl)
{
......
......@@ -41,8 +41,9 @@ class WikiProtocolSocketFactory implements SecureProtocolSocketFactory
private synchronized SSLContext GetNotSoSecureSSLContext()
{
if ( m_aSSLContext == null )
{
if ( m_aSSLContext != null ) {
return m_aSSLContext;
}
TrustManager[] pTrustUnknownCerts = new TrustManager[]
{
new X509TrustManager() {
......@@ -102,7 +103,6 @@ class WikiProtocolSocketFactory implements SecureProtocolSocketFactory
catch ( Exception e )
{
}
}
if ( m_aSSLContext == null )
throw new HttpClientError();
......
......@@ -32,31 +32,27 @@ class TextUpdateListener implements TreeModelListener
// 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) )
{
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:
......
......@@ -93,7 +93,9 @@ public class StyleCatalog {
families = new String[0];
if (classes == null)
classes = new Class[0];
if (node.hasChildNodes()) {
if (!node.hasChildNodes()) {
return;
}
NodeList children = node.getChildNodes();
int len = children.getLength();
......@@ -101,7 +103,8 @@ public class StyleCatalog {
boolean found = false;
Node child = children.item(i);
String name = child.getNodeName();
if (name.equals("style:default-style") || name.equals("style:style")) {
if (name.equals("style:default-style")
|| name.equals("style:style")) {
String familyName = getFamilyName(child);
if (familyName == null) {
Debug.log(Debug.ERROR, "familyName is null!");
......@@ -114,12 +117,12 @@ public class StyleCatalog {
found = true;
}
}
if ((!found || alwaysCreateDefault) && (defaultClass != null))
if ((!found || alwaysCreateDefault)
&& (defaultClass != null))
callConstructor(defaultClass, child);
}
}
}
}
/**
* Call the constructor of class {@code cls} with parameters {@code node},
......
......@@ -87,7 +87,9 @@ 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()) {
if (!node.hasChildNodes()) {
return;
}
NodeList children = node.getChildNodes();
int len = children.getLength();
for (int i = 0; i < len; i++) {
......@@ -106,7 +108,6 @@ public class TextStyle extends Style implements Cloneable {
}
}
}
}
/**
* Constructor for use when going from client device format to DOM
......
......@@ -60,7 +60,9 @@ 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()) {
if (!node.hasChildNodes()) {
return;
}
NodeList children = node.getChildNodes();
int len = children.getLength();
for (int i = 0; i < len; i++) {
......@@ -79,7 +81,6 @@ public class RowStyle extends Style implements Cloneable {
}
}
}
}
/**
* Constructor for use when going from client device format to DOM.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment