You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-users@jakarta.apache.org by John McNally <jm...@collab.net> on 2005/08/31 20:42:19 UTC

Re: Cache Keys

Think you're missing a !

  public boolean equals(Object o)
  {
    if (o instanceof Key)
    {
      return false;
    }



Tim Cronin wrote:

>I'm using and object as the cache key is there something special I have
>to do?
>
>Here is my key class
>
>public class Key implements Serializable
>{
>  /**
>   * the site
>   */
>  private String mSite = null;
>
>  /**
>   * the page
>   */
>  private String mPage = null;
>
>  /**
>   * the locale
>   */
>  private String mLocale = null;
>
>  /**
>   * the component ID
>   */
>  private String mComponent = null;
>
> 
>/***********************************************************************
>******
>   * create new Key (used for purge)
>   *
>   * @param site the site
> 
>************************************************************************
>*****/
>  public Key(String site)
>  {
>    mSite = site;
>  }
>
> 
>/***********************************************************************
>******
>   * create new Key (used for purge)
>   *
>   * @param site the site
>   * @param page the page
> 
>************************************************************************
>*****/
>  public Key(String site, String page)
>  {
>    mSite = site;
>    mPage = page;
>  }
>
> 
>/***********************************************************************
>******
>   * create new Key (for page)
>   *
>   * @param site the site
>   * @param page the page
>   * @param locale the locale
> 
>************************************************************************
>*****/
>  public Key(String site, String page, String locale)
>  {
>    mLocale = locale;
>    mPage = page;
>    mSite = site;
>  }
>
> 
>/***********************************************************************
>******
>   * create new Key (for component key)
>   *
>   * @param k the key (for the page)
>   * @param component the component
> 
>************************************************************************
>*****/
>  public Key(Key k, String component)
>  {
>    mSite = k.mSite;
>    mPage = k.mPage;
>    mLocale = k.mLocale;
>    mComponent = component;
>  }
>
> 
>/***********************************************************************
>******
>   * Gets The component.
>   *
>   * @return Returns the component.
> 
>************************************************************************
>*****/
>  public String getComponent()
>  {
>    return mComponent;
>  }
>
> 
>/***********************************************************************
>******
>   * Gets The locale.
>   *
>   * @return Returns the locale.
> 
>************************************************************************
>*****/
>  public String getLocale()
>  {
>    return mLocale;
>  }
>
> 
>/***********************************************************************
>******
>   * Gets The page.
>   *
>   * @return Returns the page.
> 
>************************************************************************
>*****/
>  public String getPage()
>  {
>    return mPage;
>  }
>
> 
>/***********************************************************************
>******
>   * Gets The site.
>   *
>   * @return Returns the site.
> 
>************************************************************************
>*****/
>  public String getSite()
>  {
>    return mSite;
>  }
>
> 
>/***********************************************************************
>******
>   * get the xpath logic to use to filter cache options
>   *
>   * @return the xpath logic string
> 
>************************************************************************
>*****/
>  public String getXPath()
>  {
>    StringBuffer buff = new StringBuffer();
>
> 
>buff.append("[@site='").append(StringEscapeUtils.escapeJava(mSite)).appe
>nd("'");
>
>    if (mPage != null)
>    {
>      buff.append(" and
>@page='").append(StringEscapeUtils.escapeJava(mPage)).append("'");
>    }
>
>    buff.append("]");
>
>    return buff.toString();
>  }
> 
>/***********************************************************************
>******
>   * @see java.lang.Object#equals(java.lang.Object)
> 
>************************************************************************
>*****/
>  public boolean equals(Object o)
>  {
>    if (o instanceof Key)
>    {
>      return false;
>    }
>    if (this == o)
>    {
>      return true;
>    }
>    Key that = (Key) o;
>    return new EqualsBuilder()
>      .append(mSite, that.mSite)
>      .append(mPage, that.mPage)
>      .append(mLocale, that.mLocale)
>      .append(mComponent, that.mComponent)
>      .isEquals();
>  }
>
> 
>/***********************************************************************
>******
>   * @see java.lang.Object#hashCode()
> 
>************************************************************************
>*****/
>  public int hashCode()
>  {
>    return new HashCodeBuilder()
>      .append(mSite)
>      .append(mPage)
>      .append(mLocale)
>      .append(mComponent)
>      .toHashCode();
>  }
>
> 
>/***********************************************************************
>******
>   * @see java.lang.Object#toString()
> 
>************************************************************************
>*****/
>  public String toString()
>  {
>    return new ToStringBuilder(this)
>      .append("mSite", mSite)
>      .append("mPage", mPage)
>      .append("mLocale", mLocale)
>      .append("mComponent", mComponent)
>      .toString();
>  }
>}
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: jcs-users-help@jakarta.apache.org
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org