Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.osgi.framework.VersionRange;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -569,8 +570,12 @@ private static int skipWhitespace(String s, int startIdx)
* over the map's entry set. If ordering of attributes is important (e.g.,
* for hitting attribute indices), then the map's entry set should iterate
* in the desired order. Equality testing is assumed for all attribute types
* other than version ranges, which are handled appropriated. If the attribute
* map is empty, then a filter that matches anything is returned.
* other than version ranges and collections, which are handled appropriated.
* A collection, such as a {@code List} typed attribute, becomes one equality
* test per element, so it matches a capability attribute that contains all
* of the elements; the OSGi specification does not define list matching for
* these headers. An empty collection only tests that the attribute is present.
* If the attribute map is empty, then a filter that matches anything is returned.
* @param attrs Map of attributes to convert to a filter.
* @return A filter corresponding to the attributes.
*/
Expand Down Expand Up @@ -629,26 +634,24 @@ public static SimpleFilter convert(Map<String, Object> attrs)
}
}
}
else
else if (entry.getValue() instanceof Collection)
{
List<String> values = SimpleFilter.parseSubstring(entry.getValue().toString());
if (values.size() > 1)
// A list attribute matches if it contains all of the values,
// an empty list still requires the attribute to be present.
Collection<?> values = (Collection<?>) entry.getValue();
if (values.isEmpty())
{
filters.add(
new SimpleFilter(
entry.getKey(),
values,
SimpleFilter.SUBSTRING));
filters.add(new SimpleFilter(entry.getKey(), "*", SimpleFilter.PRESENT));
}
else
for (Object value : values)
{
filters.add(
new SimpleFilter(
entry.getKey(),
values.get(0),
SimpleFilter.EQ));
filters.add(convertValue(entry.getKey(), value));
}
}
else
{
filters.add(convertValue(entry.getKey(), entry.getValue()));
}
}

SimpleFilter sf = null;
Expand All @@ -657,7 +660,7 @@ public static SimpleFilter convert(Map<String, Object> attrs)
{
sf = filters.get(0);
}
else if (attrs.size() > 1)
else if (filters.size() > 1)
{
sf = new SimpleFilter(null, filters, SimpleFilter.AND);
}
Expand All @@ -668,4 +671,14 @@ else if (filters.isEmpty())

return sf;
}

private static SimpleFilter convertValue(String name, Object value)
{
List<String> values = SimpleFilter.parseSubstring(value.toString());
if (values.size() > 1)
{
return new SimpleFilter(name, values, SimpleFilter.SUBSTRING);
}
return new SimpleFilter(name, values.get(0), SimpleFilter.EQ);
}
}
Loading
Loading