/**
 * This file is part of CERMINE project.
 * Copyright (c) 2011-2016 ICM-UW
 *
 * CERMINE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * CERMINE 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with CERMINE. If not, see <http://www.gnu.org/licenses/>.
 */

package pl.edu.icm.cermine.bibref.parsing.model;

import java.util.ArrayList;
import java.util.List;

/**
 * Represents a citation as a sequence of citation tokens.
 *
 * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
 */
public class Citation {

    private String text;
    private List<CitationToken> tokens;

    public Citation(String text, List<CitationToken> tokens) {
        this.text = text;
        this.tokens = tokens;
    }

    public Citation(String text) {
        this(text, new ArrayList<CitationToken>());
    }

    public Citation() {
        this("");
    }

    public String getText() {
        return text;
    }

    public List<CitationToken> getTokens() {
        return tokens;
    }

    public void setText(String text) {
        this.text = text;
    }

    public void addToken(CitationToken token) {
        tokens.add(token);
    }

    public void appendText(String text) {
        this.text += text;
    }

}

@@ -1042,16 +1042,62 @@
  tokens;
+%0A    private List%3CCitationToken%3E consolidated;
 %0A%0A    pu
@@ -1482,32 +1482,1191 @@
 rn tokens;%0A    %7D
+%0A    %0A    public List%3CCitationToken%3E getConcatenatedTokens() %7B%0A        if (consolidated == null) %7B%0A            consolidated = new ArrayList%3CCitationToken%3E();%0A            CitationTokenLabel prevLabel = null;%0A            String prevText = %22%22;%0A            int prevStart = 0;%0A            int prevEnd = 0;%0A            for (CitationToken token : tokens) %7B%0A                if (prevLabel != token.getLabel()) %7B%0A                    if (prevLabel != null) %7B%0A                        consolidated.add(new CitationToken(prevText, prevStart, prevEnd, prevLabel));%0A                    %7D%0A                    prevLabel = token.getLabel();%0A                    prevText = token.getText();%0A                    prevStart = token.getStartIndex();%0A                    prevEnd = token.getEndIndex();%0A                %7D else %7B%0A                    prevEnd = token.getEndIndex();%0A                    prevText += %22 %22;%0A                    prevText += token.getText();%0A                %7D%0A            %7D%0A            if (prevLabel != null) %7B%0A                consolidated.add(new CitationToken(prevText, prevStart, prevEnd, prevLabel));%0A            %7D%0A        %7D%0A        return consolidated;%0A    %7D
 %0A%0A    public voi

calculate concatenated tokens sequence