001package com.hfg.bio.seq.format.feature; 002 003import com.hfg.exception.UnimplementedMethodException; 004import com.hfg.math.Range; 005import com.hfg.util.CompareUtil; 006 007 008//------------------------------------------------------------------------------ 009/** 010 A basic implementation of the SeqFeatureLocation interface. 011 <div> 012 @author J. Alex Taylor, hairyfatguy.com 013 </div> 014 */ 015//------------------------------------------------------------------------------ 016// com.hfg Library 017// 018// This library is free software; you can redistribute it and/or 019// modify it under the terms of the GNU Lesser General Public 020// License as published by the Free Software Foundation; either 021// version 2.1 of the License, or (at your option) any later version. 022// 023// This library is distributed in the hope that it will be useful, 024// but WITHOUT ANY WARRANTY; without even the implied warranty of 025// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 026// Lesser General Public License for more details. 027// 028// You should have received a copy of the GNU Lesser General Public 029// License along with this library; if not, write to the Free Software 030// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 031// 032// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 033// jataylor@hairyfatguy.com 034//------------------------------------------------------------------------------ 035 036public class BasicSeqFeatureLocation implements SeqFeatureLocation 037{ 038 private Range<Integer> mIntRange; 039 040 //########################################################################## 041 // CONSTRUCTORS 042 //########################################################################## 043 044 //-------------------------------------------------------------------------- 045 public BasicSeqFeatureLocation() 046 { 047 super(); 048 } 049 050 //-------------------------------------------------------------------------- 051 public BasicSeqFeatureLocation(int inStart, int inEnd) 052 { 053 mIntRange = new Range<Integer>(inStart, inEnd); 054 } 055 056 057 //########################################################################## 058 // PUBLIC METHODS 059 //########################################################################## 060 061 //-------------------------------------------------------------------------- 062 @Override 063 public void append(String inAdditionalLocationData) 064 { 065 throw new UnimplementedMethodException(); 066 } 067 068 //--------------------------------------------------------------------------- 069 @Override 070 public boolean equals(Object inObj2) 071 { 072 return (inObj2 != null 073 && inObj2 instanceof SeqFeatureLocation 074 && 0 == compareTo(inObj2)); 075 } 076 077 //--------------------------------------------------------------------------- 078 @Override 079 public int compareTo(Object inObj2) 080 { 081 int result = 1; 082 083 if (inObj2 != null 084 && inObj2 instanceof SeqFeatureLocation) 085 { 086 SeqFeatureLocation seqLoc2 = (SeqFeatureLocation) inObj2; 087 088 result = CompareUtil.compare(toIntRange(), seqLoc2.toIntRange()); 089 if (0 == result) 090 { 091 result = CompareUtil.compare(toString(), inObj2.toString()); 092 } 093 } 094 095 return result; 096 } 097 098 //-------------------------------------------------------------------------- 099 @Override 100 public Range<Integer> toIntRange() 101 { 102 return mIntRange; 103 } 104 105 //-------------------------------------------------------------------------- 106 @Override 107 public String eval(String inSequence) 108 { 109 return inSequence.subSequence(toIntRange().getStart(), toIntRange().getEnd()).toString(); 110 } 111}