summaryrefslogtreecommitdiff
path: root/javaunohelper/com
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2014-10-15 14:43:35 +0200
committerNoel Grandin <noel@peralex.com>2014-10-16 08:15:48 +0200
commit973eb2f6db60c0939299a968a3121e3310e6d1f5 (patch)
tree9eece355c20bc4d930e7e58943fc2d33bedfcfd0 /javaunohelper/com
parentfa652cdd2314f485359119a8ff081a7afd1c01b0 (diff)
java: reduce the depth of some deeply nested if blocks
Change-Id: I3c0c7f08d4d8ea594e72fc0d9b93d085d4ab4bf5
Diffstat (limited to 'javaunohelper/com')
-rw-r--r--javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java129
1 files changed, 67 insertions, 62 deletions
diff --git a/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java b/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java
index b49b28f523f2..48ca6c68ab72 100644
--- a/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java
+++ b/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java
@@ -352,27 +352,29 @@ public class InterfaceContainer implements Cloneable
*/
synchronized public int indexOf(Object elem)
{
+ if (elementData == null || elem == null) {
+ return -1;
+ }
+
int index= -1;
- if (elementData != null && elem != null)
+
+ for (int i = 0; i < size; i++)
{
- for (int i = 0; i < size; i++)
+ if (elem == elementData[i])
{
- if (elem == elementData[i])
- {
- index= i;
- break;
- }
+ index= i;
+ break;
}
+ }
- if (index == -1)
+ if (index == -1)
+ {
+ for (int i = 0; i < size; i++)
{
- for (int i = 0; i < size; i++)
+ if (UnoRuntime.areSame(elem, elementData[i]))
{
- if (UnoRuntime.areSame(elem, elementData[i]))
- {
- index= i;
- break;
- }
+ index= i;
+ break;
}
}
}
@@ -408,28 +410,30 @@ public class InterfaceContainer implements Cloneable
*/
synchronized public int lastIndexOf(Object elem)
{
+ if (elementData == null || elem == null) {
+ return -1;
+ }
+
int index= -1;
- if (elementData != null && elem != null)
+
+ for (int i = size-1; i >= 0; i--)
+ {
+ if (elem == elementData[i])
+ {
+ index= i;
+ break;
+ }
+ }
+ if (index == -1)
{
for (int i = size-1; i >= 0; i--)
{
- if (elem == elementData[i])
+ if (UnoRuntime.areSame(elem, elementData[i]))
{
index= i;
break;
}
}
- if (index == -1)
- {
- for (int i = size-1; i >= 0; i--)
- {
- if (UnoRuntime.areSame(elem, elementData[i]))
- {
- index= i;
- break;
- }
- }
- }
}
return index;
}
@@ -535,52 +539,53 @@ public class InterfaceContainer implements Cloneable
synchronized public boolean retainAll(Collection collection)
{
+ if (elementData == null || collection == null) {
+ return false;
+ }
+
boolean retVal= false;
- if (elementData != null && collection != null)
- {
- // iterate over data
- Object[] arRetained= new Object[size];
- int indexRetained= 0;
- for(int i= 0; i < size; i++)
+ // iterate over data
+ Object[] arRetained= new Object[size];
+ int indexRetained= 0;
+ for(int i= 0; i < size; i++)
+ {
+ Object curElem= elementData[i];
+ // try to find the element in collection
+ Iterator itColl= collection.iterator();
+ boolean bExists= false;
+ while (itColl.hasNext())
{
- Object curElem= elementData[i];
- // try to find the element in collection
- Iterator itColl= collection.iterator();
- boolean bExists= false;
- while (itColl.hasNext())
+ if (curElem == itColl.next())
{
- if (curElem == itColl.next())
- {
- // current element is in collection
- bExists= true;
- break;
- }
+ // current element is in collection
+ bExists= true;
+ break;
}
- if (!bExists)
+ }
+ if (!bExists)
+ {
+ itColl= collection.iterator();
+ while (itColl.hasNext())
{
- itColl= collection.iterator();
- while (itColl.hasNext())
+ Object o= itColl.next();
+ if (o != null)
{
- Object o= itColl.next();
- if (o != null)
+ if (UnoRuntime.areSame(o, curElem))
{
- if (UnoRuntime.areSame(o, curElem))
- {
- bExists= true;
- break;
- }
+ bExists= true;
+ break;
}
}
}
- if (bExists)
- arRetained[indexRetained++]= curElem;
- }
- retVal= size != indexRetained;
- if (indexRetained > 0)
- {
- elementData= arRetained;
- size= indexRetained;
}
+ if (bExists)
+ arRetained[indexRetained++]= curElem;
+ }
+ retVal= size != indexRetained;
+ if (indexRetained > 0)
+ {
+ elementData= arRetained;
+ size= indexRetained;
}
return retVal;
}