Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Enums for Filter operator #48

Open
GoogleCodeExporter opened this issue Mar 15, 2015 · 3 comments
Open

Using Enums for Filter operator #48

GoogleCodeExporter opened this issue Mar 15, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

A good idea would be to use an Enum for the Filter Operator. 

For example : 

public static final int OP_EQUAL = 0, OP_NOT_EQUAL = 1, OP_LESS_THAN = 2,
OP_GREATER_THAN = 3, OP_LESS_OR_EQUAL = 4,...

would be : 

public enum FilterOperator {
    EQUALS(0),
    NOT_EQUAL(1) //... More operators

    private int filterValue;

    private FilterOperator(int filterValue) {
        this.filterValue = filterValue;
    }

    public int getFilterValue() {
        return filterValue;
    }
}

For the first step, you could simply add this enum and provide a method to
construct filter from the enum (which calls
setOperator(enumFilter.getFilterValue())) and continue to use int in the
SearchProcessor, but, IMO the design will be better with an enum :)


Thanks 

Original issue reported on code.google.com by mathieu....@gmail.com on 26 Aug 2009 at 1:07

@GoogleCodeExporter
Copy link
Author

Sorry for the flood, i'm currently refactoring my code, and I realize that an 
other
Enum for the sort order  instead of a boolean would be easier to use.


Original comment by mathieu....@gmail.com on 26 Aug 2009 at 1:55

@GoogleCodeExporter
Copy link
Author

That sounds like it could be a good idea. We'll have to take some time to 
consider
the implications for interactions with other languages like Flex, JavaScript. 
But it
will probably work out just fine.

I'd like to see an example of how an Enum for sort order would be easier than a
boolean. A concrete example would make it easier to evaluate the alternatives.

Original comment by dwolvert on 1 Oct 2009 at 11:58

  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

In the example Mathieu provided you will preserve the original int value, which 
will allow the use of this enum in other systems that will not allow enums. We 
could also add a helper method inside the enum to convert the original int to 
the enum.

Original comment by terciofi...@gmail.com on 26 Oct 2011 at 6:50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant