001    /*
002    NGramJ - n-gram based text classification
003    Copyright (C) 2001- Frank S. Nestel (frank at spieleck.de)
004    
005    This program is free software; you can redistribute it and/or modify
006    it under the terms of the GNU Lesser General Public License as published 
007    by the Free Software Foundation; either version 2.1 of the License, or
008    (at your option) any later version.
009    
010    This program is distributed in the hope that it will be useful,
011    but WITHOUT ANY WARRANTY; without even the implied warranty of
012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013    GNU General Public License for more details.
014    
015    You should have received a copy of the GNU Lesser General Public License
016    along with this program (lesser.txt); if not, write to the Free Software
017    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
018    */
019    package de.spieleck.app.cngram;
020    
021    /**
022     * store NGram
023     * @author frank nestel
024     * @author $Author: nestefan $
025     * @version $Revision: 2 $ $Date: 2006-03-27 23:00:21 +0200 (Mo, 27 Mrz 2006) $ $Author: nestefan $
026     */
027    public class NGramImpl
028      extends LightCharSequence
029      implements NGram
030    {
031      private char[] chars;
032    
033      private int count = 0;
034    
035      public NGramImpl(CharSequence seq)
036      {
037        super(seq);
038      }
039    
040      public NGramImpl(CharSequence seq, int count)
041      {
042        this(seq);
043        setCount(count);
044      }
045    
046      public int getCount()
047      {
048        return count;
049      }
050    
051      public void setCount(int count)
052      {
053        this.count = count;
054      }
055    
056      public int compareTo(Object o)
057      {
058        int d = ((NGramImpl) o).count - count;
059        if ( d != 0 )
060          return d;
061        return NGramProfile.CHAR_SEQ_COMPARATOR.compare(this,(NGramImpl)o);
062      }
063    
064      public void inc()
065      {
066        count++;
067      }
068    
069      public String toString()
070      {
071        return super.toString();
072      }
073    }
074