@SuppressWarnings("unchecked")
  private static RegisterStatus registerValue(BytesRef term,
      ComponentTermVector termVector, TermvectorNumberBasic number,
      Integer termNumberMaximum, Integer segmentNumber, boolean forceAccept,
      String[] mutableKey) throws IOException {
    long value = termVector.subComponentFunction.parserFunction
        .getValueLong(number.valueSum, 0);
    long sortValue = 0;
    if (termVector.subComponentFunction.sortType
        .equals(CodecUtil.STATS_TYPE_SUM)) {
      sortValue = value;
    } else if (termVector.subComponentFunction.sortType
        .equals(CodecUtil.STATS_TYPE_N)) {
      sortValue = number.docNumber;
    }
    boolean addItem = false;
    boolean addItemForced = false;
    MtasDataCollector<Long, ?> dataCollector = (MtasDataCollector<Long, ?>) termVector.subComponentFunction.dataCollector;
    // sort on term
    if (termVector.subComponentFunction.sortType.equals(CodecUtil.SORT_TERM)) {
      addItem = true;
      addItemForced = true;
      // sort on sum or n
    } else if (termVector.subComponentFunction.sortType
        .equals(CodecUtil.STATS_TYPE_SUM)
        || termVector.subComponentFunction.sortType
            .equals(CodecUtil.STATS_TYPE_N)) {
      // always accept
      if (forceAccept) {
        addItem = true;
        addItemForced = addItem;
        // check boundary
      } else if (termVector.boundaryRegistration) {
        addItem = dataCollector.validateSegmentBoundary(sortValue);
        if (addItem) {
          if (mutableKey[0] == null) {
            mutableKey[0] = MtasToken.getPostfixFromValue(term);
          }
          String segmentStatus = dataCollector.validateSegmentValue(
              mutableKey[0], sortValue, termNumberMaximum, segmentNumber,
              false);
          if (segmentStatus != null) {
            if (segmentStatus.equals(MtasDataCollector.SEGMENT_KEY)) {
              addItemForced = true;
            }
          } else {
            // shouldn't happen
          }
        }
        // no boundary
      } else {
        String segmentStatus = dataCollector.validateSegmentValue(sortValue,
            termNumberMaximum, segmentNumber);
        if (segmentStatus != null) {
          boolean possibleAddItem;
          if (segmentStatus.equals(MtasDataCollector.SEGMENT_KEY_OR_NEW)) {
            possibleAddItem = true;
          } else if (segmentStatus
              .equals(MtasDataCollector.SEGMENT_POSSIBLE_KEY)) {
            mutableKey[0] = MtasToken.getPostfixFromValue(term);
            segmentStatus = dataCollector.validateSegmentValue(mutableKey[0],
                sortValue, termNumberMaximum, segmentNumber, true);
            if (segmentStatus != null) {
              possibleAddItem = true;
            } else {
              possibleAddItem = false;
            }
          } else {
            // should never happen?
            possibleAddItem = false;
          }
          // further checks, passed initial
          if (possibleAddItem) {
            if (mutableKey[0] == null) {
              mutableKey[0] = MtasToken.getPostfixFromValue(term);
            }
            segmentStatus = dataCollector.validateSegmentValue(mutableKey[0],
                sortValue, termNumberMaximum, segmentNumber, false);
            if (segmentStatus != null) {
              addItem = true;
              if (segmentStatus.equals(MtasDataCollector.SEGMENT_KEY)) {
                addItemForced = true;
              }
            }
          }
        } else {
          addItem = false;
        }
      }
      // don't sort?
    } else {
      addItem = false;
    }
    if (addItem) {
      boolean computeFull = false;
      if (mutableKey[0] == null) {
        mutableKey[0] = MtasToken.getPostfixFromValue(term);
      }
      // check dataCollector type
      if (termVector.subComponentFunction.statsType
          .equals(CodecUtil.STATS_BASIC)) {
        dataCollector.add(mutableKey[0], value, number.docNumber);
      } else {
        computeFull = true;
      }
      // functions
      if (termVector.functions != null) {
        for (SubComponentFunction function : termVector.functions) {
          if (function.parserFunction.sumRule()
              && !function.parserFunction.needPositions()
              && function.statsType.equals(CodecUtil.STATS_BASIC)) {
            if (function.dataType.equals(CodecUtil.DATA_TYPE_LONG)) {
              long valueFunction = function.parserFunction
                  .getValueLong(number.valueSum, 0);
              function.dataCollector.add(mutableKey[0], valueFunction,
                  number.docNumber);
            } else if (function.dataType.equals(CodecUtil.DATA_TYPE_DOUBLE)) {
              double valueFunction = function.parserFunction
                  .getValueDouble(number.valueSum, 0);
              function.dataCollector.add(mutableKey[0], valueFunction,
                  number.docNumber);
            }
          } else {
            computeFull = true;
          }
        }
      }
      // add as full?
      return computeFull ? new RegisterStatus(sortValue, addItemForced) : null;
    } else {
      return null;
    }
  }
