//# 2 errors, 113 messages
//#
/*
    //#searchresults.java:1:1: class: net.sourceforge.pebble.search.SearchResults
    //#searchresults.java:1:1: method: net.sourceforge.pebble.search.SearchResults.net.sourceforge.pebble.search.SearchResults__static_init
 * Copyright (c) 2003-2006, Simon Brown
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   - Neither the name of Pebble nor the names of its contributors may
 *     be used to endorse or promote products derived from this software
 *     without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package net.sourceforge.pebble.search;

import net.sourceforge.pebble.comparator.SearchHitByDateComparator;
import net.sourceforge.pebble.comparator.SearchHitByScoreComparator;
import net.sourceforge.pebble.util.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
 * A container for the results (hits) of a search.
 *
 * @author    Simon Brown
 */
public class SearchResults {
    //#searchresults.java:48: method: void net.sourceforge.pebble.search.SearchResults.net.sourceforge.pebble.search.SearchResults()
    //#input(void net.sourceforge.pebble.search.SearchResults()): this
    //#output(void net.sourceforge.pebble.search.SearchResults()): new ArrayList(SearchResults#1) num objects
    //#output(void net.sourceforge.pebble.search.SearchResults()): this.hits
    //#new obj(void net.sourceforge.pebble.search.SearchResults()): new ArrayList(SearchResults#1)
    //#post(void net.sourceforge.pebble.search.SearchResults()): this.hits == &new ArrayList(SearchResults#1)
    //#post(void net.sourceforge.pebble.search.SearchResults()): new ArrayList(SearchResults#1) num objects == 1

  /** the original query */
  private String query;

  /** an optional message */
  private String message;

  /** the collection of search results */
  private List hits = new ArrayList();
    //#searchresults.java:57: end of method: void net.sourceforge.pebble.search.SearchResults.net.sourceforge.pebble.search.SearchResults()

  /**
   * Gets the query that was used to generate these results.
   *
   * @return  the original query
   */
  public String getQuery() {
    return this.query;
    //#searchresults.java:65: method: String net.sourceforge.pebble.search.SearchResults.getQuery()
    //#input(String getQuery()): this
    //#input(String getQuery()): this.query
    //#output(String getQuery()): return_value
    //#pre[2] (String getQuery()): init'ed(this.query)
    //#post(String getQuery()): return_value == this.query
    //#post(String getQuery()): init'ed(return_value)
    //#searchresults.java:65: end of method: String net.sourceforge.pebble.search.SearchResults.getQuery()
  }

  /**
   * Sets the query that was used to generate these results.
   *
   * @param s   the original query
   */
  public void setQuery(String s) {
    this.query = StringUtils.transformHTML(s);
    //#searchresults.java:74: method: void net.sourceforge.pebble.search.SearchResults.setQuery(String)
    //#input(void setQuery(String)): s
    //#input(void setQuery(String)): this
    //#output(void setQuery(String)): this.query
    //#post(void setQuery(String)): init'ed(this.query)
    //#unanalyzed(void setQuery(String)): Effects-of-calling:java.lang.String:length
    //#unanalyzed(void setQuery(String)): Effects-of-calling:java.lang.StringBuffer
    //#unanalyzed(void setQuery(String)): Effects-of-calling:java.lang.String:charAt
    //#unanalyzed(void setQuery(String)): Effects-of-calling:java.lang.StringBuffer:append
    //#unanalyzed(void setQuery(String)): Effects-of-calling:java.lang.StringBuffer:toString
  }
    //#searchresults.java:75: end of method: void net.sourceforge.pebble.search.SearchResults.setQuery(String)

  /**
   * Gets the message associated with these results. This may contain
   * information or an error message.
   *
   * @return  the message (can be null)
   */
  public String getMessage() {
    return this.message;
    //#searchresults.java:84: method: String net.sourceforge.pebble.search.SearchResults.getMessage()
    //#input(String getMessage()): this
    //#input(String getMessage()): this.message
    //#output(String getMessage()): return_value
    //#pre[2] (String getMessage()): init'ed(this.message)
    //#post(String getMessage()): return_value == this.message
    //#post(String getMessage()): init'ed(return_value)
    //#searchresults.java:84: end of method: String net.sourceforge.pebble.search.SearchResults.getMessage()
  }

