Vojtech Szocs has posted comments on this change.

Change subject: webadmin: Render client-side sorting more robust
......................................................................


Patch Set 2:

(2 comments)

http://gerrit.ovirt.org/#/c/28268/2/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/SortedListModel.java
File 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/SortedListModel.java:

Line 25: 
Line 26:         @Override
Line 27:         public int compare(T a, T b) {
Line 28:             int res = sortAscending ? comparator.compare(a, b) : 
comparator.compare(b, a);
Line 29:             return res != 0 ? res : Integer.signum(positions.get(b) - 
positions.get(a));
I'd rather be more defensive concerning "positions" map, for example:

 int posA = positions.containsKey(a) ? positions.get(a) : undefinedPosition;
 int posB = positions.containsKey(b) ? positions.get(b) : undefinedPosition;

Also, shouldn't we compare "A vs. B" instead of "B vs. A" so that items with 
lower position are considered "before" items with higher positions?

 int posDelta = Integer.signum(posA - posB);

In above code, "undefinedPosition" is similar to null item, so it could be 
Integer.MIN_VALUE (null first) or Integer.MAX_VALUE (null last).
Line 30:         }
Line 31: 
Line 32:         @Override
Line 33:         public boolean equals(Object obj) {


Line 97: 
Line 98:     private void initPositions(Collection<T> items) {
Line 99:         positions.clear();
Line 100:         Iterator<T> i = items.iterator();
Line 101:         for (int count=0; i.hasNext(); ++count) {
You can consider using a while loop here:

 int count = 0;
 while (i.hasNext()) {
     positions.put(i.next(), count++);
 }
Line 102:             positions.put(i.next(), count);
Line 103:         }
Line 104:     }
Line 105: 


-- 
To view, visit http://gerrit.ovirt.org/28268
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Iffd1ce7763e516ad109fdae5d584b183ee44117c
Gerrit-PatchSet: 2
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Lior Vernia <[email protected]>
Gerrit-Reviewer: Alexander Wels <[email protected]>
Gerrit-Reviewer: Daniel Erez <[email protected]>
Gerrit-Reviewer: Frank Kobzik <[email protected]>
Gerrit-Reviewer: Lior Vernia <[email protected]>
Gerrit-Reviewer: Vojtech Szocs <[email protected]>
Gerrit-Reviewer: [email protected]
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to