/**
 * DocumentValidator
 * Copyright (c) 2013-, Takahiko Ito, All rights reserved.
 *
 * 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 3.0 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.
 */
package org.unigram.docvalidator.validator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.unigram.docvalidator.store.Document;
import org.unigram.docvalidator.store.FileContent;
import org.unigram.docvalidator.util.CharacterTable;
import org.unigram.docvalidator.util.ResultDistributorFactory;
import org.unigram.docvalidator.util.ValidatorConfiguration;
import org.unigram.docvalidator.util.DVResource;
import org.unigram.docvalidator.util.DocumentValidatorException;
import org.unigram.docvalidator.util.ResultDistributor;
import org.unigram.docvalidator.util.ValidationError;

/**
 * Validate all input files using appended Validators.
 */
public class DocumentValidator {
  /**
   * Constructor.
   *
   * @param resource          configuration settings for DocumentValidator
   * @param resultDistributor output distributor
   * @throws DocumentValidatorException when failed to create the instance
   */
  public DocumentValidator(DVResource resource,
                           ResultDistributor resultDistributor)
      throws DocumentValidatorException {
    this(resource);
    if (resultDistributor == null) {
      throw new DocumentValidatorException("ResultDistributor is null");
    }
    this.distributor = resultDistributor;
  }

  /**
   * Constructor.
   *
   * @param resource configuration settings for DocumentValidator
   * @throws DocumentValidatorException when failed to create the instance
   */
  public DocumentValidator(DVResource resource)
      throws DocumentValidatorException {
    super();
    this.distributor = ResultDistributorFactory.createDistributor("plain",
        System.out);
    this.validators = new Vector<Validator>();
    this.conf = resource.getConfiguration();
    this.charTable = resource.getCharacterTable();
    if (!loadValidators()) {
      throw new DocumentValidatorException(
          "Failed to create DocumentValidator");
    }
  }

  /**
   * Load validators written in the configuration file.
   *
   * @return true when succeeded to load all the validators, false otherwise
   */
  @SuppressWarnings("BooleanMethodIsAlwaysInverted")
  public boolean loadValidators() {
    this.validators.clear();
    for (Iterator<ValidatorConfiguration> confIterator =
             this.conf.getChildren(); confIterator.hasNext(); ) {
      ValidatorConfiguration currentConfiguration = confIterator.next();
      String confName = currentConfiguration.getConfigurationName();
      Validator validator;
      try {
        validator =
            ValidatorFactory.createValidator(confName,
                currentConfiguration, this.charTable);
      } catch (DocumentValidatorException e) {
        LOG.error("Failed to create validator \" "
            + confName + "\" : " + e.getMessage());
        return false;
      }
      this.validators.add(validator);
    }
    return true;
  }

  /**
   * Validate the input document.
   *
   * @param document input document generated by Parser
   * @return list of validation errors
   */
  public List<ValidationError> check(Document document) {
    distributor.flushHeader();
    List<ValidationError> errors = new ArrayList<ValidationError>();
    for (Validator validator : this.validators) {
      Iterator<FileContent> fileIterator = document.getFiles();
      while (fileIterator.hasNext()) {
        List<ValidationError> currentErrors =
            validator.check(fileIterator.next(), distributor);
        errors.addAll(currentErrors);
      }
    }
    distributor.flushFooter();
    return errors;
  }

  private final Vector<Validator> validators;

  private final ValidatorConfiguration conf;

  private final CharacterTable charTable;

  private ResultDistributor distributor;

  private static final Logger LOG = LoggerFactory.getLogger(DocumentValidator.class);
}

@@ -834,33 +834,8 @@
 ist;
-%0Aimport java.util.Vector;
 %0A%0Aim
@@ -2458,22 +2458,25 @@
 s = new 
-Vector
+ArrayList
 %3CValidat
@@ -4340,26 +4340,26 @@
   pr
-ivate
+otected
  final 
-Vector
+List
 %3CVal

Remove Vector