  /**
   * Gets the message associated with these results. This may contain
   * information or an error message.
   *
   * @param s   the message (can be null)
   */
  public void setMessage(String s) {
    this.message = s;
    //#searchresults.java:94: method: void net.sourceforge.pebble.search.SearchResults.setMessage(String)
    //#input(void setMessage(String)): s
    //#input(void setMessage(String)): this
    //#output(void setMessage(String)): this.message
    //#post(void setMessage(String)): this.message == s
    //#post(void setMessage(String)): init'ed(this.message)
  }
    //#searchresults.java:95: end of method: void net.sourceforge.pebble.search.SearchResults.setMessage(String)

  /**
   * Adds a hit to the collection of hits.
   *
   * @param hit   a SearchHit instance
   */
  public void add(SearchHit hit) {
    hits.add(hit);
    //#searchresults.java:103: method: void net.sourceforge.pebble.search.SearchResults.add(SearchHit)
    //#input(void add(SearchHit)): hit
    //#input(void add(SearchHit)): this
    //#input(void add(SearchHit)): this.hits
    //#pre[3] (void add(SearchHit)): this.hits != null
  }
    //#searchresults.java:104: end of method: void net.sourceforge.pebble.search.SearchResults.add(SearchHit)

  /**
   * Gets the number of hits that the query returned.
   *
   * @return  the number of hits as an int
   */
  public int getNumberOfHits() {
    return hits.size();
    //#searchresults.java:112: method: int net.sourceforge.pebble.search.SearchResults.getNumberOfHits()
    //#input(int getNumberOfHits()): this
    //#input(int getNumberOfHits()): this.hits
    //#output(int getNumberOfHits()): return_value
    //#pre[2] (int getNumberOfHits()): this.hits != null
    //#post(int getNumberOfHits()): init'ed(return_value)
    //#searchresults.java:112: end of method: int net.sourceforge.pebble.search.SearchResults.getNumberOfHits()
  }

  /**
   * Gets a collection containing all of the hits.
   *
   * @return  a Collection of SearchHit instances
   */
  public List getHits() {
    return this.hits;
    //#searchresults.java:121: method: List net.sourceforge.pebble.search.SearchResults.getHits()
    //#input(List getHits()): this
    //#input(List getHits()): this.hits
    //#output(List getHits()): return_value
    //#pre[2] (List getHits()): init'ed(this.hits)
    //#post(List getHits()): return_value == this.hits
    //#post(List getHits()): init'ed(return_value)
    //#searchresults.java:121: end of method: List net.sourceforge.pebble.search.SearchResults.getHits()
  }

  /**
   * Sorts the search results by score, in reverse order.
   */
  public void sortByScoreDescending() {
    Collections.sort(hits, new SearchHitByScoreComparator());
    //#searchresults.java:128: method: void net.sourceforge.pebble.search.SearchResults.sortByScoreDescending()
    //#searchresults.java:128: Warning: method not available
    //#    -- call on void net.sourceforge.pebble.comparator.SearchHitByScoreComparator()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.search.SearchResults
    //#    method: void sortByScoreDescending()
    //#    unanalyzed callee: void net.sourceforge.pebble.comparator.SearchHitByScoreComparator()
    //#input(void sortByScoreDescending()): net/sourceforge/pebble/search/SearchHit.__Descendant_Table[net/sourceforge/pebble/search/SearchHit]
    //#input(void sortByScoreDescending()): net/sourceforge/pebble/search/SearchHit.__Descendant_Table[others]
    //#input(void sortByScoreDescending()): net/sourceforge/pebble/search/SearchHit.__Dispatch_Table.setNumber(I)V
    //#input(void sortByScoreDescending()): this
    //#input(void sortByScoreDescending()): this.hits
    //#pre[2] (void sortByScoreDescending()): this.hits != null
    //#presumption(void sortByScoreDescending()): java.util.Iterator:next(...).__Tag@133 == net/sourceforge/pebble/search/SearchHit
    //#presumption(void sortByScoreDescending()): java.util.Iterator:next(...)@133 != null
    //#test_vector(void sortByScoreDescending()): java.util.Iterator:hasNext(...)@132: {1}, {0}

    int number = 1;
    Iterator it = hits.iterator();
    while (it.hasNext()) {
      SearchHit hit = (SearchHit)it.next();
      hit.setNumber(number);
      number++;
    //#searchresults.java:135: ?overflow
    //#    number in -2_147_483_649..4_294_967_294
    //#    severity: LOW
    //#    class: net.sourceforge.pebble.search.SearchResults
    //#    method: void sortByScoreDescending()
    //#    basic block: bb_5
    //#    assertion: number in -2_147_483_649..4_294_967_294
    //#    VN: number + 1
    //#    Expected: {-2_147_483_648..4_294_967_295, Invalid}
    //#    Bad: {4_294_967_296}
    //#    Attribs:  Int  Bad singleton  Bad > Exp
    }
  }
    //#searchresults.java:137: end of method: void net.sourceforge.pebble.search.SearchResults.sortByScoreDescending()

