Add utility to the distinguished name interface.
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 27 Oct 2019 11:05:05 +0000 (12:05 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 27 Oct 2019 11:05:05 +0000 (12:05 +0100)
org.argeo.enterprise/src/org/argeo/naming/Distinguished.java

index ba0db49552c7001a0ec058ff039d9cbfc2daef3e..8b9c4b92b2014c57bc3ae4a44e88f6d3b00ec1e4 100644 (file)
@@ -1,5 +1,9 @@
 package org.argeo.naming;
 
+import java.util.EnumSet;
+import java.util.Set;
+import java.util.TreeSet;
+
 import javax.naming.InvalidNameException;
 import javax.naming.ldap.LdapName;
 
@@ -20,4 +24,13 @@ public interface Distinguished {
                        throw new IllegalArgumentException("Distinguished name " + dn() + " is not properly formatted.", e);
                }
        }
+
+       /** List all DNs of an enumeration as strings. */
+       static Set<String> enumToDns(EnumSet<? extends Distinguished> enumSet) {
+               Set<String> res = new TreeSet<>();
+               for (Enum<? extends Distinguished> enm : enumSet) {
+                       res.add(((Distinguished) enm).dn());
+               }
+               return res;
+       }
 }