Package org.ldaptive.dn
Class Dn
- java.lang.Object
-
- org.ldaptive.AbstractFreezable
-
- org.ldaptive.dn.Dn
-
- All Implemented Interfaces:
Freezable
public final class Dn extends AbstractFreezable
Distinguished name containing zero or more relative distinguished names. RDNs are ordered from left to right such that the left-most RDN is considered the first. For the DN 'cn=Jane Doe,ou=People,dc=ldaptive,dc=org', the first RDN is 'cn=Jane Doe'. See RFC 4514 for more details on the string representations of DNs.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDn.Builder
-
Field Summary
Fields Modifier and Type Field Description private static intHASH_CODE_SEEDhash code seed.private List<RDn>rdnComponentsRDN components.
-
Constructor Summary
Constructors Constructor Description Dn()Default constructor.Dn(String dn)Creates a new DN with the supplied string.Dn(String dn, DnParser parser)Creates a new DN with the supplied string.Dn(List<RDn> rdns)Creates a new DN with the supplied RDNs.Dn(RDn... rdn)Creates a new DN with the supplied RDNs.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, RDn rdn)Adds the supplied RDN at the supplied index.voidadd(Dn dn)Adds all the RDNs in the supplied DN to the end of this DN.voidadd(RDn rdn)Adds the supplied RDN to the end of this DN.static Dn.Builderbuilder()Creates a builder for this class.static Dncopy(Dn dn)Creates a mutable copy of the supplied DN.booleanequals(Object o)Stringformat()Produces a string representation of this DN.Stringformat(RDnNormalizer normalizer)Produces a string representation of this DN.Stringformat(RDnNormalizer normalizer, char delimiter, boolean reverse)Produces a string representation of this DN.Collection<String>getNames()Returns all the RDN names.DngetParent()Convenience method to retrieve the parent DN.RDngetRDn()Returns the first RDN in this DN.List<RDn>getRDns()Returns the RDNs in this DN.StringgetValue(String name)Returns the first RDN value with the supplied name.Collection<String>getValues(String name)Returns the RDN values with the supplied name.inthashCode()booleanisAncestor(Dn dn)Returns whether the supplied DN is an ancestor.booleanisAncestor(Dn dn, RDnNormalizer normalizer)Returns whether the supplied DN is an ancestor.booleanisDescendant(Dn dn)Returns whether the supplied DN is a descendant.booleanisDescendant(Dn dn, RDnNormalizer normalizer)Returns whether the supplied DN is a descendant.booleanisEmpty()Returns whether this DN contains any RDN components.booleanisSame(Dn dn)Returns whether the normalized format of the supplied DN equals the normalized format of this DN.booleanisSame(Dn dn, RDnNormalizer normalizer)Returns whether the normalized format of the supplied DN equals the normalized format of this DN.intsize()Returns the number of RDNs in this DN.DnsubDn(int index)Returns a new DN containing all the RDN components from the supplied index.DnsubDn(int beginIndex, int endIndex)Returns a new DN containing all the RDN components between the supplied indexes.StringtoString()-
Methods inherited from class org.ldaptive.AbstractFreezable
assertMutable, freeze, freeze, freeze, isFrozen
-
-
-
-
Field Detail
-
HASH_CODE_SEED
private static final int HASH_CODE_SEED
hash code seed.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Dn
public Dn()
Default constructor.
-
Dn
public Dn(String dn)
Creates a new DN with the supplied string. Uses aDefaultDnParserby default.- Parameters:
dn- to parse
-
Dn
public Dn(String dn, DnParser parser)
Creates a new DN with the supplied string.- Parameters:
dn- to parseparser- to parse dn
-
Dn
public Dn(RDn... rdn)
Creates a new DN with the supplied RDNs.- Parameters:
rdn- to add
-
-
Method Detail
-
getRDn
public RDn getRDn()
Returns the first RDN in this DN.- Returns:
- first RDN
-
add
public void add(Dn dn)
Adds all the RDNs in the supplied DN to the end of this DN.- Parameters:
dn- to add to this DN
-
add
public void add(RDn rdn)
Adds the supplied RDN to the end of this DN.- Parameters:
rdn- to add to this DN
-
add
public void add(int index, RDn rdn)Adds the supplied RDN at the supplied index.- Parameters:
index- to add the RDN atrdn- to add to this DN
-
subDn
public Dn subDn(int index)
Returns a new DN containing all the RDN components from the supplied index.- Parameters:
index- of RDNs to include- Returns:
- DN with sub-components of this DN
-
subDn
public Dn subDn(int beginIndex, int endIndex)
Returns a new DN containing all the RDN components between the supplied indexes.- Parameters:
beginIndex- first RDN to include (inclusive)endIndex- last RDN to include (exclusive)- Returns:
- DN with sub-components of this DN or null if beginIndex > endIndex
-
getParent
public Dn getParent()
Convenience method to retrieve the parent DN. InvokessubDn(int)with a parameter of 1.- Returns:
- DN containing all sub-components of this DN except the first or null if this DN has no components
-
getNames
public Collection<String> getNames()
Returns all the RDN names.- Returns:
- all RDN names
-
getValues
public Collection<String> getValues(String name)
Returns the RDN values with the supplied name. If the RDN is multi-value the first value is used.- Parameters:
name- of the RDN- Returns:
- RDN values for the supplied name
-
getValue
public String getValue(String name)
Returns the first RDN value with the supplied name. If the RDN is multi-value the first value is used.- Parameters:
name- of the RDN- Returns:
- RDN value
-
size
public int size()
Returns the number of RDNs in this DN.- Returns:
- number of RDNs
-
isEmpty
public boolean isEmpty()
Returns whether this DN contains any RDN components.- Returns:
- whether this DN contains any RDN components
-
isSame
public boolean isSame(Dn dn)
Returns whether the normalized format of the supplied DN equals the normalized format of this DN. SeeDefaultRDnNormalizer.- Parameters:
dn- to compare- Returns:
- whether the supplied DN is the same as this DN
-
isSame
public boolean isSame(Dn dn, RDnNormalizer normalizer)
Returns whether the normalized format of the supplied DN equals the normalized format of this DN.- Parameters:
normalizer- to use for comparisondn- to compare- Returns:
- whether the supplied DN is the same as this DN
-
isAncestor
public boolean isAncestor(Dn dn)
Returns whether the supplied DN is an ancestor. SeeisSame(Dn).- Parameters:
dn- to determine ancestry of- Returns:
- whether the supplied DN is an ancestor
-
isAncestor
public boolean isAncestor(Dn dn, RDnNormalizer normalizer)
Returns whether the supplied DN is an ancestor. SeeisSame(Dn, RDnNormalizer).- Parameters:
dn- to determine ancestry ofnormalizer- to format DN for comparison- Returns:
- whether the supplied DN is an ancestor
-
isDescendant
public boolean isDescendant(Dn dn)
Returns whether the supplied DN is a descendant. SeeisSame(Dn).- Parameters:
dn- to determine descendancy of- Returns:
- whether the supplied DN is a descendant
-
isDescendant
public boolean isDescendant(Dn dn, RDnNormalizer normalizer)
Returns whether the supplied DN is a descendant. SeeisSame(Dn, RDnNormalizer).- Parameters:
dn- to determine descendancy ofnormalizer- to format DN for comparison- Returns:
- whether the supplied DN is a descendant
-
format
public String format()
Produces a string representation of this DN. Uses aDefaultRDnNormalizerby default.- Returns:
- DN string
-
format
public String format(RDnNormalizer normalizer)
Produces a string representation of this DN.- Parameters:
normalizer- to apply to the RDN components or null for no formatting- Returns:
- DN string
-
format
public String format(RDnNormalizer normalizer, char delimiter, boolean reverse)
Produces a string representation of this DN.- Parameters:
normalizer- to apply to the RDN components or null for no formattingdelimiter- to separate each RDN componentreverse- whether to reverse the order of RDN components for formatting. i.e. process components from right to left- Returns:
- DN string
-
copy
public static Dn copy(Dn dn)
Creates a mutable copy of the supplied DN.- Parameters:
dn- to copy- Returns:
- new DN instance
-
builder
public static Dn.Builder builder()
Creates a builder for this class.- Returns:
- new builder
-
-