Vojtech Szocs has posted comments on this change.

Change subject: webadmin: remove sortby/page from searchstring
......................................................................


Patch Set 3:

(5 comments)

Nice! Some comments inline. This is exactly what I meant in my comment in 
CommonModel.java :-)

http://gerrit.ovirt.org/#/c/33787/3/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/StringConstants.java
File 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/StringConstants.java:

Line 1: package org.ovirt.engine.ui.uicommonweb;
Line 2: 
Line 3: public interface StringConstants {
Line 4:     static final String SPACE = " "; //$NON-NLS-1$
Inside Java interface, any non-method member is implicitly public, static and 
final, above is equivalent to:

 public interface StringConstants {
   String SPACE = " ";
 }

BTW can't we just use UIConstants#space instead?

 private final UIConstants constants = 
ConstantsManager.getInstance().getConstants();


http://gerrit.ovirt.org/#/c/33787/3/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/CommonModel.java
File 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/CommonModel.java:

Line 1255:         }
Line 1256:     }
Line 1257: 
Line 1258:     private boolean containsTokens(String searchString, 
SyntaxObjectType... tokens) {
Line 1259:         String upperSearchString = searchString.toUpperCase();
Is this really necessary? I'd expect the syntax checker to handle character 
case on its own.
Line 1260:         ISyntaxChecker syntaxChecker = 
getAutoCompleteModel().getSyntaxChecker();
Line 1261:         SyntaxContainer syntaxCont = 
syntaxChecker.analyzeSyntaxState(upperSearchString, true);
Line 1262:         Set<SyntaxObjectType> searchStringSet = new 
HashSet<SyntaxObjectType>();
Line 1263:         Iterator<SyntaxObject> iterator = syntaxCont.iterator();


Line 1258:     private boolean containsTokens(String searchString, 
SyntaxObjectType... tokens) {
Line 1259:         String upperSearchString = searchString.toUpperCase();
Line 1260:         ISyntaxChecker syntaxChecker = 
getAutoCompleteModel().getSyntaxChecker();
Line 1261:         SyntaxContainer syntaxCont = 
syntaxChecker.analyzeSyntaxState(upperSearchString, true);
Line 1262:         Set<SyntaxObjectType> searchStringSet = new 
HashSet<SyntaxObjectType>();
Please consider naming this "searchStringTokenSet" or similar to imply it 
contains tokens parsed from the search string.
Line 1263:         Iterator<SyntaxObject> iterator = syntaxCont.iterator();
Line 1264:         while(iterator.hasNext()) {
Line 1265:             searchStringSet.add(iterator.next().getType());
Line 1266:         }


Line 1259:         String upperSearchString = searchString.toUpperCase();
Line 1260:         ISyntaxChecker syntaxChecker = 
getAutoCompleteModel().getSyntaxChecker();
Line 1261:         SyntaxContainer syntaxCont = 
syntaxChecker.analyzeSyntaxState(upperSearchString, true);
Line 1262:         Set<SyntaxObjectType> searchStringSet = new 
HashSet<SyntaxObjectType>();
Line 1263:         Iterator<SyntaxObject> iterator = syntaxCont.iterator();
Nice, I missed the option of using iterator, so we don't have to modify 
SyntaxContainer class itself.
Line 1264:         while(iterator.hasNext()) {
Line 1265:             searchStringSet.add(iterator.next().getType());
Line 1266:         }
Line 1267:         Set<SyntaxObjectType> tokenSet = new 
HashSet<SyntaxObjectType>();


Line 1264:         while(iterator.hasNext()) {
Line 1265:             searchStringSet.add(iterator.next().getType());
Line 1266:         }
Line 1267:         Set<SyntaxObjectType> tokenSet = new 
HashSet<SyntaxObjectType>();
Line 1268:         tokenSet.addAll(Arrays.asList(tokens));
The "tokens" argument will be null if user calls method like so:

 containsTokens(anything); // note missing var-args parameter

and Arrays.asList(tokens) will throw NullPointerException in consequence.

This is why I generally prefer List (or Set) over var-args in cases like these.

If we want to use var-args, I suggest to do null check at the very beginning of 
this method:

 if (tokens == null) {
   return false;
 }
Line 1269:         searchStringSet.retainAll(tokenSet);
Line 1270:         return !searchStringSet.isEmpty();
Line 1271:     }
Line 1272: 


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I2b905d91e4b0a147df9c0e75c956e819ba42d0e6
Gerrit-PatchSet: 3
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alexander Wels <aw...@redhat.com>
Gerrit-Reviewer: Alexander Wels <aw...@redhat.com>
Gerrit-Reviewer: Einav Cohen <eco...@redhat.com>
Gerrit-Reviewer: Vojtech Szocs <vsz...@redhat.com>
Gerrit-Reviewer: automat...@ovirt.org
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to