Mention.java

  1. /*
  2.  *  Mention.java
  3.  *
  4.  *  Copyright (c) 2007-2011, The University of Sheffield.
  5.  *
  6.  *  This file is part of GATE Mímir (see http://gate.ac.uk/family/mimir.html),
  7.  *  and is free software, licenced under the GNU Lesser General Public License,
  8.  *  Version 3, June 2007 (also included with this distribution as file
  9.  *  LICENCE-LGPL3.html).
  10.  *
  11.  *  Valentin Tablan, 19 Feb 2009
  12.  *
  13.  *  $Id: Mention.java 14541 2011-11-14 19:31:23Z ian_roberts $
  14.  */
  15. package gate.mimir.index;

  16. /**
  17.  * Simple holder class holding the URI and length of a mention.
  18.  */
  19. public class Mention {
  20.  
  21.   /**
  22.    * Special value used when the mention has no length information (e.g. if it
  23.    * refers to document metadata hit).
  24.    */
  25.   public static final int NO_LENGTH = -1;
  26.  
  27.   private int length;

  28.   private String uri;

  29.   public Mention(String uri, int length) {
  30.     this.uri = uri;
  31.     this.length = length;
  32.   }

  33.   @Override
  34.   public boolean equals(Object obj) {
  35.     if(this == obj) return true;
  36.     if(obj == null) return false;
  37.     Mention other = (Mention)obj;
  38.     if(length != other.length) return false;
  39.     if(uri == null) {
  40.       if(other.uri != null) return false;
  41.     } else if(!uri.equals(other.uri)) return false;
  42.     return true;
  43.   }

  44.   public int getLength() {
  45.     return length;
  46.   }

  47.   public String getUri() {
  48.     return uri;
  49.   }

  50.   @Override
  51.   public int hashCode() {
  52.     final int prime = 31;
  53.     int result = 1;
  54.     result = prime * result + length;
  55.     result = prime * result + ((uri == null) ? 0 : uri.hashCode());
  56.     return result;
  57.   }
  58. }