@ SuppressWarnings ( "unchecked" ) private static RegisterStatus registerValue ( BytesRef term , ComponentTermVector termVector , TermvectorNumberBasic number , Integer termNumberMaximum , Integer segmentNumber , boolean forceAccept , String [ ] mutableKey ) throws IOException { long value = termVector . subComponentFunction . parserFunction . getValueLong ( number . valueSum , 0 ) ; long sortValue = 0 ; if ( termVector . subComponentFunction . sortType . equals ( CodecUtil . STATS_TYPE_SUM ) ) { sortValue = value ; } else if ( termVector . subComponentFunction . sortType . equals ( CodecUtil . STATS_TYPE_N ) ) { sortValue = number . docNumber ; } boolean addItem = false ; boolean addItemForced = false ; MtasDataCollector < Long , ? > dataCollector = ( MtasDataCollector < Long , ? > ) termVector . subComponentFunction . dataCollector ; if ( termVector . subComponentFunction . sortType . equals ( CodecUtil . SORT_TERM ) ) { addItem = true ; addItemForced = true ; } else if ( termVector . subComponentFunction . sortType . equals ( CodecUtil . STATS_TYPE_SUM ) || termVector . subComponentFunction . sortType . equals ( CodecUtil . STATS_TYPE_N ) ) { if ( forceAccept ) { addItem = true ; addItemForced = addItem ; } else if ( termVector . boundaryRegistration ) { addItem = dataCollector . validateSegmentBoundary ( sortValue ) ; if ( addItem ) { if ( mutableKey [ 0 ] == null ) { mutableKey [ 0 ] = MtasToken . getPostfixFromValue ( term ) ; } String segmentStatus = dataCollector . validateSegmentValue ( mutableKey [ 0 ] , sortValue , termNumberMaximum , segmentNumber , false ) ; if ( segmentStatus != null ) { if ( segmentStatus . equals ( MtasDataCollector . SEGMENT_KEY ) ) { addItemForced = true ; } } else { } } } else { String segmentStatus = dataCollector . validateSegmentValue ( sortValue , termNumberMaximum , segmentNumber ) ; if ( segmentStatus != null ) { boolean possibleAddItem ; if ( segmentStatus . equals ( MtasDataCollector . SEGMENT_KEY_OR_NEW ) ) { possibleAddItem = true ; } else if ( segmentStatus . equals ( MtasDataCollector . SEGMENT_POSSIBLE_KEY ) ) { mutableKey [ 0 ] = MtasToken . getPostfixFromValue ( term ) ; segmentStatus = dataCollector . validateSegmentValue ( mutableKey [ 0 ] , sortValue , termNumberMaximum , segmentNumber , true ) ; if ( segmentStatus != null ) { possibleAddItem = true ; } else { possibleAddItem = false ; } } else { possibleAddItem = false ; } if ( possibleAddItem ) { if ( mutableKey [ 0 ] == null ) { mutableKey [ 0 ] = MtasToken . getPostfixFromValue ( term ) ; } segmentStatus = dataCollector . validateSegmentValue ( mutableKey [ 0 ] , sortValue , termNumberMaximum , segmentNumber , false ) ; if ( segmentStatus != null ) { addItem = true ; if ( segmentStatus . equals ( MtasDataCollector . SEGMENT_KEY ) ) { addItemForced = true ; } } } } else { addItem = false ; } } } else { addItem = false ; } if ( addItem ) { boolean computeFull = false ; if ( mutableKey [ 0 ] == null ) { mutableKey [ 0 ] = MtasToken . getPostfixFromValue ( term ) ; } if ( termVector . subComponentFunction . statsType . equals ( CodecUtil . STATS_BASIC ) ) { dataCollector . add ( mutableKey [ 0 ] , value , number . docNumber ) ; } else { computeFull = true ; } if ( termVector . functions != null ) { for ( SubComponentFunction function : termVector . functions ) { if ( function . parserFunction . sumRule ( ) && ! function . parserFunction . needPositions ( ) && function . statsType . equals ( CodecUtil . STATS_BASIC ) ) { if ( function . dataType . equals ( CodecUtil . DATA_TYPE_LONG ) ) { long valueFunction = function . parserFunction . getValueLong ( number . valueSum , 0 ) ; function . dataCollector . add ( mutableKey [ 0 ] , valueFunction , number . docNumber ) ; } else if ( function . dataType . equals ( CodecUtil . DATA_TYPE_DOUBLE ) ) { double valueFunction = function . parserFunction . getValueDouble ( number . valueSum , 0 ) ; function . dataCollector . add ( mutableKey [ 0 ] , valueFunction , number . docNumber ) ; } } else { computeFull = true ; } } } return computeFull ? new RegisterStatus ( sortValue , addItemForced ) : null ; } else { return null ; } }
Register value.

@param term
the term
@param termVector
the term vector
@param number
the number
@param termNumberMaximum
the term number maximum
@param segmentNumber
the segment number
@param forceAccept
the force accept
@param mutableKey
the mutable key
@return the register status
@throws IOException
Signals that an I/O exception has occurred.