C
cbongior
I would like to create a class that inherits from a TreeMap and somehow
(for autoboxing, iterating and other typing purposes related to 1.5)
tell the compiler that map backing this class what types it contains.
Here is the code -- I think you will see what I mean. Specifically to
avoid this UGLY syntax: List<SearchResult> results =
(List<SearchResult>)super.get(fieldName);
What is the syntax for telling 'super' what types it will contain?
Christian
private static class SearchResults extends TreeMap{
private List<Long> recNums = new ArrayList<Long>();
public void addResult(String fieldName,SearchResult res) {
List<SearchResult> results = (List<SearchResult>)
super.get(fieldName);
if(results == null)
results = new ArrayList<SearchResult>();
results.add(res);
super.put(fieldName,res);
recNums.add(res.getRecordNumber());
}
public void addResult(Field f,String criteria,Record r) {
addResult(f.getName(),new SearchResult(f,criteria,r));
}
public long[] getRecordNumbers() {
int i = 0;
long[] retVal = new long[recNums.size()];
for (Long rec : recNums)
retVal[i++] = rec;
return retVal;
}
}
(for autoboxing, iterating and other typing purposes related to 1.5)
tell the compiler that map backing this class what types it contains.
Here is the code -- I think you will see what I mean. Specifically to
avoid this UGLY syntax: List<SearchResult> results =
(List<SearchResult>)super.get(fieldName);
What is the syntax for telling 'super' what types it will contain?
Christian
private static class SearchResults extends TreeMap{
private List<Long> recNums = new ArrayList<Long>();
public void addResult(String fieldName,SearchResult res) {
List<SearchResult> results = (List<SearchResult>)
super.get(fieldName);
if(results == null)
results = new ArrayList<SearchResult>();
results.add(res);
super.put(fieldName,res);
recNums.add(res.getRecordNumber());
}
public void addResult(Field f,String criteria,Record r) {
addResult(f.getName(),new SearchResult(f,criteria,r));
}
public long[] getRecordNumbers() {
int i = 0;
long[] retVal = new long[recNums.size()];
for (Long rec : recNums)
retVal[i++] = rec;
return retVal;
}
}