Class BinarySearchUsingFirstCharacters

java.lang.Object
org.gvsig.utils.search.BinarySearchUsingFirstCharacters

public class BinarySearchUsingFirstCharacters extends Object
This class has static methods that return items that their beginning text value matches with a text pattern.
It's necessary that items of the parameter array (Vector) were sort ordered according to their text value.
Supports Vectors with and without repeated items. There are four methods, that are a modification of a binary search algorithm of search, getting a rank of items:
  • Considering case sensitive in the search.
  • Ignoring case sensitive in the search.
  • Considering case sensitive in the search and an object which implements the Comparable interface
  • Ignoring case sensitive in the search, but yes an objecth which implements the Comparable interface
Author:
Pablo Piqueras Bartolomé (pablo.piqueras@iver.es)
  • Constructor Details

    • BinarySearchUsingFirstCharacters

      public BinarySearchUsingFirstCharacters()
  • Method Details

    • doSearchConsideringCaseSensitive

      public static List doSearchConsideringCaseSensitive(String text, Vector sortOrderedItems)
      This method should be used when is wanted to distinguish small letters from capital letters during the search. It's necessary that all items of the array implement the Comparable interface.
      And it's also necessary that the value returned by the toString() method of each item (supposing they inherit from Object) would be the expected value user saw (that would be used to compare the items).
      Parameters:
      text - java.lang.String
      sortOrderedItems - java.util.Vector
    • doSearchIgnoringCaseSensitive

      public static List doSearchIgnoringCaseSensitive(String text, Vector sortOrderedItems)
      This method should be used when is wanted not to distinguish small letters from capital letters during the search. It's necessary that all items of the array implement the Comparable interface.
      And it's also necessary that the value returned by the toString() method of each item (supposing they inherit from Object) would be the expected value user saw (that would be used to compare the items). In this particular situation, it's supposed that the vector is sort ordered according the default algorithm of Java; this has the problem that it doesn't consideres the special characters and the orthographic rules of languages that aren't English, and then, for a particular text search, an incorrect result could be obtained. The solution decided for this problem has been to modify the algorithm, for seach into two ranks.
      Parameters:
      text - java.lang.String
      sortOrderedItems - java.util.Vector
    • doSearchConsideringCaseSensitive

      public static List doSearchConsideringCaseSensitive(String text, Vector sortOrderedItems, Comparator comp)
      This method should be used when is wanted distinguish small letters from capital letters during the search, and the comparation of items done according an algorithm we define. And it's also necessary that the value returned by the toString() method of each item (supposing they inherit from Object) would be the expected value user saw (that would be used to compare the items).
      Parameters:
      text - java.lang.String
      sortOrderedItems - java.util.Vector
      comp - An Comparator object which implements the compareTo() method.
    • doSearchIgnoringCaseSensitive

      public static List doSearchIgnoringCaseSensitive(String text, Vector sortOrderedItems, Comparator comp)
      This method should be used when is wanted not to distinguish small letters from capital letters during the search, and the comparation of items done according an algorithm we define. And it's also necessary that the value returned by the toString() method of each item (supposing they inherit from Object) would be the expected value user saw (that would be used to compare the items).
      Parameters:
      text - java.lang.String
      sortOrderedItems - java.util.Vector
      comp - An Comparator object which implements the compareTo() method.