int item_index = vec.indexOf(arg);
int item_index = -1;  for (int j = 0; j < vec.size(); ++j) { CollationElement e = (CollationElement) vec.elementAt (j);  if (arg.equals (e.key)) { item_index = j; break; } }
  public RuleBasedCollator (String rules) throws ParseException  {    this.rules = rules;    this.frenchAccents = false;    // We keep each rule in order in a vector.  At the end we traverse    // the vector and compute collation values from it.    int insertion_index = 0;    Vector vec = new Vector ();    StringBuffer argument = new StringBuffer ();    int len = rules.length();    for (int index = 0; index < len; ++index)      {	char c = rules.charAt(index);	// Just skip whitespace.	if (Character.isWhitespace(c))	  continue;	// Modifier.	if (c == '@')	  {	    frenchAccents = true;	    continue;	  }	// Check for relation or reset operator.	if (! (c == '<' || c == ';' || c == ',' || c == '=' || c == '&'))	  throw new ParseException ("invalid character", index);	++index;	while (index < len)	  {	    if (! Character.isWhitespace(rules.charAt(index)))	      break;	    ++index;	  }	if (index == len)	  throw new ParseException ("missing argument", index);	int save = index;	index = text_argument (rules, index, argument);	if (argument.length() == 0)	  throw new ParseException ("invalid character", save);	String arg = argument.toString();	int item_index = vec.indexOf(arg);	if (c != '&')	  {	    // If the argument already appears in the vector, then we	    // must remove it in order to re-order.	    if (item_index != -1)	      {		vec.removeElementAt(item_index);		if (insertion_index >= item_index)		  --insertion_index;	      }	    CollationElement r = new CollationElement (arg, c);	    vec.insertElementAt(r, insertion_index);	    ++insertion_index;	  }	else	  {	    // Reset.	    if (item_index == -1)	      throw		new ParseException ("argument to reset not previously seen",				    save);	    insertion_index = item_index + 1;	  }	// Ugly: in this case the resulting INDEX comes from	// text_argument, which returns the index of the next	// character we should examine.	--index;      }    // Now construct a hash table that maps strings onto their    // collation values.    int primary = 0;    int secondary = 0;    int tertiary = 0;    this.map = new Hashtable ();    this.prefixes = new Hashtable ();    Enumeration e = vec.elements();    while (e.hasMoreElements())      {	CollationElement r = (CollationElement) e.nextElement();	switch (r.relation)	  {	  case '<':	    ++primary;	    secondary = 0;	    tertiary = 0;	    break;	  case ';':	    ++secondary;	    tertiary = 0;	    break;	  case ',':	    ++tertiary;	    break;	  case '=':	    break;	  }	// This must match CollationElementIterator.	map.put(r.key, new Integer (primary << 16				    | secondary << 8 | tertiary));	// Make a map of all lookaheads we might need.	for (int i = r.key.length() - 1; i >= 1; --i)	  prefixes.put(r.key.substring(0, i), Boolean.TRUE);      }  }