package de.danielnaber.languagetool.rules;

  /* LanguageTool, a natural language style checker 
   * Copyright (C) 2005 Daniel Naber (http://www.danielnaber.de)
   * 
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
   * This library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this library; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
   * USA
   */
  import java.util.ArrayList;
  import java.util.List;
  import java.util.ResourceBundle;

  import de.danielnaber.languagetool.AnalyzedSentence;
  import de.danielnaber.languagetool.AnalyzedTokenReadings;
  import de.danielnaber.languagetool.Language;

  /**
   * Check if there is duplicated whitespace in a sentence.
   * Considers two spaces as incorrect, and proposes a single space instead.
   *    
   * @author Marcin Miłkowski
   */


public class WhitespaceRule extends Rule {
   
    public WhitespaceRule(final ResourceBundle messages, final Language language) {
      super(messages);
      super.setCategory(new Category(messages.getString("category_misc")));
    }
    
    public String getId() {
      return "WHITESPACE_RULE";
    }

    public String getDescription() {
      return messages.getString("desc_whitespacerepetition");
    }

    public RuleMatch[] match(final AnalyzedSentence text) {
      final List<RuleMatch> ruleMatches = new ArrayList<RuleMatch>();
      final AnalyzedTokenReadings[] tokens = text.getTokens();
      boolean prevWhite = false;
      int prevLen = 0;
      int prevPos = 0;
      //note: we start from token 1
      //token no. 0 is guaranteed to be SENT_START
      int i = 1;
      while (i < tokens.length) {
       if (tokens[i].isWhitespace() && prevWhite) {
         final int pos = tokens[i].getStartPos();
           while (i < tokens.length && tokens[i].isWhitespace()) {             
             prevLen += tokens[i].getToken().length();
             i++;
           }
            final String msg = messages.getString("whitespace_repetition");            
            final RuleMatch ruleMatch = 
              new RuleMatch(this, prevPos, pos + prevLen - 1, msg);
            ruleMatch.setSuggestedReplacement(" ");
            ruleMatches.add(ruleMatch);
          }
          prevWhite = tokens[i].isWhitespace();
          prevLen = tokens[i].getToken().length();
          prevPos = tokens[i].getStartPos();
          i++;
      }
      return toRuleMatchArray(ruleMatches);
    }

    public void reset() {
      // nothing
    }

  }


@@ -1619,30 +1619,50 @@
  %7D%0A    %0A    
-public
+@Override%0A    public final
  String getI
@@ -1710,22 +1710,42 @@
  %7D%0A%0A    
-public
+@Override%0A    public final
  String 
@@ -1824,32 +1824,46 @@
 ition%22);%0A    %7D%0A%0A
+    @Override%0A
     public RuleM
@@ -2528,96 +2528,8 @@
   %7D%0A
-            final String msg = messages.getString(%22whitespace_repetition%22);            %0A
     
@@ -2631,11 +2631,70 @@
  1, 
-msg
+%0A                  messages.getString(%22whitespace_repetition%22)
 );%0A 
@@ -2788,32 +2788,67 @@
 h);%0A          %7D%0A
+          if (i %3C tokens.length) %7B%0A
           prevWh
@@ -2986,24 +2986,36 @@
        i++;%0A
+          %7D%0A
       %7D%0A    
@@ -3057,24 +3057,38 @@
 es);%0A    %7D%0A%0A
+    @Override%0A
     public v

fix bug with i > tokens.length