Search in sources :

Example 1 with NotFilter

use of aQute.libg.filters.NotFilter in project bndtools by bndtools.

the class BndBuilderCapReqLoader method createVersionFilter.

private static final String createVersionFilter(String ns, String value, String rangeStr, String versionAttr) {
    SimpleFilter pkgNameFilter = new SimpleFilter(ns, value);
    Filter filter = pkgNameFilter;
    if (rangeStr != null) {
        VersionRange range = new VersionRange(rangeStr);
        Filter left;
        if (range.includeLow())
            left = new SimpleFilter(versionAttr, Operator.GreaterThanOrEqual, range.getLow().toString());
        else
            left = new NotFilter(new SimpleFilter(versionAttr, Operator.LessThanOrEqual, range.getLow().toString()));
        Filter right;
        if (!range.isRange())
            right = null;
        else if (range.includeHigh())
            right = new SimpleFilter(versionAttr, Operator.LessThanOrEqual, range.getHigh().toString());
        else
            right = new NotFilter(new SimpleFilter(versionAttr, Operator.GreaterThanOrEqual, range.getHigh().toString()));
        AndFilter combined = new AndFilter().addChild(pkgNameFilter).addChild(left);
        if (right != null)
            combined.addChild(right);
        filter = combined;
    }
    return filter.toString();
}
Also used : AndFilter(aQute.libg.filters.AndFilter) SimpleFilter(aQute.libg.filters.SimpleFilter) NotFilter(aQute.libg.filters.NotFilter) AndFilter(aQute.libg.filters.AndFilter) Filter(aQute.libg.filters.Filter) SimpleFilter(aQute.libg.filters.SimpleFilter) NotFilter(aQute.libg.filters.NotFilter) VersionRange(aQute.bnd.version.VersionRange)

Example 2 with NotFilter

use of aQute.libg.filters.NotFilter in project bnd by bndtools.

the class Filters method fromVersionRange.

/**
	 * Generate an LDAP-style version filter from a version range, using a
	 * specific attribute name for the version; for example can be used to
	 * generate a range using the {@code bundle-version} attribute such as
	 * {@code (&(bundle-version>=1.0)(!(bundle-version>=2.0))}.
	 * 
	 * @param range
	 * @param versionAttr
	 * @return The generated filter
	 * @throws IllegalArgumentException If the supplied range is invalid.
	 */
public static String fromVersionRange(String range, String versionAttr) throws IllegalArgumentException {
    if (range == null)
        return null;
    VersionRange parsedRange = new VersionRange(range);
    Filter left;
    if (parsedRange.includeLow())
        left = new SimpleFilter(versionAttr, Operator.GreaterThanOrEqual, parsedRange.getLow().toString());
    else
        left = new NotFilter(new SimpleFilter(versionAttr, Operator.LessThanOrEqual, parsedRange.getLow().toString()));
    Filter right;
    if (!parsedRange.isRange())
        right = null;
    else if (parsedRange.includeHigh())
        right = new SimpleFilter(versionAttr, Operator.LessThanOrEqual, parsedRange.getHigh().toString());
    else
        right = new NotFilter(new SimpleFilter(versionAttr, Operator.GreaterThanOrEqual, parsedRange.getHigh().toString()));
    Filter result;
    if (right != null)
        result = new AndFilter().addChild(left).addChild(right);
    else
        result = left;
    return result.toString();
}
Also used : AndFilter(aQute.libg.filters.AndFilter) Filter(aQute.libg.filters.Filter) SimpleFilter(aQute.libg.filters.SimpleFilter) NotFilter(aQute.libg.filters.NotFilter) AndFilter(aQute.libg.filters.AndFilter) SimpleFilter(aQute.libg.filters.SimpleFilter) NotFilter(aQute.libg.filters.NotFilter) VersionRange(aQute.bnd.version.VersionRange)

Aggregations

VersionRange (aQute.bnd.version.VersionRange)2 AndFilter (aQute.libg.filters.AndFilter)2 Filter (aQute.libg.filters.Filter)2 NotFilter (aQute.libg.filters.NotFilter)2 SimpleFilter (aQute.libg.filters.SimpleFilter)2