From 98b448aa8cf393379246c04cdc827646860b4713 Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Sat, 8 Jan 2011 01:58:15 +0000 Subject: [PATCH] SOLR-2288: more small tweaks to eliminate compiler warnings .. inlcudes a small code de-dup refactoring in FieldAnalysisResponse git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1056594 13f79535-47bb-0310-9956-ffa450edef68 --- .../solrj/response/AnalysisResponseBase.java | 10 ++--- .../response/DocumentAnalysisResponse.java | 28 ++++++++----- .../solrj/response/FieldAnalysisResponse.java | 42 +++++++++---------- 3 files changed, 43 insertions(+), 37 deletions(-) diff --git a/solr/src/solrj/org/apache/solr/client/solrj/response/AnalysisResponseBase.java b/solr/src/solrj/org/apache/solr/client/solrj/response/AnalysisResponseBase.java index f98d2a0b364..55d87d4fbe8 100644 --- a/solr/src/solrj/org/apache/solr/client/solrj/response/AnalysisResponseBase.java +++ b/solr/src/solrj/org/apache/solr/client/solrj/response/AnalysisResponseBase.java @@ -62,12 +62,12 @@ public class AnalysisResponseBase extends SolrResponseBase { * * @return The built analysis phases list. */ - protected List buildPhases(NamedList phaseNL) { + protected List buildPhases(NamedList>> phaseNL) { List phases = new ArrayList(phaseNL.size()); - for (Map.Entry phaseEntry : phaseNL) { + for (Map.Entry>> phaseEntry : phaseNL) { AnalysisPhase phase = new AnalysisPhase(phaseEntry.getKey()); - List tokens = (List) phaseEntry.getValue(); - for (NamedList token : tokens) { + List> tokens = phaseEntry.getValue(); + for (NamedList token : tokens) { TokenInfo tokenInfo = buildTokenInfo(token); phase.addTokenInfo(tokenInfo); } @@ -95,7 +95,7 @@ public class AnalysisResponseBase extends SolrResponseBase { * * @return The built token info. */ - protected TokenInfo buildTokenInfo(NamedList tokenNL) { + protected TokenInfo buildTokenInfo(NamedList tokenNL) { String text = (String) tokenNL.get("text"); String rawText = (String) tokenNL.get("rawText"); String type = (String) tokenNL.get("type"); diff --git a/solr/src/solrj/org/apache/solr/client/solrj/response/DocumentAnalysisResponse.java b/solr/src/solrj/org/apache/solr/client/solrj/response/DocumentAnalysisResponse.java index 9cc66b9f384..f0d5dff787e 100644 --- a/solr/src/solrj/org/apache/solr/client/solrj/response/DocumentAnalysisResponse.java +++ b/solr/src/solrj/org/apache/solr/client/solrj/response/DocumentAnalysisResponse.java @@ -42,24 +42,30 @@ public class DocumentAnalysisResponse extends AnalysisResponseBase implements It public void setResponse(NamedList response) { super.setResponse(response); - NamedList analysis = (NamedList) response.get("analysis"); - for (Map.Entry documentEntry : analysis) { - DocumentAnalysis documentAnalysis = new DocumentAnalysis(documentEntry.getKey()); - NamedList document = (NamedList) documentEntry.getValue(); - for (Map.Entry fieldEntry : document) { + @SuppressWarnings("unchecked") + NamedList>> analysis + = (NamedList>>) response.get("analysis"); + for (Map.Entry>> document : analysis) { + DocumentAnalysis documentAnalysis = new DocumentAnalysis(document.getKey()); + for (Map.Entry> fieldEntry : document.getValue()) { FieldAnalysis fieldAnalysis = new FieldAnalysis(fieldEntry.getKey()); - NamedList field = (NamedList) fieldEntry.getValue(); - NamedList query = (NamedList) field.get("query"); + NamedList field = fieldEntry.getValue(); + + @SuppressWarnings("unchecked") + NamedList>> query + = (NamedList>>) field.get("query"); if (query != null) { List phases = buildPhases(query); fieldAnalysis.setQueryPhases(phases); } - - NamedList index = (NamedList) field.get("index"); - for (Map.Entry valueEntry : index) { + + @SuppressWarnings("unchecked") + NamedList>>> index + = (NamedList>>>) field.get("index"); + for (Map.Entry>>> valueEntry : index) { String fieldValue = valueEntry.getKey(); - NamedList valueNL = (NamedList) valueEntry.getValue(); + NamedList>> valueNL = valueEntry.getValue(); List phases = buildPhases(valueNL); fieldAnalysis.setIndexPhases(fieldValue, phases); } diff --git a/solr/src/solrj/org/apache/solr/client/solrj/response/FieldAnalysisResponse.java b/solr/src/solrj/org/apache/solr/client/solrj/response/FieldAnalysisResponse.java index 722c2c96cc8..e7343647db8 100644 --- a/solr/src/solrj/org/apache/solr/client/solrj/response/FieldAnalysisResponse.java +++ b/solr/src/solrj/org/apache/solr/client/solrj/response/FieldAnalysisResponse.java @@ -42,35 +42,35 @@ public class FieldAnalysisResponse extends AnalysisResponseBase { public void setResponse(NamedList response) { super.setResponse(response); - NamedList analysisNL = (NamedList) response.get("analysis"); + @SuppressWarnings("unchecked") + NamedList>>>>> analysisNL + = (NamedList>>>>>) response.get("analysis"); - NamedList fieldTypesNL = (NamedList) analysisNL.get("field_types"); - for (Map.Entry entry : fieldTypesNL) { - Analysis analysis = new Analysis(); - NamedList fieldTypeNL = (NamedList) entry.getValue(); - NamedList queryNL = (NamedList) fieldTypeNL.get("query"); - List phases = (queryNL == null) ? null : buildPhases(queryNL); - analysis.setQueryPhases(phases); - NamedList indexNL = (NamedList) fieldTypeNL.get("index"); - phases = buildPhases(indexNL); - analysis.setIndexPhases(phases); - String fieldTypeName = entry.getKey(); - analysisByFieldTypeName.put(fieldTypeName, analysis); + for (Map.Entry>>>> entry + : analysisNL.get("field_types")) { + + analysisByFieldTypeName.put(entry.getKey(), buildAnalysis(entry.getValue())); } - NamedList fieldNamesNL = (NamedList) analysisNL.get("field_names"); - for (Map.Entry entry : fieldNamesNL) { + for (Map.Entry>>>> entry + : analysisNL.get("field_names")) { + + analysisByFieldName.put(entry.getKey(), buildAnalysis(entry.getValue())); + } + } + + private Analysis buildAnalysis(NamedList>>> value) { Analysis analysis = new Analysis(); - NamedList fieldNameNL = (NamedList) entry.getValue(); - NamedList queryNL = (NamedList) fieldNameNL.get("query"); + + NamedList>> queryNL = value.get("query"); List phases = (queryNL == null) ? null : buildPhases(queryNL); analysis.setQueryPhases(phases); - NamedList indexNL = (NamedList) fieldNameNL.get("index"); + + NamedList>> indexNL = value.get("index"); phases = buildPhases(indexNL); analysis.setIndexPhases(phases); - String fieldName = entry.getKey(); - analysisByFieldName.put(fieldName, analysis); - } + + return analysis; } /**