@Override
 public long lookupTerm(BytesRef key) {
   assertThread("Sorted set doc values", creationThread);
   assert key.isValid();
   long result = in.lookupTerm(key);
   assert result < valueCount;
   assert key.isValid();
   return result;
 }
 @Override
 public BytesRef binaryValue() {
   assertThread("Sorted doc values", creationThread);
   final BytesRef result = in.binaryValue();
   assert result.isValid();
   return result;
 }
 @Override
 public TermsEnum intersect(CompiledAutomaton automaton, BytesRef bytes) throws IOException {
   TermsEnum termsEnum = in.intersect(automaton, bytes);
   assert termsEnum != null;
   assert bytes == null || bytes.isValid();
   return new AssertingTermsEnum(termsEnum);
 }
 @Override
 public void seekExact(BytesRef term, TermState state) throws IOException {
   assertThread("Terms enums", creationThread);
   assert term.isValid();
   in.seekExact(term, state);
   this.state = State.POSITIONED;
 }
 @Override
 public BytesRef lookupOrd(long ord) {
   assertThread("Sorted set doc values", creationThread);
   assert ord >= 0 && ord < valueCount;
   final BytesRef result = in.lookupOrd(ord);
   assert result.isValid();
   return result;
 }
 @Override
 public BytesRef term() throws IOException {
   assertThread("Terms enums", creationThread);
   assert state == State.POSITIONED : "term() called on unpositioned TermsEnum";
   BytesRef ret = super.term();
   assert ret == null || ret.isValid();
   return ret;
 }
 @Override
 public SeekStatus seekCeil(BytesRef term) throws IOException {
   assertThread("Terms enums", creationThread);
   assert term.isValid();
   SeekStatus result = super.seekCeil(term);
   if (result == SeekStatus.END) {
     state = State.UNPOSITIONED;
   } else {
     state = State.POSITIONED;
   }
   return result;
 }
 // TODO: we should separately track if we are 'at the end' ?
 // someone should not call next() after it returns null!!!!
 @Override
 public BytesRef next() throws IOException {
   assertThread("Terms enums", creationThread);
   assert state == State.INITIAL || state == State.POSITIONED
       : "next() called on unpositioned TermsEnum";
   BytesRef result = super.next();
   if (result == null) {
     state = State.UNPOSITIONED;
   } else {
     assert result.isValid();
     state = State.POSITIONED;
   }
   return result;
 }
 @Override
 public boolean seekExact(BytesRef text) throws IOException {
   assertThread("Terms enums", creationThread);
   assert text.isValid();
   boolean result;
   if (delegateOverridesSeekExact) {
     result = in.seekExact(text);
   } else {
     result = super.seekExact(text);
   }
   if (result) {
     state = State.POSITIONED;
   } else {
     state = State.UNPOSITIONED;
   }
   return result;
 }
 @Override
 public BytesRef getMax() throws IOException {
   BytesRef v = in.getMax();
   assert v == null || v.isValid();
   return v;
 }