001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021 022package org.biojava.bio.symbol; 023 024import java.io.Serializable; 025 026/** 027 * An abstract implementation of <code>Location</code>. 028 * 029 * This provides implementations of the binary operators which delegate to 030 * the <code>LocationTools</code> class. 031 * @author Matthew Pocock 032 */ 033public abstract class AbstractLocation 034implements Location, Serializable { 035 public Location getDecorator(Class decoratorClass) { 036 if(decoratorClass.isInstance(this)) { 037 return this; 038 } else { 039 return null; 040 } 041 } 042 043 public Location newInstance(Location loc) { 044 return loc; 045 } 046 047 public boolean contains(Location l) { 048 return LocationTools.contains(this, l); 049 } 050 051 public boolean overlaps(Location l) { 052 return LocationTools.overlaps(this, l); 053 } 054 055 public Location union(Location loc) { 056 return LocationTools.union(this, loc); 057 } 058 059 public Location intersection(Location loc) { 060 return LocationTools.intersection(this, loc); 061 } 062 063 public boolean equals(Object o) { 064 if(!(o instanceof Location)) { 065 return false; 066 } else { 067 return LocationTools.areEqual(this, (Location) o); 068 } 069 } 070 071 public int hashCode() { 072 return getMin() ^ getMax(); 073 } 074}