SOLR-2288: more small tweaks to eliminate compiler warnings

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1056578 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2011-01-08 00:59:11 +00:00
parent 44b5ae0b69
commit cd90c9a911
7 changed files with 50 additions and 36 deletions

View File

@ -20,6 +20,8 @@ import org.apache.lucene.util.PriorityQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeSet;
@ -182,6 +184,7 @@ public class ConcurrentLRUCache<K,V> {
int wantToKeep = lowerWaterMark;
int wantToRemove = sz - lowerWaterMark;
@SuppressWarnings("unchecked") // generic array's are anoying
CacheEntry<K,V>[] eset = new CacheEntry[sz];
int eSize = 0;
@ -280,7 +283,7 @@ public class ConcurrentLRUCache<K,V> {
wantToKeep = lowerWaterMark - numKept;
wantToRemove = sz - lowerWaterMark - numRemoved;
PQueue queue = new PQueue(wantToRemove);
PQueue<K,V> queue = new PQueue<K,V>(wantToRemove);
for (int i=eSize-1; i>=0; i--) {
CacheEntry<K,V> ce = eset[i];
@ -331,9 +334,8 @@ public class ConcurrentLRUCache<K,V> {
// Now delete everything in the priority queue.
// avoid using pop() since order doesn't matter anymore
for (Object o : queue.getValues()) {
if (o==null) continue;
CacheEntry<K,V> ce = (CacheEntry)o;
for (CacheEntry<K,V> ce : queue.getValues()) {
if (ce==null) continue;
evictEntry(ce.key);
numRemoved++;
}
@ -349,27 +351,29 @@ public class ConcurrentLRUCache<K,V> {
}
}
private static class PQueue extends PriorityQueue {
private static class PQueue<K,V> extends PriorityQueue<CacheEntry<K,V>> {
int myMaxSize;
PQueue(int maxSz) {
super.initialize(maxSz);
myMaxSize = maxSz;
}
Object[] getValues() { return heap; }
Iterable<CacheEntry<K,V>> getValues() {
return Collections.unmodifiableCollection(Arrays.asList(heap));
}
protected boolean lessThan(Object a, Object b) {
protected boolean lessThan(CacheEntry a, CacheEntry b) {
// reverse the parameter order so that the queue keeps the oldest items
return ((CacheEntry)b).lastAccessedCopy < ((CacheEntry)a).lastAccessedCopy;
return b.lastAccessedCopy < a.lastAccessedCopy;
}
// necessary because maxSize is private in base class
public Object myInsertWithOverflow(Object element) {
public CacheEntry<K,V> myInsertWithOverflow(CacheEntry<K,V> element) {
if (size() < myMaxSize) {
add(element);
return null;
} else if (size() > 0 && !lessThan(element, heap[1])) {
Object ret = heap[1];
CacheEntry<K,V> ret = heap[1];
heap[1] = element;
updateTop();
return ret;
@ -400,11 +404,11 @@ public class ConcurrentLRUCache<K,V> {
Map<K, V> result = new LinkedHashMap<K, V>();
if (n <= 0)
return result;
TreeSet<CacheEntry> tree = new TreeSet<CacheEntry>();
TreeSet<CacheEntry<K,V>> tree = new TreeSet<CacheEntry<K,V>>();
markAndSweepLock.lock();
try {
for (Map.Entry<Object, CacheEntry<K,V>> entry : map.entrySet()) {
CacheEntry ce = entry.getValue();
CacheEntry<K,V> ce = entry.getValue();
ce.lastAccessedCopy = ce.lastAccessed;
if (tree.size() < n) {
tree.add(ce);
@ -418,7 +422,7 @@ public class ConcurrentLRUCache<K,V> {
} finally {
markAndSweepLock.unlock();
}
for (CacheEntry<K, V> e : tree) {
for (CacheEntry<K,V> e : tree) {
result.put(e.key, e.value);
}
return result;
@ -428,7 +432,7 @@ public class ConcurrentLRUCache<K,V> {
Map<K,V> result = new LinkedHashMap<K,V>();
if (n <= 0)
return result;
TreeSet<CacheEntry> tree = new TreeSet<CacheEntry>();
TreeSet<CacheEntry<K,V>> tree = new TreeSet<CacheEntry<K,V>>();
// we need to grab the lock since we are changing lastAccessedCopy
markAndSweepLock.lock();
try {

View File

@ -50,7 +50,7 @@ public class SimpleOrderedMap<T> extends NamedList<T> {
* @param nameValuePairs underlying List which should be used to implement a SimpleOrderedMap; modifying this List will affect the SimpleOrderedMap.
*/
@Deprecated
public SimpleOrderedMap(List nameValuePairs) {
public SimpleOrderedMap(List<Object> nameValuePairs) {
super(nameValuePairs);
}
@ -60,7 +60,7 @@ public class SimpleOrderedMap<T> extends NamedList<T> {
@Override
public SimpleOrderedMap<T> clone() {
ArrayList newList = new ArrayList(nvPairs.size());
ArrayList<Object> newList = new ArrayList<Object>(nvPairs.size());
newList.addAll(nvPairs);
return new SimpleOrderedMap<T>(newList);
}

View File

@ -274,7 +274,7 @@ public class TermsComponent extends SearchComponent {
if (th != null) {
for (ShardResponse srsp : sreq.responses) {
@SuppressWarnings("unchecked")
NamedList<Object> terms = (NamedList<Object>) srsp.getSolrResponse().getResponse().get("terms");
NamedList<NamedList<Number>> terms = (NamedList<NamedList<Number>>) srsp.getSolrResponse().getResponse().get("terms");
th.parse(terms);
}
}
@ -333,7 +333,7 @@ public class TermsComponent extends SearchComponent {
}
}
public void parse(NamedList<Object> terms) {
public void parse(NamedList<NamedList<Number>> terms) {
// exit if there is no terms
if (terms == null) {
return;

View File

@ -74,11 +74,13 @@ public class FieldStatsInfo implements Serializable {
stddev = (Double)entry.getValue();
}
else if( "facets".equals( entry.getKey() ) ) {
@SuppressWarnings("unchecked")
NamedList<Object> fields = (NamedList<Object>)entry.getValue();
facets = new HashMap<String, List<FieldStatsInfo>>();
for( Map.Entry<String, Object> ev : fields ) {
List<FieldStatsInfo> vals = new ArrayList<FieldStatsInfo>();
facets.put( ev.getKey(), vals );
@SuppressWarnings("unchecked")
NamedList<NamedList<Object>> vnl = (NamedList<NamedList<Object>>) ev.getValue();
for( int i=0; i<vnl.size(); i++ ) {
String n = vnl.getName(i);

View File

@ -44,9 +44,9 @@ public class QueryResponse extends SolrResponseBase
private NamedList<Object> _facetInfo = null;
private NamedList<Object> _debugInfo = null;
private NamedList<Object> _highlightingInfo = null;
private NamedList<Object> _spellInfo = null;
private NamedList<NamedList<Object>> _spellInfo = null;
private NamedList<Object> _statsInfo = null;
private NamedList<Object> _termsInfo = null;
private NamedList<NamedList<Number>> _termsInfo = null;
// Facet stuff
private Map<String,Integer> _facetQuery = null;
@ -116,7 +116,7 @@ public class QueryResponse extends SolrResponseBase
extractHighlightingInfo( _highlightingInfo );
}
else if ( "spellcheck".equals( n ) ) {
_spellInfo = (NamedList<Object>) res.getVal( i );
_spellInfo = (NamedList<NamedList<Object>>) res.getVal( i );
extractSpellCheckInfo( _spellInfo );
}
else if ( "stats".equals( n ) ) {
@ -124,17 +124,17 @@ public class QueryResponse extends SolrResponseBase
extractStatsInfo( _statsInfo );
}
else if ( "terms".equals( n ) ) {
_termsInfo = (NamedList<Object>) res.getVal( i );
_termsInfo = (NamedList<NamedList<Number>>) res.getVal( i );
extractTermsInfo( _termsInfo );
}
}
}
private void extractSpellCheckInfo(NamedList<Object> spellInfo) {
private void extractSpellCheckInfo(NamedList<NamedList<Object>> spellInfo) {
_spellResponse = new SpellCheckResponse(spellInfo);
}
private void extractTermsInfo(NamedList<Object> termsInfo) {
private void extractTermsInfo(NamedList<NamedList<Number>> termsInfo) {
_termsResponse = new TermsResponse(termsInfo);
}

View File

@ -35,8 +35,8 @@ public class SpellCheckResponse {
private List<Suggestion> suggestions = new ArrayList<Suggestion>();
Map<String, Suggestion> suggestionMap = new LinkedHashMap<String, Suggestion>();
public SpellCheckResponse(NamedList<Object> spellInfo) {
NamedList<Object> sugg = (NamedList<Object>) spellInfo.get("suggestions");
public SpellCheckResponse(NamedList<NamedList<Object>> spellInfo) {
NamedList<Object> sugg = spellInfo.get("suggestions");
if (sugg == null) {
correctlySpelled = true;
return;
@ -55,12 +55,14 @@ public class SpellCheckResponse {
collations.add(new Collation()
.setCollationQueryString((String) sugg.getVal(i)));
} else if (o instanceof NamedList) {
NamedList expandedCollation = (NamedList) o;
String collationQuery = (String) expandedCollation
.get("collationQuery");
@SuppressWarnings("unchecked")
NamedList<Object> expandedCollation = (NamedList<Object>) o;
String collationQuery
= (String) expandedCollation.get("collationQuery");
int hits = (Integer) expandedCollation.get("hits");
NamedList<String> misspellingsAndCorrections = (NamedList<String>) expandedCollation
.get("misspellingsAndCorrections");
@SuppressWarnings("unchecked")
NamedList<String> misspellingsAndCorrections
= (NamedList<String>) expandedCollation.get("misspellingsAndCorrections");
Collation collation = new Collation();
collation.setCollationQueryString(collationQuery);
@ -79,6 +81,7 @@ public class SpellCheckResponse {
}
}
} else {
@SuppressWarnings("unchecked")
Suggestion s = new Suggestion(n, (NamedList<Object>) sugg.getVal(i));
suggestionMap.put(n, s);
suggestions.add(s);
@ -152,16 +155,21 @@ public class SpellCheckResponse {
} else if ("origFreq".equals(n)) {
originalFrequency = (Integer) suggestion.getVal(i);
} else if ("suggestion".equals(n)) {
@SuppressWarnings("unchecked")
List list = (List)suggestion.getVal(i);
if (list.size() > 0 && list.get(0) instanceof NamedList) {
// extended results detected
@SuppressWarnings("unchecked")
List<NamedList> extended = (List<NamedList>)list;
alternativeFrequencies = new ArrayList<Integer>();
for (NamedList nl : (List<NamedList>)list) {
for (NamedList nl : extended) {
alternatives.add((String)nl.get("word"));
alternativeFrequencies.add((Integer)nl.get("freq"));
}
} else {
alternatives.addAll(list);
@SuppressWarnings("unchecked")
List<String> alts = (List<String>) list;
alternatives.addAll(alts);
}
}
}

View File

@ -29,14 +29,14 @@ import java.util.Map;
public class TermsResponse {
private Map<String, List<Term>> termMap = new HashMap<String, List<Term>>();
public TermsResponse(NamedList<Object> termsInfo) {
public TermsResponse(NamedList<NamedList<Number>> termsInfo) {
for (int i = 0; i < termsInfo.size(); i++) {
String fieldName = termsInfo.getName(i);
List<Term> itemList = new ArrayList<Term>();
NamedList<Object> items = (NamedList<Object>) termsInfo.getVal(i);
NamedList<Number> items = termsInfo.getVal(i);
for (int j = 0; j < items.size(); j++) {
Term t = new Term(items.getName(j), ((Number) items.getVal(j)).longValue());
Term t = new Term(items.getName(j), items.getVal(j).longValue());
itemList.add(t);
}