private List<OIdentifiable> cursorToList(OIndexCursor cursor) {
   final List<OIdentifiable> currentResult = new ArrayList<OIdentifiable>();
   Map.Entry<Object, OIdentifiable> entry = cursor.nextEntry();
   while (entry != null) {
     currentResult.add(entry.getValue());
     entry = cursor.nextEntry();
   }
   return currentResult;
 }
  @Override
  public String getName() {
    final StringBuilder res = new StringBuilder("IndexChain{");
    final List<String> indexNames = getIndexNames();

    for (int i = 0; i < indexNames.size(); i++) {
      String indexName = indexNames.get(i);
      if (i > 0) res.append(", ");
      res.append(indexName);
    }

    res.append("}");

    return res.toString();
  }
  private List<OIdentifiable> applyFirstIndex(Collection<Comparable> currentKeys) {
    final List<OIdentifiable> result;
    if (isComposite(firstIndex)) {
      result = new ArrayList<OIdentifiable>();
      for (Comparable key : currentKeys) {
        result.addAll(getFromCompositeIndex(key, firstIndex));
      }
    } else {
      final OIndexCursor cursor = firstIndex.iterateEntries(currentKeys, true);

      result = cursorToList(cursor);
    }

    updateStatistic(firstIndex);

    return result;
  }
    @Override
    public Map.Entry<Object, OIdentifiable> nextEntry() {
      if (currentIterator == null) return null;

      while (!currentIterator.hasNext()) {
        final Map.Entry<Object, OIdentifiable> entry = internalCursor.nextEntry();

        if (entry == null) {
          currentIterator = null;
          return null;
        }

        queryResult.clear();
        queryResult.addAll(applyTailIndexes(entry.getValue()));

        currentIterator = queryResult.iterator();
      }

      if (!currentIterator.hasNext()) {
        currentIterator = null;
        return null;
      }

      final OIdentifiable result = currentIterator.next();

      return new Map.Entry<Object, OIdentifiable>() {
        @Override
        public Object getKey() {
          throw new UnsupportedOperationException("getKey");
        }

        @Override
        public OIdentifiable getValue() {
          return result;
        }

        @Override
        public OIdentifiable setValue(OIdentifiable value) {
          throw new UnsupportedOperationException("setValue");
        }
      };
    }