Tokens.java
01 /**
02  * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03  */
04 package net.sourceforge.pmd.cpd;
05 
06 import java.util.ArrayList;
07 import java.util.Iterator;
08 import java.util.List;
09 
10 public class Tokens {
11 
12     private List<TokenEntry> tokens = new ArrayList<TokenEntry>();
13 
14     public void add(TokenEntry tokenEntry) {
15         this.tokens.add(tokenEntry);
16     }
17 
18     public Iterator<TokenEntry> iterator() {
19         return tokens.iterator();
20     }
21 
22     private TokenEntry get(int index) {
23         return tokens.get(index);
24     }
25 
26     public int size() {
27         return tokens.size();
28     }
29 
30     public int getLineCount(TokenEntry mark, Match match) {
31         TokenEntry endTok = get(mark.getIndex() + match.getTokenCount() 1);
32         if (endTok == TokenEntry.EOF) {
33             endTok = get(mark.getIndex() + match.getTokenCount() 2);
34         }
35         return endTok.getBeginLine() - mark.getBeginLine() 1;
36     }
37 
38     public List<TokenEntry> getTokens() {
39         return tokens;
40     }
41 
42 }