stiwari99 / hibernate-generic-dao

Automatically exported from code.google.com/p/hibernate-generic-dao
0 stars 0 forks source link

Using Enums for Filter operator #48

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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