/// Gets the object associated with the specified key in the dictionary.
  // The key is assumed to be a String, which is matched against
  // the wildcard-pattern keys in the dictionary.
  // @param key the string to match
  // @returns the element for the key, or null if there's no match
  // @see Acme.Utils#match
  public synchronized Object get(Object key) {

    String sKey = (String) key;
    // System.out.println("Trying "+sKey);
    int matching_len = -1, found = -1;
    // to optimize speed, keys should be sorted by length
    // TODO: above
    for (int i = keys.size() - 1; i > -1; i--) {
      String thisKey = (String) keys.elementAt(i);
      // System.out.println("Trying "+thisKey);
      if (Acme.Utils.match(thisKey, sKey)) {
        int current = Acme.Utils.matchSpan(thisKey, sKey);
        if (current > matching_len) {
          // System.out.println("using "+thisKey);
          found = i;
          matching_len = current;
        }
      }
    }
    if (found > -1) return elements.elementAt(found);
    return null;
  }
Ejemplo n.º 2
0
 // / Gets the object associated with the specified key in the dictionary.
 // The key is assumed to be a String, which is matched against
 // the wildcard-pattern keys in the dictionary.
 // @param key the string to match
 // @returns the element for the key, or null if there's no match
 // @see Acme.Utils#match
 @Override
 public synchronized Object get(Object key) {
   String sKey = (String) key;
   int matching_len = 0, found = -1;
   // to optimize speed, keys should be sorted by length
   // TODO: above
   for (int i = keys.size() - 1; i > -1; i--) {
     String thisKey = (String) keys.elementAt(i);
     int current = Acme.Utils.matchSpan(thisKey, sKey);
     if (current > matching_len) {
       found = i;
       matching_len = current;
     }
   }
   if (found > -1) return elements.elementAt(found);
   return null;
 }