From: <bra...@us...> - 2008-07-01 23:16:37
|
Revision: 2351 http://archive-access.svn.sourceforge.net/archive-access/?rev=2351&view=rev Author: bradtofel Date: 2008-07-01 16:16:44 -0700 (Tue, 01 Jul 2008) Log Message: ----------- REFACTOR: now these classes are directly aware of the type of SearchResult they contain. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/CaptureSearchResults.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UrlSearchResults.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/CaptureSearchResults.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/CaptureSearchResults.java 2008-07-01 23:16:20 UTC (rev 2350) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/CaptureSearchResults.java 2008-07-01 23:16:44 UTC (rev 2351) @@ -24,7 +24,8 @@ */ package org.archive.wayback.core; -import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; import java.util.Iterator; import org.archive.wayback.WaybackConstants; @@ -36,62 +37,113 @@ * @version $Date$, $Revision$ */ public class CaptureSearchResults extends SearchResults { - public String getResultsType() { - return WaybackConstants.RESULTS_TYPE_CAPTURE; + /** + * List of UrlSearchResult objects for index records matching a query + */ + private ArrayList<CaptureSearchResult> results = + new ArrayList<CaptureSearchResult>(); + /** + * 14-digit timestamp of first capture date contained in the SearchResults + */ + private String firstResultTimestamp; + + /** + * 14-digit timestamp of last capture date contained in the SearchResults + */ + private String lastResultTimestamp; + + /** + * @return Returns the 14-digit String Timestamp of the first Capture in + * this set of SearchResult objects + */ + public String getFirstResultTimestamp() { + return firstResultTimestamp; } /** - * append a result - * @param result + * @return Returns the firstResult Date. */ - public void addSearchResult(final SearchResult result) { - addSearchResult(result,true); + public Date getFirstResultDate() { + return new Timestamp(firstResultTimestamp).getDate(); } + /** - * add a result to this results, at either the begginning or at the end, - * depending on the append argument - * @param result - * SearchResult to add to this set - * @param append + * @return Returns the 14-digit String Timestamp of the last Capture in + * this set of SearchResult objects */ - public void addSearchResult(final SearchResult result, final boolean append) { - String resultDate = result.get(WaybackConstants.RESULT_CAPTURE_DATE); - if((firstResultDate == null) || - (firstResultDate.compareTo(resultDate) > 0)) { - firstResultDate = resultDate; - } - if((lastResultDate == null) || - (lastResultDate.compareTo(resultDate) < 0)) { - lastResultDate = resultDate; - } - addSearchResultRaw(result,append); + public String getLastResultTimestamp() { + return lastResultTimestamp; } + + public Date getLastResultDate() { + return new Timestamp(lastResultTimestamp).getDate(); + } + /** * @param wbRequest - * @return The closest SearchResult to the request. - * @throws ParseException + * @return The closest CaptureSearchResult to the request. */ - public SearchResult getClosest(WaybackRequest wbRequest) { + public CaptureSearchResult getClosest(WaybackRequest wbRequest) { - SearchResult closest = null; + CaptureSearchResult closest = null; long closestDistance = 0; - SearchResult cur = null; - Timestamp wantTimestamp; - wantTimestamp = Timestamp.parseBefore(wbRequest - .get(WaybackConstants.REQUEST_EXACT_DATE)); + CaptureSearchResult cur = null; + long wantTime = Timestamp.parseBefore(wbRequest + .get(WaybackConstants.REQUEST_EXACT_DATE)).getDate().getTime(); - Iterator<SearchResult> itr = results.iterator(); + Iterator<CaptureSearchResult> itr = results.iterator(); while (itr.hasNext()) { cur = itr.next(); - long curDistance; - Timestamp curTimestamp = Timestamp.parseBefore(cur - .get(WaybackConstants.RESULT_CAPTURE_DATE)); - curDistance = curTimestamp.absDistanceFromTimestamp(wantTimestamp); - + long curDistance = Math.abs(wantTime - + cur.getCaptureDate().getTime()); + if ((closest == null) || (curDistance < closestDistance)) { closest = cur; closestDistance = curDistance; } } return closest; + } + /** + * append a result + * @param result + */ + public void addSearchResult(CaptureSearchResult result) { + addSearchResult(result,true); + } + /** + * add a result to this results, at either the begginning or at the end, + * depending on the append argument + * @param result + * SearchResult to add to this set + * @param append + */ + public void addSearchResult(CaptureSearchResult result, boolean append) { + String resultDate = result.getCaptureTimestamp(); + if((firstResultTimestamp == null) || + (firstResultTimestamp.compareTo(resultDate) > 0)) { + firstResultTimestamp = resultDate; + } + if((lastResultTimestamp == null) || + (lastResultTimestamp.compareTo(resultDate) < 0)) { + lastResultTimestamp = resultDate; + } + + if(append) { + results.add(result); + } else { + results.add(0,result); + } } + + public boolean isEmpty() { + return results.isEmpty(); + } + + public Iterator<CaptureSearchResult> iterator() { + return results.iterator(); + } + + public int size() { + return results.size(); + } } Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UrlSearchResults.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UrlSearchResults.java 2008-07-01 23:16:20 UTC (rev 2350) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UrlSearchResults.java 2008-07-01 23:16:44 UTC (rev 2351) @@ -24,7 +24,8 @@ */ package org.archive.wayback.core; -import org.archive.wayback.WaybackConstants; +import java.util.ArrayList; +import java.util.Iterator; /** * @@ -33,19 +34,33 @@ * @version $Date$, $Revision$ */ public class UrlSearchResults extends SearchResults { + /** + * List of UrlSearchResult objects for index records matching a query + */ + private ArrayList<UrlSearchResult> results = + new ArrayList<UrlSearchResult>(); - public String getResultsType() { - return WaybackConstants.RESULTS_TYPE_URL; - } - public void addSearchResult(SearchResult result) { + public void addSearchResult(UrlSearchResult result) { addSearchResult(result,true); } - /* (non-Javadoc) - * @see org.archive.wayback.core.SearchResults#addSearchResult(org.archive.wayback.core.SearchResult, boolean) - */ - @Override - public void addSearchResult(SearchResult result, boolean append) { - addSearchResultRaw(result,append); + public void addSearchResult(UrlSearchResult result, boolean append) { + if(append) { + results.add(result); + } else { + results.add(0,result); + } } + + public boolean isEmpty() { + return results.isEmpty(); + } + + public Iterator<UrlSearchResult> iterator() { + return results.iterator(); + } + + public int size() { + return results.size(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |