##### Coverage Report - org.owasp.dependencycheck.data.lucene.AbstractTokenizingFilter

Classes in this File | Line Coverage | Branch Coverage | Complexity
AbstractTokenizingFilter |
100% | 12/12
100% | 4/4
| 1.25;1.25

1 |  |
     /*
2 |  |
      * This file is part of dependency-check-core.
3 |  |
      *
4 |  |
      * Dependency-check-core is free software: you can redistribute it and/or modify it
5 |  |
      * under the terms of the GNU General Public License as published by the Free
6 |  |
      * Software Foundation, either version 3 of the License, or (at your option) any
7 |  |
      * later version.
8 |  |
      *
9 |  |
      * Dependency-check-core is distributed in the hope that it will be useful, but
10 |  |
      * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 |  |
      * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 |  |
      * details.
13 |  |
      *
14 |  |
      * You should have received a copy of the GNU General Public License along with
15 |  |
      * dependency-check-core. If not, see http://www.gnu.org/licenses/.
16 |  |
      *
17 |  |
      * Copyright (c) 2013 Jeremy Long. All Rights Reserved.
18 |  |
      */
19 |  |
     package org.owasp.dependencycheck.data.lucene;
20 |  |
21 |  |
     import java.util.LinkedList;
22 |  |
     import org.apache.lucene.analysis.TokenFilter;
23 |  |
     import org.apache.lucene.analysis.TokenStream;
24 |  |
     import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
25 |  |
26 |  |
     /**
27 |  |
      * An abstract tokenizing filter that can be used as the base for a tokenizing
28 |  |
      * filter.
29 |  |
      *
30 |  |
      * @author Jeremy Long (jeremy.long@owasp.org)
31 |  |
      */
32 |  |
     public abstract class AbstractTokenizingFilter extends TokenFilter {
33 |  |
34 |  |
         /**
35 |  |
          * The char term attribute.
36 |  |
          */
37 | 30 |
         private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
38 |  |
39 |  |
         /**
40 |  |
          * Gets the CharTermAttribute.
41 |  |
          *
42 |  |
          * @return the CharTermAttribute
43 |  |
          */
44 |  |
         protected CharTermAttribute getTermAtt() {
45 | 33027 |
             return termAtt;
46 |  |
         }
47 |  |
         /**
48 |  |
          * A collection of tokens to add to the stream.
49 |  |
          */
50 |  |
         private final LinkedList<String> tokens;
51 |  |
52 |  |
         /**
53 |  |
          * Gets the list of tokens.
54 |  |
          *
55 |  |
          * @return the list of tokens
56 |  |
          */
57 |  |
         protected LinkedList<String> getTokens() {
58 | 33027 |
             return tokens;
59 |  |
         }
60 |  |
61 |  |
         /**
62 |  |
          * Constructs a new AbstractTokenizingFilter.
63 |  |
          *
64 |  |
          * @param stream the TokenStream that this filter will process
65 |  |
          */
66 |  |
         public AbstractTokenizingFilter(TokenStream stream) {
67 | 30 |
             super(stream);
68 | 30 |
             tokens = new LinkedList<String>();
69 | 30 |
         }
70 |  |
71 |  |
         /**
72 |  |
          * Adds a term, if one exists, from the tokens collection.
73 |  |
          *
74 |  |
          * @return whether or not a new term was added
75 |  |
          */
76 |  |
         protected boolean addTerm() {
77 | 32955 |
             final boolean termAdded = tokens.size() > 0;
78 | 32955 |
             if (termAdded) {
79 | 19516 |
                 final String term = tokens.pop();
80 | 19516 |
                 clearAttributes();
81 | 19516 |
                 termAtt.append(term);
82 |  |
             }
83 | 32955 |
             return termAdded;
84 |  |
         }
85 |  |
     }