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.util.Iterator; 025 026/** 027 * Abstract <code>Location</code> decorator (wrapper). 028 * 029 * <p> 030 * These wrap up a normal <code>Location</code> object, and act as markers to indicate that 031 * the location has some kind of special semantics. 032 * </p> 033 * 034 * When implementing a new Location decorator. 035 * @author Matthew Pocock 036 */ 037public abstract class AbstractLocationDecorator implements Location { 038 private final Location wrapped; 039 040 /** 041 * Construct a new decorator wrapping the specified Location. 042 */ 043 044 protected AbstractLocationDecorator(Location wrapped) { 045 this.wrapped = wrapped; 046 } 047 048 protected final Location getWrapped() { 049 return wrapped; 050 } 051 052 protected abstract Location decorate(Location loc); 053 054 public Location newInstance(Location loc) { 055 if(loc instanceof AbstractLocationDecorator) { 056 Location wrapped = ((AbstractLocationDecorator) loc).getWrapped(); 057 loc = wrapped.newInstance(wrapped); 058 } 059 return decorate(loc); 060 } 061 062 public Location getDecorator(Class decoratorClass) { 063 if(decoratorClass.isInstance(this)) { 064 return this; 065 } else { 066 return getWrapped().getDecorator(decoratorClass); 067 } 068 } 069 070 public int getMin() { 071 return getWrapped().getMin(); 072 } 073 074 public int getMax() { 075 return getWrapped().getMax(); 076 } 077 078 public boolean overlaps(Location l) { 079 return getWrapped().overlaps(l); 080 } 081 082 public boolean contains(Location l) { 083 return getWrapped().contains(l); 084 } 085 086 public boolean contains(int p) { 087 return getWrapped().contains(p); 088 } 089 090 public boolean equals(Object o) { 091 return getWrapped().equals(o); 092 } 093 094 public Location intersection(Location l) { 095 return getWrapped().intersection(l); 096 } 097 098 public Location union(Location l) { 099 return getWrapped().union(l); 100 } 101 102 public SymbolList symbols(SymbolList seq) { 103 return getWrapped().symbols(seq); 104 } 105 106 public Location translate(int dist) { 107 return decorate(getWrapped().translate(dist)); 108 } 109 110 public boolean isContiguous() { 111 return getWrapped().isContiguous(); 112 } 113 114 public Iterator blockIterator() { 115 return getWrapped().blockIterator(); 116 } 117}