コード例 #1
0
 public void readFrom(DataInputStream stream, DataExternalizer<Value> externalizer)
     throws IOException {
   while (stream.available() > 0) {
     final int valueCount = DataInputOutputUtil.readINT(stream);
     if (valueCount < 0) {
       removeAssociatedValue(
           -valueCount); // ChangeTrackingValueContainer marked inputId as invalidated, see
                         // ChangeTrackingValueContainer.saveTo
       setNeedsCompacting(true);
     } else {
       for (int valueIdx = 0; valueIdx < valueCount; valueIdx++) {
         final Value value = externalizer.read(stream);
         int idCountOrSingleValue = DataInputOutputUtil.readINT(stream);
         if (idCountOrSingleValue > 0) {
           addValue(idCountOrSingleValue, value);
         } else {
           idCountOrSingleValue = -idCountOrSingleValue;
           ensureFileSetCapacityForValue(value, idCountOrSingleValue);
           int prev = 0;
           for (int i = 0; i < idCountOrSingleValue; i++) {
             final int id = DataInputOutputUtil.readINT(stream);
             addValue(prev + id, value);
             prev += id;
           }
         }
       }
     }
   }
 }
 @Override
 public void addValue(int inputId, Value value) {
   ValueContainerImpl<Value> merged = myMerged;
   if (merged != null) {
     merged.addValue(inputId, value);
   }
   ValueContainerImpl<Value> added = myAdded;
   if (added == null) {
     myAdded = added = new ValueContainerImpl<Value>();
   }
   added.addValue(
       inputId,
       value); // will flush the changes & caller should ensure exclusiveness to avoid intermediate
               // visibility issues
 }
コード例 #3
0
    public ValueContainerImpl<T> read(final DataInput in) throws IOException {
      DataInputStream stream = (DataInputStream) in;
      final ValueContainerImpl<T> valueContainer = new ValueContainerImpl<T>();

      while (stream.available() > 0) {
        final int valueCount = DataInputOutputUtil.readSINT(in);
        if (valueCount < 0) {
          valueContainer.removeAllValues(-valueCount);
          valueContainer.setNeedsCompacting(true);
        } else {
          for (int valueIdx = 0; valueIdx < valueCount; valueIdx++) {
            final T value = myExternalizer.read(in);
            final int idCount = DataInputOutputUtil.readSINT(in);
            for (int i = 0; i < idCount; i++) {
              final int id = DataInputOutputUtil.readSINT(in);
              if (id < 0) {
                valueContainer.removeValue(-id, value);
                valueContainer.setNeedsCompacting(true);
              } else {
                valueContainer.addValue(id, value);
              }
            }
          }
        }
      }
      return valueContainer;
    }