tmf: HTNode coding style improvement.
authorFlorian Wininger <florian.wininger@polymtl.ca>
Thu, 24 Apr 2014 17:30:29 +0000 (13:30 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 28 Apr 2014 21:18:51 +0000 (17:18 -0400)
Change-Id: I9f298cdff2d583a738d7926ad5ba2b0fcd07bd9d
Signed-off-by: Florian Wininger <florian.wininger@polymtl.ca>
Reviewed-on: https://git.eclipse.org/r/25512
Tested-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
org.eclipse.linuxtools.statesystem.core/src/org/eclipse/linuxtools/internal/statesystem/core/backend/historytree/HTNode.java

index 8e7b2895212a03b8d2b6169a8bcd98bba15a400d..ab1ef7bd1512b6129a947e58f945ced3a691c34d 100644 (file)
@@ -394,7 +394,7 @@ public abstract class HTNode {
         try {
             assert (endtime >= this.nodeStart);
 
-            if (intervals.size() > 0) {
+            if (!intervals.isEmpty()) {
                 /*
                  * Sort the intervals by ascending order of their end time. This
                  * speeds up lookups a bit
@@ -433,12 +433,7 @@ public abstract class HTNode {
         /* This is from a state system query, we are "reading" this node */
         rwl.readLock().lock();
         try {
-            if (intervals.size() == 0) {
-                return;
-            }
-            int startIndex = getStartIndexFor(t);
-
-            for (int i = startIndex; i < intervals.size(); i++) {
+            for (int i = getStartIndexFor(t); i < intervals.size(); i++) {
                 /*
                  * Now we only have to compare the Start times, since we now the
                  * End times necessarily fit.
@@ -474,13 +469,7 @@ public abstract class HTNode {
     public HTInterval getRelevantInterval(int key, long t) throws TimeRangeException {
         rwl.readLock().lock();
         try {
-            if (intervals.size() == 0) {
-                return null;
-            }
-
-            int startIndex = getStartIndexFor(t);
-
-            for (int i = startIndex; i < intervals.size(); i++) {
+            for (int i = getStartIndexFor(t); i < intervals.size(); i++) {
                 HTInterval curInterval = intervals.get(i);
                 if (curInterval.getAttribute() == key
                         && curInterval.getStartTime() <= t
@@ -488,6 +477,7 @@ public abstract class HTNode {
                     return curInterval;
                 }
             }
+
             /* We didn't find the relevant information in this node */
             return null;
 
@@ -498,6 +488,10 @@ public abstract class HTNode {
 
     private int getStartIndexFor(long t) throws TimeRangeException {
         /* Should only be called by methods with the readLock taken */
+
+        if (intervals.isEmpty()) {
+            return 0;
+        }
         /*
          * Since the intervals are sorted by end time, we can skip all the ones
          * at the beginning whose end times are smaller than 't'. Java does
This page took 0.044557 seconds and 5 git commands to generate.