SOLR-2288: more small tweaks to eliminate compiler warnings

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1056612 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2011-01-08 03:47:31 +00:00
parent 6813c2ed59
commit bdd7fea1e4
11 changed files with 85 additions and 75 deletions

View File

@ -47,6 +47,8 @@ import java.util.*;
*/
public abstract class AnalysisRequestHandlerBase extends RequestHandlerBase {
public static final Set<String> EMPTY_STRING_SET = Collections.emptySet();
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
rsp.add("analysis", doAnalysis(req));
}
@ -70,7 +72,7 @@ public abstract class AnalysisRequestHandlerBase extends RequestHandlerBase {
*
* @return NamedList containing the tokens produced by analyzing the given value
*/
protected NamedList<List<NamedList>> analyzeValue(String value, AnalysisContext context) {
protected NamedList<? extends Object> analyzeValue(String value, AnalysisContext context) {
Analyzer analyzer = context.getAnalyzer();
@ -93,7 +95,7 @@ public abstract class AnalysisRequestHandlerBase extends RequestHandlerBase {
TokenizerFactory tfac = tokenizerChain.getTokenizerFactory();
TokenFilterFactory[] filtfacs = tokenizerChain.getTokenFilterFactories();
NamedList<List<NamedList>> namedList = new NamedList<List<NamedList>>();
NamedList<Object> namedList = new NamedList<Object>();
if( cfiltfacs != null ){
String source = value;
@ -234,7 +236,7 @@ public abstract class AnalysisRequestHandlerBase extends RequestHandlerBase {
return tokensNamedLists;
}
private String writeCharStream(NamedList out, CharStream input ){
private String writeCharStream(NamedList<Object> out, CharStream input ){
final int BUFFER_SIZE = 1024;
char[] buf = new char[BUFFER_SIZE];
int len = 0;
@ -252,7 +254,6 @@ public abstract class AnalysisRequestHandlerBase extends RequestHandlerBase {
return sb.toString();
}
// ================================================= Inner classes =================================================
/**
@ -342,7 +343,7 @@ public abstract class AnalysisRequestHandlerBase extends RequestHandlerBase {
*
*/
public AnalysisContext(String fieldName, FieldType fieldType, Analyzer analyzer) {
this(fieldName, fieldType, analyzer, Collections.EMPTY_SET);
this(fieldName, fieldType, analyzer, EMPTY_STRING_SET);
}
/**

View File

@ -230,9 +230,8 @@ public class DocumentAnalysisRequestHandler extends AnalysisRequestHandlerBase {
if (request.getQuery() != null) {
try {
AnalysisContext analysisContext = new AnalysisContext(fieldType, fieldType.getQueryAnalyzer(), Collections.EMPTY_SET);
NamedList<List<NamedList>> tokens = analyzeValue(request.getQuery(), analysisContext);
fieldTokens.add("query", tokens);
AnalysisContext analysisContext = new AnalysisContext(fieldType, fieldType.getQueryAnalyzer(), EMPTY_STRING_SET);
fieldTokens.add("query", analyzeValue(request.getQuery(), analysisContext));
} catch (Exception e) {
// ignore analysis exceptions since we are applying arbitrary text to all fields
}
@ -241,10 +240,11 @@ public class DocumentAnalysisRequestHandler extends AnalysisRequestHandlerBase {
Analyzer analyzer = fieldType.getAnalyzer();
AnalysisContext analysisContext = new AnalysisContext(fieldType, analyzer, termsToMatch);
Collection<Object> fieldValues = document.getFieldValues(name);
NamedList<NamedList<List<NamedList>>> indexTokens = new SimpleOrderedMap<NamedList<List<NamedList>>>();
NamedList<NamedList<? extends Object>> indexTokens
= new SimpleOrderedMap<NamedList<? extends Object>>();
for (Object fieldValue : fieldValues) {
NamedList<List<NamedList>> tokens = analyzeValue(fieldValue.toString(), analysisContext);
indexTokens.add(String.valueOf(fieldValue), tokens);
indexTokens.add(String.valueOf(fieldValue),
analyzeValue(fieldValue.toString(), analysisContext));
}
fieldTokens.add("index", indexTokens);
}

View File

@ -38,7 +38,7 @@ public class DumpRequestHandler extends RequestHandlerBase
// Write the streams...
if( req.getContentStreams() != null ) {
ArrayList streams = new ArrayList();
ArrayList<NamedList<Object>> streams = new ArrayList<NamedList<Object>>();
// Cycle through each stream
for( ContentStream content : req.getContentStreams() ) {
NamedList<Object> stream = new SimpleOrderedMap<Object>();

View File

@ -69,6 +69,7 @@ class JsonLoader extends ContentStreamLoader {
}
}
@SuppressWarnings("fallthrough")
void processUpdate(SolrQueryRequest req, UpdateRequestProcessor processor, JSONParser parser) throws IOException
{
int ev = parser.nextEvent();

View File

@ -94,7 +94,7 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
private volatile IndexCommit indexCommitPoint;
volatile NamedList snapShootDetails;
volatile NamedList<Object> snapShootDetails;
private AtomicBoolean replicationEnabled = new AtomicBoolean(true);
@ -189,13 +189,13 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
}
}
private List<NamedList> getCommits() {
private List<NamedList<Object>> getCommits() {
Map<Long, IndexCommit> commits = core.getDeletionPolicy().getCommits();
List<NamedList> l = new ArrayList<NamedList>();
List<NamedList<Object>> l = new ArrayList<NamedList<Object>>();
for (IndexCommit c : commits.values()) {
try {
NamedList nl = new NamedList();
NamedList<Object> nl = new NamedList<Object>();
nl.add("indexVersion", c.getVersion());
nl.add(GENERATION, c.getGeneration());
nl.add(CMD_GET_FILE_LIST, c.getFileNames());
@ -701,7 +701,7 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
return details;
}
private void addVal(NamedList nl, String key, Properties props, Class clzz) {
private void addVal(NamedList<Object> nl, String key, Properties props, Class clzz) {
String s = props.getProperty(key);
if (s == null || s.trim().length() == 0) return;
if (clzz == Date.class) {

View File

@ -63,6 +63,9 @@ import java.util.zip.InflaterInputStream;
public class SnapPuller {
private static final Logger LOG = LoggerFactory.getLogger(SnapPuller.class.getName());
private static final List<Map<String,Object>> EMPTY_LIST_OF_MAPS
= Collections.emptyList();
private final String masterUrl;
private final ReplicationHandler replicationHandler;
@ -192,14 +195,14 @@ public class SnapPuller {
return getNamedListResponse(post);
}
private NamedList getNamedListResponse(PostMethod method) throws IOException {
private NamedList<?> getNamedListResponse(PostMethod method) throws IOException {
try {
int status = myHttpClient.executeMethod(method);
if (status != HttpStatus.SC_OK) {
throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE,
"Request failed for the url " + method);
}
return (NamedList) new JavaBinCodec().unmarshal(method.getResponseBodyAsStream());
return (NamedList<?>) new JavaBinCodec().unmarshal(method.getResponseBodyAsStream());
} finally {
try {
method.releaseConnection();
@ -216,8 +219,12 @@ public class SnapPuller {
post.addParameter(COMMAND, CMD_GET_FILE_LIST);
post.addParameter(CMD_INDEX_VERSION, String.valueOf(version));
post.addParameter("wt", "javabin");
NamedList nl = getNamedListResponse(post);
List<Map<String, Object>> f = (List<Map<String, Object>>) nl.get(CMD_GET_FILE_LIST);
@SuppressWarnings("unchecked")
NamedList<List<Map<String, Object>>> nl
= (NamedList<List<Map<String, Object>>>) getNamedListResponse(post);
List<Map<String, Object>> f = nl.get(CMD_GET_FILE_LIST);
if (f != null)
filesToDownload = Collections.synchronizedList(f);
else {
@ -225,7 +232,7 @@ public class SnapPuller {
LOG.error("No files to download for indexversion: "+ version);
}
f = (List<Map<String, Object>>) nl.get(CONF_FILES);
f = nl.get(CONF_FILES);
if (f != null)
confFilesToDownload = Collections.synchronizedList(f);
}
@ -704,10 +711,11 @@ public class SnapPuller {
*/
private Collection<Map<String, Object>> getModifiedConfFiles(List<Map<String, Object>> confFilesToDownload) {
if (confFilesToDownload == null || confFilesToDownload.isEmpty())
return Collections.EMPTY_LIST;
return EMPTY_LIST_OF_MAPS;
//build a map with alias/name as the key
Map<String, Map<String, Object>> nameVsFile = new HashMap<String, Map<String, Object>>();
NamedList names = new NamedList();
NamedList<String> names = new NamedList<String>();
for (Map<String, Object> map : confFilesToDownload) {
//if alias is present that is the name the file may have in the slave
String name = (String) (map.get(ALIAS) == null ? map.get(NAME) : map.get(ALIAS));
@ -725,7 +733,7 @@ public class SnapPuller {
nameVsFile.remove(name); //checksums are same so the file need not be downloaded
}
}
return nameVsFile.isEmpty() ? Collections.EMPTY_LIST : nameVsFile.values();
return nameVsFile.isEmpty() ? EMPTY_LIST_OF_MAPS : nameVsFile.values();
}
/**
@ -788,25 +796,25 @@ public class SnapPuller {
//make a copy first because it can be null later
List<Map<String, Object>> tmp = confFilesToDownload;
//create a new instance. or else iterator may fail
return tmp == null ? Collections.EMPTY_LIST : new ArrayList<Map<String, Object>>(tmp);
return tmp == null ? EMPTY_LIST_OF_MAPS : new ArrayList<Map<String, Object>>(tmp);
}
List<Map<String, Object>> getConfFilesDownloaded() {
//make a copy first because it can be null later
List<Map<String, Object>> tmp = confFilesDownloaded;
// NOTE: it's safe to make a copy of a SynchronizedCollection(ArrayList)
return tmp == null ? Collections.EMPTY_LIST : new ArrayList<Map<String, Object>>(tmp);
return tmp == null ? EMPTY_LIST_OF_MAPS : new ArrayList<Map<String, Object>>(tmp);
}
List<Map<String, Object>> getFilesToDownload() {
//make a copy first because it can be null later
List<Map<String, Object>> tmp = filesToDownload;
return tmp == null ? Collections.EMPTY_LIST : new ArrayList<Map<String, Object>>(tmp);
return tmp == null ? EMPTY_LIST_OF_MAPS : new ArrayList<Map<String, Object>>(tmp);
}
List<Map<String, Object>> getFilesDownloaded() {
List<Map<String, Object>> tmp = filesDownloaded;
return tmp == null ? Collections.EMPTY_LIST : new ArrayList<Map<String, Object>>(tmp);
return tmp == null ? EMPTY_LIST_OF_MAPS : new ArrayList<Map<String, Object>>(tmp);
}
Map<String, Object> getCurrentFile() {

View File

@ -71,7 +71,8 @@ public class SnapShooter {
}
void createSnapshot(final IndexCommit indexCommit, ReplicationHandler replicationHandler) {
NamedList details = new NamedList();
NamedList<Object> details = new NamedList<Object>();
details.add("startTime", new Date().toString());
File snapShotDir = null;
String directoryName = null;

View File

@ -124,8 +124,8 @@ public class StatsComponent extends SearchComponent {
StatsInfo si = rb._statsInfo;
NamedList stats = new SimpleOrderedMap();
NamedList stats_fields = new SimpleOrderedMap();
NamedList<NamedList<Object>> stats = new SimpleOrderedMap<NamedList<Object>>();
NamedList<Object> stats_fields = new SimpleOrderedMap<Object>();
stats.add("stats_fields", stats_fields);
for (String field : si.statsFields.keySet()) {
NamedList stv = si.statsFields.get(field).getStatsValues();
@ -209,8 +209,8 @@ class SimpleStats {
return res;
}
public NamedList getStatsFields() throws IOException {
NamedList<NamedList<Number>> res = new SimpleOrderedMap<NamedList<Number>>();
public NamedList<Object> getStatsFields() throws IOException {
NamedList<Object> res = new SimpleOrderedMap<Object>();
String[] statsFs = params.getParams(StatsParams.STATS_FIELD);
boolean isShard = params.getBool(ShardParams.IS_SHARD, false);
if (null != statsFs) {
@ -221,7 +221,7 @@ class SimpleStats {
}
SchemaField sf = searcher.getSchema().getField(f);
FieldType ft = sf.getType();
NamedList stv;
NamedList<?> stv;
// Currently, only UnInvertedField can deal with multi-part trie fields
String prefix = TrieField.getMainValuePrefix(ft);
@ -243,7 +243,7 @@ class SimpleStats {
return res;
}
public NamedList getFieldCacheStats(String fieldName, String[] facet ) {
public NamedList<?> getFieldCacheStats(String fieldName, String[] facet ) {
FieldType ft = searcher.getSchema().getFieldType(fieldName);
FieldCache.DocTermsIndex si = null;

View File

@ -77,7 +77,7 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar
return;
}
NamedList termVectors = new NamedList();
NamedList<Object> termVectors = new NamedList<Object>();
rb.rsp.add(TERM_VECTORS, termVectors);
FieldOptions allFields = new FieldOptions();
//figure out what options we have, and try to get the appropriate vector
@ -106,7 +106,7 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar
IndexSchema schema = rb.req.getSchema();
//Build up our per field mapping
Map<String, FieldOptions> fieldOptions = new HashMap<String, FieldOptions>();
NamedList warnings = new NamedList();
NamedList<List<String>> warnings = new NamedList<List<String>>();
List<String> noTV = new ArrayList<String>();
List<String> noPos = new ArrayList<String>();
List<String> noOff = new ArrayList<String>();
@ -187,7 +187,7 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar
mapper.fieldOptions = allFields; //this will only stay set if fieldOptions.isEmpty() (in other words, only if the user didn't set any fields)
while (iter.hasNext()) {
Integer docId = iter.next();
NamedList docNL = new NamedList();
NamedList<Object> docNL = new NamedList<Object>();
mapper.docNL = docNL;
termVectors.add("doc-" + docId, docNL);
@ -272,7 +272,7 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar
private static class TVMapper extends TermVectorMapper {
private IndexReader reader;
private NamedList docNL;
private NamedList<Object> docNL;
//needs to be set for each new field
FieldOptions fieldOptions;
@ -280,7 +280,7 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar
//internal vars not passed in by construction
private boolean useOffsets, usePositions;
//private Map<String, Integer> idfCache;
private NamedList fieldNL;
private NamedList<Object> fieldNL;
private Term currentTerm;
@ -289,34 +289,34 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar
}
public void map(BytesRef term, int frequency, TermVectorOffsetInfo[] offsets, int[] positions) {
NamedList termInfo = new NamedList();
fieldNL.add(term.utf8ToString(), termInfo);
if (fieldOptions.termFreq == true) {
termInfo.add("tf", frequency);
NamedList<Object> termInfo = new NamedList<Object>();
fieldNL.add(term.utf8ToString(), termInfo);
if (fieldOptions.termFreq == true) {
termInfo.add("tf", frequency);
}
if (useOffsets == true) {
NamedList<Number> theOffsets = new NamedList<Number>();
termInfo.add("offsets", theOffsets);
for (int i = 0; i < offsets.length; i++) {
TermVectorOffsetInfo offset = offsets[i];
theOffsets.add("start", offset.getStartOffset());
theOffsets.add("end", offset.getEndOffset());
}
if (useOffsets == true) {
NamedList theOffsets = new NamedList();
termInfo.add("offsets", theOffsets);
for (int i = 0; i < offsets.length; i++) {
TermVectorOffsetInfo offset = offsets[i];
theOffsets.add("start", offset.getStartOffset());
theOffsets.add("end", offset.getEndOffset());
}
}
if (usePositions == true) {
NamedList positionsNL = new NamedList();
for (int i = 0; i < positions.length; i++) {
positionsNL.add("position", positions[i]);
}
termInfo.add("positions", positionsNL);
}
if (fieldOptions.docFreq == true) {
termInfo.add("df", getDocFreq(term));
}
if (fieldOptions.tfIdf == true) {
double tfIdfVal = ((double) frequency) / getDocFreq(term);
termInfo.add("tf-idf", tfIdfVal);
}
if (usePositions == true) {
NamedList<Integer> positionsNL = new NamedList<Integer>();
for (int i = 0; i < positions.length; i++) {
positionsNL.add("position", positions[i]);
}
termInfo.add("positions", positionsNL);
}
if (fieldOptions.docFreq == true) {
termInfo.add("df", getDocFreq(term));
}
if (fieldOptions.tfIdf == true) {
double tfIdfVal = ((double) frequency) / getDocFreq(term);
termInfo.add("tf-idf", tfIdfVal);
}
}
private int getDocFreq(BytesRef term) {
@ -343,7 +343,7 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar
}
useOffsets = storeOffsets && fieldOptions.offsets;
usePositions = storePositions && fieldOptions.positions;
fieldNL = new NamedList();
fieldNL = new NamedList<Object>();
docNL.add(field, fieldNL);
}
@ -394,4 +394,4 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar
class FieldOptions {
String fieldName;
boolean termFreq, positions, offsets, docFreq, tfIdf;
}
}

View File

@ -900,15 +900,15 @@ public class UnInvertedField {
//////////////////////////// caching /////////////////////////////
//////////////////////////////////////////////////////////////////
public static UnInvertedField getUnInvertedField(String field, SolrIndexSearcher searcher) throws IOException {
SolrCache cache = searcher.getFieldValueCache();
SolrCache<String,UnInvertedField> cache = searcher.getFieldValueCache();
if (cache == null) {
return new UnInvertedField(field, searcher);
}
UnInvertedField uif = (UnInvertedField)cache.get(field);
UnInvertedField uif = cache.get(field);
if (uif == null) {
synchronized (cache) {
uif = (UnInvertedField)cache.get(field);
uif = cache.get(field);
if (uif == null) {
uif = new UnInvertedField(field, searcher);
cache.put(field, uif);
@ -918,7 +918,6 @@ public class UnInvertedField {
return uif;
}
}

View File

@ -79,7 +79,7 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean {
private final SolrCache<Query,DocSet> filterCache;
private final SolrCache<QueryResultKey,DocList> queryResultCache;
private final SolrCache<Integer,Document> documentCache;
private final SolrCache<String,Object> fieldValueCache;
private final SolrCache<String,UnInvertedField> fieldValueCache;
private final LuceneQueryOptimizer optimizer;
@ -470,7 +470,7 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean {
////////////////////////////////////////////////////////////////////////////////
/** expert: internal API, subject to change */
public SolrCache getFieldValueCache() {
public SolrCache<String,UnInvertedField> getFieldValueCache() {
return fieldValueCache;
}