mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 14:03:17 +00:00
[DS-707] Inefficient use of keySet iterators
git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5474 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -103,7 +103,7 @@ public interface BrowseCreateDAO
|
||||
* @param sortCols an Integer-String map of sort column numbers and values
|
||||
* @throws BrowseException
|
||||
*/
|
||||
public void insertIndex(String table, int itemID, Map sortCols) throws BrowseException;
|
||||
public void insertIndex(String table, int itemID, Map<Integer, String> sortCols) throws BrowseException;
|
||||
|
||||
/**
|
||||
* Updates an index record into the given table for the given item id. The Map should contain
|
||||
@@ -127,7 +127,7 @@ public interface BrowseCreateDAO
|
||||
* @return true if the record is updated, false if not found
|
||||
* @throws BrowseException
|
||||
*/
|
||||
public boolean updateIndex(String table, int itemID, Map sortCols) throws BrowseException;
|
||||
public boolean updateIndex(String table, int itemID, Map<Integer, String> sortCols) throws BrowseException;
|
||||
|
||||
/**
|
||||
* Get the browse index's internal id for the location of the given string
|
||||
|
@@ -688,7 +688,7 @@ public class BrowseCreateDAOOracle implements BrowseCreateDAO
|
||||
}
|
||||
}
|
||||
|
||||
public void insertIndex(String table, int itemID, Map sortCols)
|
||||
public void insertIndex(String table, int itemID, Map<Integer, String> sortCols)
|
||||
throws BrowseException
|
||||
{
|
||||
try
|
||||
@@ -700,12 +700,9 @@ public class BrowseCreateDAOOracle implements BrowseCreateDAO
|
||||
row.setColumn("item_id", itemID);
|
||||
|
||||
// now set the columns for the other sort values
|
||||
Iterator itra = sortCols.keySet().iterator();
|
||||
while (itra.hasNext())
|
||||
for (Map.Entry<Integer, String> sortCol : sortCols.entrySet())
|
||||
{
|
||||
Integer key = (Integer) itra.next();
|
||||
String nValue = (String) sortCols.get(key);
|
||||
row.setColumn("sort_" + key.toString(), utils.truncateSortValue(nValue));
|
||||
row.setColumn("sort_" + sortCol.getKey().toString(), utils.truncateSortValue(sortCol.getValue()));
|
||||
}
|
||||
|
||||
DatabaseManager.update(context, row);
|
||||
@@ -720,7 +717,7 @@ public class BrowseCreateDAOOracle implements BrowseCreateDAO
|
||||
/* (non-Javadoc)
|
||||
* @see org.dspace.browse.BrowseCreateDAO#updateIndex(java.lang.String, int, java.util.Map)
|
||||
*/
|
||||
public boolean updateIndex(String table, int itemID, Map sortCols)
|
||||
public boolean updateIndex(String table, int itemID, Map<Integer, String> sortCols)
|
||||
throws BrowseException
|
||||
{
|
||||
try
|
||||
@@ -733,16 +730,13 @@ public class BrowseCreateDAOOracle implements BrowseCreateDAO
|
||||
return false;
|
||||
|
||||
// Iterate through all the sort values
|
||||
Iterator itra = sortCols.keySet().iterator();
|
||||
while (itra.hasNext())
|
||||
for (Map.Entry<Integer, String> sortCol : sortCols.entrySet())
|
||||
{
|
||||
Integer key = (Integer) itra.next();
|
||||
|
||||
// Generate the appropriate column name
|
||||
String column = "sort_" + key.toString();
|
||||
String column = "sort_" + sortCol.getKey().toString();
|
||||
|
||||
// Create the value that will be written in to the column
|
||||
String newValue = utils.truncateSortValue( (String) sortCols.get(key) );
|
||||
String newValue = utils.truncateSortValue( sortCol.getValue() );
|
||||
|
||||
// Check the column exists - if it doesn't, something has gone seriously wrong
|
||||
if (!row.hasColumn(column))
|
||||
|
@@ -695,7 +695,7 @@ public class BrowseCreateDAOPostgres implements BrowseCreateDAO
|
||||
/* (non-Javadoc)
|
||||
* @see org.dspace.browse.BrowseCreateDAO#insertIndex(java.lang.String, int, java.lang.String, java.lang.String, java.util.Map)
|
||||
*/
|
||||
public void insertIndex(String table, int itemID, Map sortCols)
|
||||
public void insertIndex(String table, int itemID, Map<Integer, String> sortCols)
|
||||
throws BrowseException
|
||||
{
|
||||
try
|
||||
@@ -707,12 +707,9 @@ public class BrowseCreateDAOPostgres implements BrowseCreateDAO
|
||||
row.setColumn("item_id", itemID);
|
||||
|
||||
// now set the columns for the other sort values
|
||||
Iterator itra = sortCols.keySet().iterator();
|
||||
while (itra.hasNext())
|
||||
for (Map.Entry<Integer, String> sortCol : sortCols.entrySet())
|
||||
{
|
||||
Integer key = (Integer) itra.next();
|
||||
String nValue = (String) sortCols.get(key);
|
||||
row.setColumn("sort_" + key.toString(), utils.truncateSortValue(nValue));
|
||||
row.setColumn("sort_" + sortCol.getKey().toString(), utils.truncateSortValue(sortCol.getValue()));
|
||||
}
|
||||
|
||||
DatabaseManager.update(context, row);
|
||||
@@ -727,7 +724,7 @@ public class BrowseCreateDAOPostgres implements BrowseCreateDAO
|
||||
/* (non-Javadoc)
|
||||
* @see org.dspace.browse.BrowseCreateDAO#updateIndex(java.lang.String, int, java.util.Map)
|
||||
*/
|
||||
public boolean updateIndex(String table, int itemID, Map sortCols)
|
||||
public boolean updateIndex(String table, int itemID, Map<Integer, String> sortCols)
|
||||
throws BrowseException
|
||||
{
|
||||
try
|
||||
@@ -740,16 +737,13 @@ public class BrowseCreateDAOPostgres implements BrowseCreateDAO
|
||||
return false;
|
||||
|
||||
// Iterate through all the sort values
|
||||
Iterator itra = sortCols.keySet().iterator();
|
||||
while (itra.hasNext())
|
||||
for (Map.Entry<Integer, String> sortCol : sortCols.entrySet())
|
||||
{
|
||||
Integer key = (Integer) itra.next();
|
||||
|
||||
// Generate the appropriate column name
|
||||
String column = "sort_" + key.toString();
|
||||
String column = "sort_" + sortCol.getKey().toString();
|
||||
|
||||
// Create the value that will be written in to the column
|
||||
String newValue = utils.truncateSortValue( (String) sortCols.get(key) );
|
||||
String newValue = utils.truncateSortValue( sortCol.getValue() );
|
||||
|
||||
// Check the column exists - if it doesn't, something has gone seriously wrong
|
||||
if (!row.hasColumn(column))
|
||||
|
@@ -267,10 +267,10 @@ public class ChecksumHistoryDAO extends DAOSupport
|
||||
* @param interests
|
||||
* set of results and the duration of time before they are
|
||||
* removed from the database
|
||||
*
|
||||
*
|
||||
* @return number of bitstreams deleted
|
||||
*/
|
||||
public int prune(Map interests)
|
||||
public int prune(Map<String, Long> interests)
|
||||
{
|
||||
Connection conn = null;
|
||||
try
|
||||
@@ -278,12 +278,10 @@ public class ChecksumHistoryDAO extends DAOSupport
|
||||
conn = DatabaseManager.getConnection();
|
||||
long now = System.currentTimeMillis();
|
||||
int count = 0;
|
||||
for (Iterator iter = interests.keySet().iterator(); iter.hasNext();)
|
||||
for (Map.Entry<String, Long> interest : interests.entrySet())
|
||||
{
|
||||
String result = (String) iter.next();
|
||||
Long dur = (Long) interests.get(result);
|
||||
count += deleteHistoryByDateAndCode(new Date(now
|
||||
- dur.longValue()), result, conn);
|
||||
- interest.getValue().longValue()), interest.getKey(), conn);
|
||||
conn.commit();
|
||||
}
|
||||
return count;
|
||||
|
@@ -180,7 +180,7 @@ public final class ResultsPruner
|
||||
/**
|
||||
* Map of retention durations, keyed by result code name
|
||||
*/
|
||||
Map interests = new HashMap();
|
||||
Map<String, Long> interests = new HashMap<String, Long>();
|
||||
|
||||
/**
|
||||
* Checksum results database Data access
|
||||
|
@@ -70,11 +70,10 @@ public class LicenseUtils
|
||||
|
||||
if (additionalInfo != null)
|
||||
{
|
||||
int i = 1;
|
||||
for (String key : additionalInfo.keySet())
|
||||
int i = 7; // Start is next index after previous args
|
||||
for (Map.Entry<String, Object> info : additionalInfo.entrySet())
|
||||
{
|
||||
args[6 + i] = new FormattableArgument(key, additionalInfo
|
||||
.get(key));
|
||||
args[i] = new FormattableArgument(info.getKey(), info.getValue());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@@ -1255,23 +1255,10 @@ public class Group extends DSpaceObject
|
||||
// so now to establish all parent,child relationships we can iterate
|
||||
// through the parents hash
|
||||
|
||||
Iterator<Integer> i = parents.keySet().iterator();
|
||||
|
||||
while (i.hasNext())
|
||||
for (Map.Entry<Integer, Set<Integer>> parent : parents.entrySet())
|
||||
{
|
||||
Integer parentID = i.next();
|
||||
|
||||
Set<Integer> myChildren = getChildren(parents, parentID);
|
||||
|
||||
Iterator<Integer> j = myChildren.iterator();
|
||||
|
||||
while (j.hasNext())
|
||||
{
|
||||
// child of a parent
|
||||
Integer childID = j.next();
|
||||
|
||||
((Set<Integer>) parents.get(parentID)).add(childID);
|
||||
}
|
||||
Set<Integer> myChildren = getChildren(parents, parent.getKey());
|
||||
parent.getValue().addAll(myChildren);
|
||||
}
|
||||
|
||||
// empty out group2groupcache table
|
||||
|
@@ -44,6 +44,7 @@ import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -342,33 +343,30 @@ public class QueryArgs
|
||||
*
|
||||
* @return the created HashMap
|
||||
*/
|
||||
public HashMap buildQueryHash(HttpServletRequest request)
|
||||
public Map<String, String> buildQueryMap(HttpServletRequest request)
|
||||
{
|
||||
HashMap queryHash = new HashMap();
|
||||
Map<String, String> queryMap = new HashMap<String, String>();
|
||||
String numFieldStr = request.getParameter("num_search_field");
|
||||
// for backward compatibility
|
||||
if (numFieldStr == null) numFieldStr = "3";
|
||||
int numField = Integer.parseInt(numFieldStr);
|
||||
for (int i = 1; i < numField; i++)
|
||||
{
|
||||
queryHash.put("query"+i, (request.getParameter("query"+i) == null) ? ""
|
||||
: request.getParameter("query"+i));
|
||||
queryHash.put("field"+i,
|
||||
(request.getParameter("field"+i) == null) ? "ANY" : request
|
||||
.getParameter("field"+i));
|
||||
queryHash.put("conjunction"+i,
|
||||
(request.getParameter("conjunction"+i) == null) ? "AND"
|
||||
: request.getParameter("conjunction"+i));
|
||||
String queryStr = "query" + i;
|
||||
String fieldStr = "field" + i;
|
||||
String conjunctionStr = "conjunction" + i;
|
||||
|
||||
queryMap.put(queryStr, StringUtils.defaultString(request.getParameter(queryStr), ""));
|
||||
queryMap.put(fieldStr, StringUtils.defaultString(request.getParameter(fieldStr), "ANY"));
|
||||
queryMap.put(conjunctionStr, StringUtils.defaultString(request.getParameter(conjunctionStr), "AND"));
|
||||
}
|
||||
|
||||
queryHash.put("query"+numField, (request.getParameter("query"+numField) == null) ? ""
|
||||
: request.getParameter("query"+numField));
|
||||
String queryStr = "query" + numField;
|
||||
String fieldStr = "field" + numField;
|
||||
queryMap.put(queryStr, StringUtils.defaultString(request.getParameter(queryStr), ""));
|
||||
queryMap.put(fieldStr, StringUtils.defaultString(request.getParameter(fieldStr), "ANY"));
|
||||
|
||||
queryHash.put("field"+numField,
|
||||
(request.getParameter("field"+numField) == null) ? "ANY"
|
||||
: request.getParameter("field"+numField));
|
||||
|
||||
return (queryHash);
|
||||
return (queryMap);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -396,25 +394,23 @@ public class QueryArgs
|
||||
public String buildHTTPQuery(HttpServletRequest request)
|
||||
throws UnsupportedEncodingException
|
||||
{
|
||||
String querystring = "";
|
||||
HashMap queryHash = buildQueryHash(request);
|
||||
StringBuilder queryString = new StringBuilder();
|
||||
Map<String, String> queryMap = buildQueryMap(request);
|
||||
|
||||
Iterator i = queryHash.keySet().iterator();
|
||||
|
||||
while (i.hasNext())
|
||||
for (Map.Entry<String, String> query : queryMap.entrySet())
|
||||
{
|
||||
String key = (String) i.next();
|
||||
String value = (String) queryHash.get(key);
|
||||
|
||||
querystring = querystring + "&" + key + "="
|
||||
+ URLEncoder.encode(value, Constants.DEFAULT_ENCODING);
|
||||
queryString.append("&")
|
||||
.append(query.getKey())
|
||||
.append("=")
|
||||
.append(URLEncoder.encode(query.getValue(), Constants.DEFAULT_ENCODING));
|
||||
}
|
||||
|
||||
if (request.getParameter("num_search_field") != null)
|
||||
{
|
||||
querystring = querystring + "&num_search_field="+request.getParameter("num_search_field");
|
||||
}
|
||||
queryString.append("&num_search_field=").append(request.getParameter("num_search_field"));
|
||||
}
|
||||
|
||||
// return the result with the leading "&" removed
|
||||
return (querystring.substring(1));
|
||||
return queryString.substring(1);
|
||||
}
|
||||
}
|
||||
|
@@ -259,7 +259,7 @@ public class MARC21InitialArticleWord extends InitialArticleWord
|
||||
|
||||
// Iterate through word/language array
|
||||
// Generate temporary language map
|
||||
Map langWordMap = new HashMap();
|
||||
Map<Language, List> langWordMap = new HashMap<Language, List>();
|
||||
for (wordIdx = 0; wordIdx < articleWordArray.length; wordIdx++)
|
||||
{
|
||||
for (langIdx = 1; langIdx < articleWordArray[wordIdx].length; langIdx++)
|
||||
@@ -268,7 +268,7 @@ public class MARC21InitialArticleWord extends InitialArticleWord
|
||||
|
||||
if (lang != null && lang.IANA.length() > 0)
|
||||
{
|
||||
List words = (List)langWordMap.get(lang);
|
||||
List words = langWordMap.get(lang);
|
||||
|
||||
if (words == null)
|
||||
{
|
||||
@@ -284,22 +284,21 @@ public class MARC21InitialArticleWord extends InitialArticleWord
|
||||
}
|
||||
|
||||
// Iterate through languages
|
||||
Iterator langIter = langWordMap.keySet().iterator();
|
||||
while (langIter.hasNext())
|
||||
for (Map.Entry<Language, List> langToWord : langWordMap.entrySet())
|
||||
{
|
||||
Language lang = (Language)langIter.next();
|
||||
List wordList = (List)langWordMap.get(lang);
|
||||
Language lang = langToWord.getKey();
|
||||
List wordList = langToWord.getValue();
|
||||
|
||||
// Convert the list into an array of strings
|
||||
String[] words = new String[wordList.size()];
|
||||
|
||||
|
||||
for (int idx = 0; idx < wordList.size(); idx++)
|
||||
words[idx] = (String)wordList.get(idx);
|
||||
|
||||
// Sort the array into length order - longest to shortest
|
||||
// This ensures maximal matching on the article words
|
||||
Arrays.sort(words, new MARC21InitialArticleWord.InverseLengthComparator() );
|
||||
|
||||
|
||||
// Add language/article entry to map
|
||||
ianaArticleMap.put(lang.IANA, new MARC21InitialArticleWord.ArticlesForLang(lang, words));
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -71,7 +71,6 @@ import org.dspace.search.DSQuery;
|
||||
import org.dspace.search.QueryArgs;
|
||||
import org.dspace.search.QueryResults;
|
||||
import org.dspace.sort.SortOption;
|
||||
import org.dspace.browse.*;
|
||||
|
||||
/**
|
||||
* Servlet for handling a simple search.
|
||||
@@ -108,7 +107,7 @@ public class SimpleSearchServlet extends DSpaceServlet
|
||||
String order = request.getParameter("order");
|
||||
int rpp = UIUtil.getIntParameter(request, "rpp");
|
||||
String advancedQuery = "";
|
||||
HashMap queryHash = new HashMap();
|
||||
Map<String, String> queryHash = new HashMap<String, String>();
|
||||
|
||||
// can't start earlier than 0 in the results!
|
||||
if (start < 0)
|
||||
@@ -402,7 +401,7 @@ public class SimpleSearchServlet extends DSpaceServlet
|
||||
request.setAttribute("communities", communities);
|
||||
request.setAttribute("no_results", "yes");
|
||||
|
||||
queryHash = qArgs.buildQueryHash(request);
|
||||
queryHash = qArgs.buildQueryMap(request);
|
||||
|
||||
Iterator i = queryHash.keySet().iterator();
|
||||
|
||||
|
Reference in New Issue
Block a user