Skip to content

Commit

Permalink
Fix the TypeSafeResolver so that the equals implementation for Key wo…
Browse files Browse the repository at this point in the history
…rks correctly. Any Resolvable implementation must now implement their own equals and hashCode.
  • Loading branch information
mbogoevici committed Jun 10, 2010
1 parent 9fe42e1 commit 3ed176d
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 8 deletions.
Expand Up @@ -75,4 +75,13 @@ public boolean isAssignableTo(Class<?> clazz)
return false;
}

public int getHashCode()
{
return hashCode();
}

public boolean isEqualTo(Resolvable r)
{
return equals(r);
}
}
Expand Up @@ -80,4 +80,13 @@ public String toString()
return delegate().toString();
}

public int getHashCode()
{
return delegate().getHashCode();
}

public boolean isEqualTo(Resolvable r)
{
return delegate().isEqualTo(r);
}
}
Expand Up @@ -135,6 +135,18 @@ public InterceptionType getInterceptionType()
return interceptionType;
}

public int getHashCode()
{
return 31*super.getHashCode()
+ this.getInterceptionType().hashCode();
}

public boolean isEqualTo(Resolvable r)
{
return super.isEqualTo(r)
&& r instanceof InterceptorResolvable
&& this.getInterceptionType().equals(((InterceptorResolvable)r).getInterceptionType());
}
}

}
14 changes: 14 additions & 0 deletions impl/src/main/java/org/jboss/weld/resolution/Resolvable.java
Expand Up @@ -87,4 +87,18 @@ public interface Resolvable
*/
public Bean<?> getDeclaringBean();

/**
* Force the Resolvable to implement its own comparison strategy
* (thus subclasses can be compared differently)
* @param r
* @return
*/
public boolean isEqualTo(Resolvable r);

/**
* Force the Resolvable to implement
* @return
*/
public int getHashCode();

}
Expand Up @@ -276,6 +276,20 @@ public String toString()
return "Types: " + getTypes() + "; Bindings: " + getQualifiers();
}

public int getHashCode()
{
int result = 17;
result = 31 * result + this.getTypes().hashCode();
result = 31 * result + this.getQualifiers().hashCode();
return result;
}

public boolean isEqualTo(Resolvable r)
{
return this.getTypes().equals(r.getTypes())
&& this.getQualifiers().equals(r.getQualifiers());

}
}

}
Expand Up @@ -51,10 +51,11 @@ public R getResolvable()
@Override
public boolean equals(Object obj)
{
if (obj instanceof Resolvable)
if (obj instanceof Key)
{
Resolvable that = (Resolvable) obj;
return this.getResolvable().getTypes().equals(that.getTypes()) && this.getResolvable().getQualifiers().equals(that.getQualifiers());
Key that = (Key) obj;
return that.getResolvable().getClass().equals(this.getResolvable().getClass())
&& that.getResolvable().isEqualTo(that.getResolvable());
}
else
{
Expand All @@ -65,10 +66,7 @@ public boolean equals(Object obj)
@Override
public int hashCode()
{
int result = 17;
result = 31 * result + this.getResolvable().getTypes().hashCode();
result = 31 * result + this.getResolvable().getQualifiers().hashCode();
return result;
return this.getResolvable().hashCode();
}

@Override
Expand Down
Expand Up @@ -41,7 +41,7 @@ public class EnterpriseBeanInterceptionTest extends AbstractWeldTest
{

@Test(groups = { "interceptors", "incontainer-broken"})
public void ls() throws Exception
public void testInterceptors() throws Exception
{
SessionBean<Ball> ballSessionBean = (SessionBean<Ball>)getCurrentManager().getBeans(Ball.class).iterator().next();
InterceptorBindings interceptorBindings = new InterceptorBindingsAdapter(getCurrentManager().getCdiInterceptorsRegistry().getInterceptionModel(ballSessionBean.getType()));
Expand Down

0 comments on commit 3ed176d

Please sign in to comment.