  /**
   * Sorts the search results by date, in reverse order.
   */
  public void sortByDateDescending() {
    Collections.sort(hits, new SearchHitByDateComparator());
    //#searchresults.java:143: method: void net.sourceforge.pebble.search.SearchResults.sortByDateDescending()
    //#searchresults.java:143: Warning: method not available
    //#    -- call on void net.sourceforge.pebble.comparator.SearchHitByDateComparator()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.search.SearchResults
    //#    method: void sortByDateDescending()
    //#    unanalyzed callee: void net.sourceforge.pebble.comparator.SearchHitByDateComparator()
    //#input(void sortByDateDescending()): net/sourceforge/pebble/search/SearchHit.__Descendant_Table[net/sourceforge/pebble/search/SearchHit]
    //#input(void sortByDateDescending()): net/sourceforge/pebble/search/SearchHit.__Descendant_Table[others]
    //#input(void sortByDateDescending()): net/sourceforge/pebble/search/SearchHit.__Dispatch_Table.setNumber(I)V
    //#input(void sortByDateDescending()): this
    //#input(void sortByDateDescending()): this.hits
    //#pre[2] (void sortByDateDescending()): this.hits != null
    //#presumption(void sortByDateDescending()): java.util.Iterator:next(...).__Tag@148 == net/sourceforge/pebble/search/SearchHit
    //#presumption(void sortByDateDescending()): java.util.Iterator:next(...)@148 != null
    //#test_vector(void sortByDateDescending()): java.util.Iterator:hasNext(...)@147: {1}, {0}

    int number = 1;
    Iterator it = hits.iterator();
    while (it.hasNext()) {
      SearchHit hit = (SearchHit)it.next();
      hit.setNumber(number);
      number++;
    //#searchresults.java:150: ?overflow
    //#    number in -2_147_483_649..4_294_967_294
    //#    severity: LOW
    //#    class: net.sourceforge.pebble.search.SearchResults
    //#    method: void sortByDateDescending()
    //#    basic block: bb_5
    //#    assertion: number in -2_147_483_649..4_294_967_294
    //#    VN: number + 1
    //#    Expected: {-2_147_483_648..4_294_967_295, Invalid}
    //#    Bad: {4_294_967_296}
    //#    Attribs:  Int  Bad singleton  Bad > Exp
    }
  }
    //#searchresults.java:152: end of method: void net.sourceforge.pebble.search.SearchResults.sortByDateDescending()

}
    //#output(net.sourceforge.pebble.search.SearchResults__static_init): __Descendant_Table[net/sourceforge/pebble/search/SearchResults]
    //#output(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.add(Lnet/sourceforge/pebble/search/SearchHit;)V
    //#output(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.getHits()Ljava/util/List;
    //#output(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.getMessage()Ljava/lang/String;
    //#output(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.getNumberOfHits()I
    //#output(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.getQuery()Ljava/lang/String;
    //#output(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.setMessage(Ljava/lang/String;)V
    //#output(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.setQuery(Ljava/lang/String;)V
    //#output(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.sortByDateDescending()V
    //#output(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.sortByScoreDescending()V
    //#post(net.sourceforge.pebble.search.SearchResults__static_init): __Descendant_Table[net/sourceforge/pebble/search/SearchResults] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.add(Lnet/sourceforge/pebble/search/SearchHit;)V == &add
    //#post(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.getHits()Ljava/util/List; == &getHits
    //#post(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.getMessage()Ljava/lang/String; == &getMessage
    //#post(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.getNumberOfHits()I == &getNumberOfHits
    //#post(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.getQuery()Ljava/lang/String; == &getQuery
    //#post(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.setMessage(Ljava/lang/String;)V == &setMessage
    //#post(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.setQuery(Ljava/lang/String;)V == &setQuery
    //#post(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.sortByDateDescending()V == &sortByDateDescending
    //#post(net.sourceforge.pebble.search.SearchResults__static_init): __Dispatch_Table.sortByScoreDescending()V == &sortByScoreDescending
    //#searchresults.java:: end of method: net.sourceforge.pebble.search.SearchResults.net.sourceforge.pebble.search.SearchResults__static_init
    //#searchresults.java:: end of class: net.sourceforge.pebble.search.SearchResults
