Example #1
0
  /**
   * Returns an unmodifiable view of the Index. It is just a locked index that cannot be unlocked,
   * so if you try to add something, nothing will happen (it won't throw an exception). Trying to
   * unlock it will throw an UnsupportedOperationException. If the underlying Index is modified, the
   * change will "write-through" to the view.
   *
   * @return An unmodifiable view of the Index
   */
  public HashIndex<E> unmodifiableView() {
    HashIndex<E> newIndex =
        new HashIndex<E>() {
          @Override
          public void unlock() {
            throw new UnsupportedOperationException("This is an unmodifiable view!");
          }

          private static final long serialVersionUID = 3415903369787491736L;
        };
    newIndex.objects = objects;
    newIndex.indexes = indexes;
    newIndex.lock();
    return newIndex;
  }