code: public int indexOf(E o, boolean add) {
      Integer index = indexes.get(o);
      if (index == null) {
        if (add && ! locked) {
          try {
            semaphore.acquire();
            index = indexes.get(o);
            if (index == null) {
              index = objects.size();
              objects.add(o);
              indexes.put(o, index);
            }
            semaphore.release();
          } catch (InterruptedException e) {
            throw new RuntimeException(e);
          }
        } else {
          return -1;
        }
      }
      return index;
    }
docs: Takes an Object and returns the integer index of the Object,
  perhaps adding it to the index first.
  Returns -1 if the Object is not in the Index.
  <p>
  <i>Notes:</i> The method indexOf(x, true) is the direct replacement for
  the number(x) method in the old Numberer class.  This method now uses a
  Semaphore object to make the index safe for concurrent multithreaded
  usage. (CDM: Is this better than using a synchronized block?)
  
  @param o the Object whose index is desired.
  @param add Whether it is okay to add new items to the index
  @return The index of the Object argument.  Returns -1 if the object is not in the index.