[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
hashCode question (was Re: Silly Java question)
From: |
Jeff Bailey |
Subject: |
hashCode question (was Re: Silly Java question) |
Date: |
Mon, 26 Dec 2005 17:22:07 -0500 |
Le lundi 26 décembre 2005 à 09:50 -0500, Brian Jones a écrit :
> > * From Section 7.2 of rfc1510: When comparing names, a name of type
> > * UNKNOWN will match principals authenticated with names of any type.
> > * A principal authenticated with a name of type UNKNOWN, however, will
> > * only match other names of type UNKNOWN.
> >
> >But how do I encode that logic into a hashCode?
> equals(Object o)
> {
> // just using UNKNOWN as a string below
> // casting/type check missing below to whatever type is necessary...
> if (o.getName().equals("UNKNOWN"))
> return true;
> else
> // compare hashcodes
> }
>
> It appears your principle hashcode should be based on the principle
> name, i.e. using hashcode from String.
>
> Anyone else feel free to correct me.
The guidelines I've seen say that if two items are equal, then their
hashcodes should match. If they are unequal, their hashcodes should not
match.
I have implemented the equals function like so:
public boolean equals(Object that)
{
if (that == this)
return true;
if (! (that instanceof KerberosPrincipal))
return false;
// The other type must be the same or UNKNOWN.
if (((KerberosPrincipal)that).getNameType() != nameType)
if (((KerberosPrincipal)that).getNameType() != KRB_NT_UNKNOWN)
return false;
// The toString output must match.
if (! toString().equals(((KerberosPrincipal)that).toString()))
return false;
// Fallthrough case, we must be the same.
return true;
}
But with a hashcode, I think I just have an int to compare, don't I? I
don't know how encode this type of logic into that.
Tks,
Jeff Bailey
- Silly Java question, Jeff Bailey, 2005/12/25
- Message not available
- hashCode question (was Re: Silly Java question),
Jeff Bailey <=
- Re: hashCode question (was Re: Silly Java question), Michael Barker, 2005/12/27
- Re: hashCode question (was Re: Silly Java question), Per Bothner, 2005/12/27
- Re: hashCode question (was Re: Silly Java question), Michael Barker, 2005/12/27
- Re: hashCode question (was Re: Silly Java question), Per Bothner, 2005/12/27
- Re: hashCode question (was Re: Silly Java question), Michael Barker, 2005/12/27
Re: Silly Java question, Roman Kennke, 2005/12/27