001/*
002 * Copyright 2019 Leibniz-Institut für Analytische Wissenschaften – ISAS – e.V..
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package de.isas.mztab2.io.validators;
017
018import java.util.Collections;
019import java.util.List;
020import uk.ac.ebi.pride.jmztab2.model.IMZTabColumn;
021import uk.ac.ebi.pride.jmztab2.utils.errors.MZTabError;
022import uk.ac.ebi.pride.jmztab2.utils.parser.MZTabParserContext;
023
024/**
025 * Implementations of the field validator are applied to the type object (usually a parsed string element)
026 * during the parsing process. The validator can access the current parsing context for state-dependent 
027 * validation and receives the current column specification for type specific checking.
028 *
029 * @author nilshoffmann
030 * @param <T> the type of the parsed object to validate.
031 */
032public interface FieldValidator<T> {
033    /**
034     * Validate the given object of type T, using the provided parser context and column to
035     * check the state of not yet completely parsed and constructed mzTab hierarchy.
036     *
037     * @param lineNumber the current line number being parsed. Maybe -1 to indicate no active lineNumber, e.g. for post-hoc refine validation.
038     * @param parserContext the parser context
039     * @param column the IMzTabColumn to use for type validation constraints
040     * @param field the string representation of the field
041     * @param t the object to validate
042     * @return a list of {@link MZTabError}, maybe empty.
043     */
044    public default List<MZTabError> validateLine(int lineNumber, MZTabParserContext parserContext, IMZTabColumn column, String field, T t) {
045        return Collections.emptyList();
046    }
047}