ObjectNameKey.java

  1. package org.exoplatform.forum.service.cache.model.key;

  2. import org.exoplatform.forum.common.cache.model.ScopeCacheKey;
  3. import org.exoplatform.forum.service.Utils;

  4. public class ObjectNameKey extends ScopeCacheKey {

  5.   private final String path;
  6.   private final String id;
  7.   private final String type;

  8.   public ObjectNameKey(String path) {
  9.     if (!Utils.isEmpty(path) && path.indexOf(Utils.CATEGORY) > 0) {
  10.       path = path.substring(path.indexOf(Utils.CATEGORY));
  11.     }
  12.     this.path = path;
  13.     this.id = null;
  14.     this.type = null;
  15.   }

  16.   public ObjectNameKey(String id, String type) {
  17.     this.path = null;
  18.     this.id = id;
  19.     this.type = type;
  20.   }

  21.   @Override
  22.   public boolean equals(Object o) {
  23.     if (this == o) return true;
  24.     if (!(o instanceof ObjectNameKey)) return false;
  25.     if (!super.equals(o)) return false;

  26.     ObjectNameKey that = (ObjectNameKey) o;

  27.     if (id != null ? !id.equals(that.id) : that.id != null) return false;
  28.     if (path != null ? !path.equals(that.path) : that.path != null) return false;
  29.     if (type != null ? !type.equals(that.type) : that.type != null) return false;

  30.     return true;
  31.   }

  32.   @Override
  33.   public int hashCode() {
  34.     int result = super.hashCode();
  35.     result = 31 * result + (path != null ? path.hashCode() : 0);
  36.     result = 31 * result + (id != null ? id.hashCode() : 0);
  37.     result = 31 * result + (type != null ? type.hashCode() : 0);
  38.     return result;
  39.   }

  40. }