Here you can find the source of generatePropertiesFilter(SortedMap
Parameter | Description |
---|---|
propertiesMap | Map of properties |
public static String generatePropertiesFilter(SortedMap<String, String> propertiesMap)
//package com.java2s; import java.util.SortedMap; public class Main { /**//from w w w .ja v a 2 s .c o m * Generate a Filter as a String given a Map of property/value pairs. * (& (prop1=value1) (& (prop2=value1))) * * @param propertiesMap Map of properties * @return Filter as a String */ public static String generatePropertiesFilter(SortedMap<String, String> propertiesMap) { if (propertiesMap.size() == 1) { return "(" + propertiesMap.firstKey() + "=" + propertiesMap.get(propertiesMap.firstKey()) + ")"; } else if (propertiesMap.size() > 1) { return "(&" + generatePropertiesFilter( propertiesMap.subMap(propertiesMap.firstKey(), propertiesMap.firstKey() + "\0")) + generatePropertiesFilter(propertiesMap.tailMap(propertiesMap.firstKey() + "\0")) + ")"; } return ""; } }