felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guillaume Nodet <gno...@gmail.com>
Subject Re: svn commit: r927298 - /felix/trunk/utils/src/main/java/org/apache/felix/utils/filter/FilterImpl.java
Date Thu, 25 Mar 2010 08:36:59 GMT
Yeah, I know.  That was my idea originally.  The problem is that some obr
repositories out there still use the '<' and '>' operator, so i'd like to
support those anyway.
I'll see if a better way would be to transform the filter expressions using
regexp before parsing them and turn '(x<a)'  into '(!(x>=a))'

On Thu, Mar 25, 2010 at 09:22, Richard S. Hall <heavy@ungoverned.org> wrote:

> I'm not sure it's a great idea to continue to extend the Filter impl. From
> my point of view it is better to stick to the standard filter where
> possible...I understand that the subset operator is necessary for time being
> to support mandatory attributes, but eventually we should be able to avoid
> that too.
>
> -> richard
>
>
> On 3/25/10 16:18, gnodet@apache.org wrote:
>
>> Author: gnodet
>> Date: Thu Mar 25 08:18:26 2010
>> New Revision: 927298
>>
>> URL: http://svn.apache.org/viewvc?rev=927298&view=rev
>> Log:
>> [utils] add support for<  and>  on the filter
>>
>> Modified:
>>
>> felix/trunk/utils/src/main/java/org/apache/felix/utils/filter/FilterImpl.java
>>
>> Modified:
>> felix/trunk/utils/src/main/java/org/apache/felix/utils/filter/FilterImpl.java
>> URL:
>> http://svn.apache.org/viewvc/felix/trunk/utils/src/main/java/org/apache/felix/utils/filter/FilterImpl.java?rev=927298&r1=927297&r2=927298&view=diff
>>
>> ==============================================================================
>> ---
>> felix/trunk/utils/src/main/java/org/apache/felix/utils/filter/FilterImpl.java
>> (original)
>> +++
>> felix/trunk/utils/src/main/java/org/apache/felix/utils/filter/FilterImpl.java
>> Thu Mar 25 08:18:26 2010
>> @@ -40,29 +40,31 @@ import org.osgi.framework.Version;
>>  public class FilterImpl implements Filter {
>>
>>      /* filter operators */
>> -    private static final int                   EQUAL           = 1;
>> -    private static final int                   APPROX          = 2;
>> -    private static final int                   GREATER         = 3;
>> -    private static final int                   LESS            = 4;
>> -    private static final int                   PRESENT         = 5;
>> -    private static final int                   SUBSTRING       = 6;
>> -    private static final int                   AND                     =
>> 7;
>> -    private static final int                   OR                      =
>> 8;
>> -    private static final int                   NOT                     =
>> 9;
>> -    private static final int                   SUBSET          = 10;
>> -    private static final int                   SUPERSET        = 11;
>> +    private static final int            EQUAL       = 1;
>> +    private static final int            APPROX      = 2;
>> +    private static final int            GTEQ        = 3;
>> +    private static final int            LTEQ        = 4;
>> +    private static final int            GT          = 5;
>> +    private static final int            LT          = 6;
>> +    private static final int            PRESENT     = 7;
>> +    private static final int            SUBSTRING   = 8;
>> +    private static final int            AND         = 9;
>> +    private static final int            OR          = 10;
>> +    private static final int            NOT         = 11;
>> +    private static final int            SUBSET      = 12;
>> +    private static final int            SUPERSET    = 13;
>>
>>      /** filter operation */
>> -    private final int                                  op;
>> +    private final int                   op;
>>      /** filter attribute or null if operation AND, OR or NOT */
>> -    private final String                               attr;
>> +    private final String                attr;
>>      /** filter operands */
>> -    private final Object                               value;
>> +    private final Object                value;
>>      /** optim in case of version */
>>      private final Object                converted;
>>
>>      /* normalized filter string for Filter object */
>> -    private transient volatile String  filterString;
>> +    private transient volatile String   filterString;
>>
>>      /**
>>       * Constructs a {@link FilterImpl} object. This filter object may be
>> @@ -263,20 +265,34 @@ public class FilterImpl implements Filte
>>
>>                  break;
>>              }
>> -            case GREATER : {
>> +            case GTEQ: {
>>                  sb.append(attr);
>>                  sb.append(">=");
>>                  sb.append(encodeValue((String) value));
>>
>>                  break;
>>              }
>> -            case LESS : {
>> +            case LTEQ: {
>>                  sb.append(attr);
>>                  sb.append("<=");
>>                  sb.append(encodeValue((String) value));
>>
>>                  break;
>>              }
>> +            case GT: {
>> +                sb.append(attr);
>> +                sb.append(">");
>> +                sb.append(encodeValue((String) value));
>> +
>> +                break;
>> +            }
>> +            case LT: {
>> +                sb.append(attr);
>> +                sb.append("<");
>> +                sb.append(encodeValue((String) value));
>> +
>> +                break;
>> +            }
>>              case APPROX : {
>>                  sb.append(attr);
>>                  sb.append("~=");
>> @@ -389,8 +405,10 @@ public class FilterImpl implements Filte
>>
>>              case SUBSTRING :
>>              case EQUAL :
>> -            case GREATER :
>> -            case LESS :
>> +            case GTEQ:
>> +            case LTEQ:
>> +            case GT:
>> +            case LT:
>>              case APPROX :
>>              case SUBSET :
>>              case SUPERSET : {
>> @@ -443,8 +461,10 @@ public class FilterImpl implements Filte
>>
>>              case SUBSTRING :
>>              case EQUAL :
>> -            case GREATER :
>> -            case LESS :
>> +            case GTEQ:
>> +            case LTEQ:
>> +            case GT:
>> +            case LT:
>>              case APPROX :
>>              case SUBSET :
>>              case SUPERSET : {
>> @@ -577,12 +597,18 @@ public class FilterImpl implements Filte
>>                      case EQUAL : {
>>                          return ((Version) value1).compareTo(converted) ==
>> 0;
>>                      }
>> -                    case GREATER : {
>> +                    case GTEQ: {
>>                          return ((Version) value1).compareTo(converted)>=
>> 0;
>>                      }
>> -                    case LESS : {
>> +                    case LTEQ: {
>>                          return ((Version) value1).compareTo(converted)<=
>> 0;
>>                      }
>> +                    case GT: {
>> +                        return ((Version) value1).compareTo(converted)>
>>  0;
>> +                    }
>> +                    case LT: {
>> +                        return ((Version) value1).compareTo(converted)<
>>  0;
>> +                    }
>>                  }
>>              } else {
>>                  return compare_Comparable(operation, (Version) value1,
>> value2);
>> @@ -808,12 +834,18 @@ public class FilterImpl implements Filte
>>
>>                  return string.equalsIgnoreCase(string2);
>>              }
>> -            case GREATER : {
>> +            case GTEQ: {
>>                  return string.compareTo((String) value2)>= 0;
>>              }
>> -            case LESS : {
>> +            case LTEQ: {
>>                  return string.compareTo((String) value2)<= 0;
>>              }
>> +            case GT: {
>> +                return string.compareTo((String) value2)>  0;
>> +            }
>> +            case LT: {
>> +                return string.compareTo((String) value2)<  0;
>> +            }
>>          }
>>          return false;
>>      }
>> @@ -834,12 +866,18 @@ public class FilterImpl implements Filte
>>              case EQUAL : {
>>                  return intval == intval2;
>>              }
>> -            case GREATER : {
>> +            case GTEQ: {
>>                  return intval>= intval2;
>>              }
>> -            case LESS : {
>> +            case LTEQ: {
>>                  return intval<= intval2;
>>              }
>> +            case GT: {
>> +                return intval>  intval2;
>> +            }
>> +            case LT: {
>> +                return intval<  intval2;
>> +            }
>>          }
>>          return false;
>>      }
>> @@ -861,12 +899,18 @@ public class FilterImpl implements Filte
>>              case EQUAL : {
>>                  return longval == longval2;
>>              }
>> -            case GREATER : {
>> +            case GTEQ: {
>>                  return longval>= longval2;
>>              }
>> -            case LESS : {
>> +            case LTEQ: {
>>                  return longval<= longval2;
>>              }
>> +            case GT: {
>> +                return longval>  longval2;
>> +            }
>> +            case LT: {
>> +                return longval<  longval2;
>> +            }
>>          }
>>          return false;
>>      }
>> @@ -888,12 +932,18 @@ public class FilterImpl implements Filte
>>              case EQUAL : {
>>                  return byteval == byteval2;
>>              }
>> -            case GREATER : {
>> +            case GTEQ: {
>>                  return byteval>= byteval2;
>>              }
>> -            case LESS : {
>> +            case LTEQ: {
>>                  return byteval<= byteval2;
>>              }
>> +            case GT: {
>> +                return byteval>  byteval2;
>> +            }
>> +            case LT: {
>> +                return byteval<  byteval2;
>> +            }
>>          }
>>          return false;
>>      }
>> @@ -916,12 +966,18 @@ public class FilterImpl implements Filte
>>              case EQUAL : {
>>                  return shortval == shortval2;
>>              }
>> -            case GREATER : {
>> +            case GTEQ: {
>>                  return shortval>= shortval2;
>>              }
>> -            case LESS : {
>> +            case LTEQ: {
>>                  return shortval<= shortval2;
>>              }
>> +            case GT: {
>> +                return shortval>  shortval2;
>> +            }
>> +            case LT: {
>> +                return shortval<  shortval2;
>> +            }
>>          }
>>          return false;
>>      }
>> @@ -950,12 +1006,18 @@ public class FilterImpl implements Filte
>>                          || (Character.toLowerCase(charval) == Character
>>                                  .toLowerCase(charval2));
>>              }
>> -            case GREATER : {
>> +            case GTEQ: {
>>                  return charval>= charval2;
>>              }
>> -            case LESS : {
>> +            case LTEQ: {
>>                  return charval<= charval2;
>>              }
>> +            case GT: {
>> +                return charval>  charval2;
>> +            }
>> +            case LT: {
>> +                return charval<  charval2;
>> +            }
>>          }
>>          return false;
>>      }
>> @@ -970,8 +1032,8 @@ public class FilterImpl implements Filte
>>          switch (operation) {
>>              case APPROX :
>>              case EQUAL :
>> -            case GREATER :
>> -            case LESS : {
>> +            case GTEQ:
>> +            case LTEQ: {
>>                  return boolval == boolval2;
>>              }
>>          }
>> @@ -996,12 +1058,18 @@ public class FilterImpl implements Filte
>>              case EQUAL : {
>>                  return Float.compare(floatval, floatval2) == 0;
>>              }
>> -            case GREATER : {
>> +            case GTEQ: {
>>                  return Float.compare(floatval, floatval2)>= 0;
>>              }
>> -            case LESS : {
>> +            case LTEQ: {
>>                  return Float.compare(floatval, floatval2)<= 0;
>>              }
>> +            case GT: {
>> +                return Float.compare(floatval, floatval2)>  0;
>> +            }
>> +            case LT: {
>> +                return Float.compare(floatval, floatval2)<  0;
>> +            }
>>          }
>>          return false;
>>      }
>> @@ -1024,12 +1092,18 @@ public class FilterImpl implements Filte
>>              case EQUAL : {
>>                  return Double.compare(doubleval, doubleval2) == 0;
>>              }
>> -            case GREATER : {
>> +            case GTEQ: {
>>                  return Double.compare(doubleval, doubleval2)>= 0;
>>              }
>> -            case LESS : {
>> +            case LTEQ: {
>>                  return Double.compare(doubleval, doubleval2)<= 0;
>>              }
>> +            case GT: {
>> +                return Double.compare(doubleval, doubleval2)>  0;
>> +            }
>> +            case LT: {
>> +                return Double.compare(doubleval, doubleval2)<  0;
>> +            }
>>          }
>>          return false;
>>      }
>> @@ -1070,12 +1144,18 @@ public class FilterImpl implements Filte
>>              case EQUAL : {
>>                  return value1.compareTo(value2) == 0;
>>              }
>> -            case GREATER : {
>> +            case GTEQ: {
>>                  return value1.compareTo(value2)>= 0;
>>              }
>> -            case LESS : {
>> +            case LTEQ: {
>>                  return value1.compareTo(value2)<= 0;
>>              }
>> +            case GT: {
>> +                return value1.compareTo(value2)>  0;
>> +            }
>> +            case LT: {
>> +                return value1.compareTo(value2)<  0;
>> +            }
>>          }
>>          return false;
>>      }
>> @@ -1112,8 +1192,8 @@ public class FilterImpl implements Filte
>>          switch (operation) {
>>              case APPROX :
>>              case EQUAL :
>> -            case GREATER :
>> -            case LESS : {
>> +            case GTEQ:
>> +            case LTEQ: {
>>                  return value1.equals(value2);
>>              }
>>          }
>> @@ -1312,23 +1392,29 @@ public class FilterImpl implements Filte
>>                  case '>' : {
>>                      if (filterChars[pos + 1] == '=') {
>>                          pos += 2;
>> -                        return new FilterImpl(FilterImpl.GREATER, attr,
>> +                        return new FilterImpl(FilterImpl.GTEQ, attr,
>> +                                parse_value());
>> +                    }
>> +                    else {
>> +                        pos += 1;
>> +                        return new FilterImpl(FilterImpl.GT, attr,
>>                                  parse_value());
>>                      }
>> -                    break;
>>                  }
>>                  case '<' : {
>>                      if (filterChars[pos + 1] == '=') {
>>                          pos += 2;
>> -                        return new FilterImpl(FilterImpl.LESS, attr,
>> +                        return new FilterImpl(FilterImpl.LTEQ, attr,
>>                                  parse_value());
>> -                    }
>> -                    if (filterChars[pos + 1] == '*') {
>> +                    } else if (filterChars[pos + 1] == '*') {
>>                          pos += 2;
>>                          return new FilterImpl(FilterImpl.SUBSET, attr,
>>                                  parse_value());
>> +                    } else {
>> +                        pos += 1;
>> +                        return new FilterImpl(FilterImpl.LT, attr,
>> +                                parse_value());
>>                      }
>> -                    break;
>>                  }
>>                  case '=' : {
>>                      if (filterChars[pos + 1] == '*') {
>>
>>
>>
>>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message