MtasPrefixTokenFilterFactory.java.html
5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MtasPrefixTokenFilterFactory.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> > <a href="index.source.html" class="el_package">mtas.analysis.util</a> > <span class="el_source">MtasPrefixTokenFilterFactory.java</span></div><h1>MtasPrefixTokenFilterFactory.java</h1><pre class="source lang-java linenums">package mtas.analysis.util;
import java.io.IOException;
import java.util.Map;
import mtas.analysis.token.MtasToken;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.analysis.util.TokenFilterFactory;
/**
* A factory for creating MtasPrefixTokenFilter objects.
*/
public class MtasPrefixTokenFilterFactory extends TokenFilterFactory {
/** The prefix. */
private String prefix;
/**
* Instantiates a new mtas prefix token filter factory.
*
* @param args the args
*/
public MtasPrefixTokenFilterFactory(Map<String, String> args) {
<span class="fc" id="L25"> super(args);</span>
<span class="fc" id="L26"> prefix = get(args, "prefix");</span>
<span class="fc" id="L27"> }</span>
/*
* (non-Javadoc)
*
* @see
* org.apache.lucene.analysis.util.TokenFilterFactory#create(org.apache.lucene
* .analysis.TokenStream)
*/
@Override
public TokenStream create(TokenStream input) {
<span class="nc" id="L38"> return new MtasPrefixTokenFilter(input, prefix);</span>
}
/**
* The Class MtasPrefixTokenFilter.
*/
private static class MtasPrefixTokenFilter extends TokenFilter {
/** The prefix. */
private String prefix;
/** The term att. */
<span class="nc" id="L50"> private final CharTermAttribute termAtt = addAttribute(</span>
CharTermAttribute.class);
/**
* Instantiates a new mtas prefix token filter.
*
* @param input the input
* @param prefix the prefix
*/
protected MtasPrefixTokenFilter(TokenStream input, String prefix) {
<span class="nc" id="L60"> super(input);</span>
<span class="nc" id="L61"> this.prefix = prefix + MtasToken.DELIMITER;</span>
<span class="nc" id="L62"> }</span>
/*
* (non-Javadoc)
*
* @see org.apache.lucene.analysis.TokenStream#incrementToken()
*/
@Override
public final boolean incrementToken() throws IOException {
<span class="nc bnc" id="L71" title="All 2 branches missed."> if (input.incrementToken()) {</span>
<span class="nc" id="L72"> int oldLen = termAtt.length();</span>
<span class="nc" id="L73"> char[] buffer = termAtt.resizeBuffer(oldLen + prefix.length());</span>
<span class="nc bnc" id="L75" title="All 2 branches missed."> for (int i = 0; i < oldLen; i++) {</span>
<span class="nc" id="L76"> buffer[(oldLen + prefix.length() - 1 - i)] = buffer[(oldLen - 1 - i)];</span>
}
<span class="nc bnc" id="L78" title="All 2 branches missed."> for (int i = 0; i < prefix.length(); i++) {</span>
<span class="nc" id="L79"> buffer[i] = prefix.charAt(i);</span>
}
<span class="nc" id="L81"> termAtt.copyBuffer(buffer, 0, oldLen + prefix.length());</span>
<span class="nc" id="L82"> return true;</span>
} else {
<span class="nc" id="L84"> return false;</span>
}
}
/*
* (non-Javadoc)
*
* @see org.apache.lucene.util.AttributeSource#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
<span class="nc bnc" id="L95" title="All 2 branches missed."> if (this == obj)</span>
<span class="nc" id="L96"> return true;</span>
<span class="nc bnc" id="L97" title="All 2 branches missed."> if (obj == null)</span>
<span class="nc" id="L98"> return false;</span>
<span class="nc bnc" id="L99" title="All 2 branches missed."> if (getClass() != obj.getClass())</span>
<span class="nc" id="L100"> return false;</span>
<span class="nc" id="L101"> final MtasPrefixTokenFilter that = (MtasPrefixTokenFilter) obj;</span>
<span class="nc bnc" id="L102" title="All 4 branches missed."> return prefix.equals(that.prefix) && super.equals(that);</span>
}
/*
* (non-Javadoc)
*
* @see org.apache.lucene.util.AttributeSource#hashCode()
*/
@Override
public int hashCode() {
<span class="nc" id="L112"> int h = this.getClass().getSimpleName().hashCode();</span>
<span class="nc" id="L113"> h = (h * 7) ^ prefix.hashCode();</span>
<span class="nc" id="L114"> return h;</span>
}
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>