001package com.hfg.bio.seq.format.feature;
002
003import java.util.ArrayList;
004import java.util.List;
005
006import com.hfg.util.collection.CollectionUtil;
007
008//------------------------------------------------------------------------------
009/**
010 Basic implementation of SeqFeature 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 abstract class SeqFeatureImpl implements SeqFeature
037{
038   private FeatureKey             mName;
039   private SeqFeatureLocation     mLocation;
040   private List<FeatureQualifier> mQualifiers;
041
042   //###########################################################################
043   // CONSTRUCTORS
044   //###########################################################################
045
046   //---------------------------------------------------------------------------
047   public SeqFeatureImpl(FeatureKey inName, SeqFeatureLocation inLocation)
048   {
049      mName = inName;
050      mLocation = inLocation;
051   }
052
053   //###########################################################################
054   // PUBLIC METHODS
055   //###########################################################################
056
057   //---------------------------------------------------------------------------
058   @Override
059   public String toString()
060   {
061      return name().name();
062   }
063
064   //---------------------------------------------------------------------------
065   @Override
066   public FeatureKey name()
067   {
068      return mName;
069   }
070
071   //---------------------------------------------------------------------------
072   public SeqFeatureLocation getLocation()
073   {
074      return mLocation;
075   }
076
077   //---------------------------------------------------------------------------
078   public SeqFeature addQualifier(FeatureQualifier inValue)
079   {
080      if (null == mQualifiers)
081      {
082         mQualifiers = new ArrayList<FeatureQualifier>(25);
083      }
084
085      mQualifiers.add(inValue);
086
087      return this;
088   }
089
090   //---------------------------------------------------------------------------
091   public List<FeatureQualifier> getQualifiers()
092   {
093      return mQualifiers;
094   }
095
096   //---------------------------------------------------------------------------
097   public List<FeatureQualifier> getQualifiers(String inQualifierName)
098   {
099      List<FeatureQualifier> qualifiers = null;
100
101      if (CollectionUtil.hasValues(mQualifiers))
102      {
103         for (FeatureQualifier qualifier : mQualifiers)
104         {
105            if (qualifier.name().equals(inQualifierName))
106            {
107               if (null == qualifiers)
108               {
109                  qualifiers = new ArrayList<FeatureQualifier>(25);
110               }
111
112               qualifiers.add(qualifier);
113            }
114         }
115      }
116
117      return qualifiers;
118   }
119
120}