static void scanModifications()

in uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java [705:856]


  static void scanModifications(BinaryCasSerDes bcsd, CommonSerDesSequential csds,
          FsChange[] fssModified, Obj2IntIdentityHashMap<TOP> fs2auxOffset,
          List<AddrPlusValue> chgMainAvs, List<AddrPlusValue> chgByteAvs,
          List<AddrPlusValue> chgShortAvs, List<AddrPlusValue> chgLongAvs) {

    // scan the sorted mods to precompute the various change items:
    // changed main heap: addr and new slot value
    // for aux heaps: new values.
    // Note: the changed main heap values point to these (and also to new string values)
    // -- for byte (and boolean), short, long
    // for aux heaps: changed (updated) values: the addr(s) followed by the values
    final Obj2IntIdentityHashMap<TOP> fs2addr = csds.fs2addr;
    for (FsChange fsChange : fssModified) {
      final TOP fs = fsChange.fs;
      final TypeImpl type = fs._getTypeImpl();
      if (fsChange.arrayUpdates != null) {
        switch (type.getComponentSlotKind()) {

          case Slot_BooleanRef:
            fsChange.arrayUpdates.forAllInts(index -> {
              chgByteAvs.add(new AddrPlusValue(
                      convertArrayIndexToAuxHeapAddr(bcsd, index, fs, fs2auxOffset),
                      ((BooleanArray) fs).get(index) ? 1 : 0));
            });
            break;

          case Slot_ByteRef:
            fsChange.arrayUpdates.forAllInts(index -> {
              chgByteAvs.add(new AddrPlusValue(
                      convertArrayIndexToAuxHeapAddr(bcsd, index, fs, fs2auxOffset),
                      ((ByteArray) fs).get(index)));
            });
            break;

          case Slot_ShortRef:
            fsChange.arrayUpdates.forAllInts(index -> {
              chgShortAvs.add(new AddrPlusValue(
                      convertArrayIndexToAuxHeapAddr(bcsd, index, fs, fs2auxOffset),
                      ((ShortArray) fs).get(index)));
            });
            break;

          case Slot_LongRef:
            fsChange.arrayUpdates.forAllInts(index -> {
              chgLongAvs.add(new AddrPlusValue(
                      convertArrayIndexToAuxHeapAddr(bcsd, index, fs, fs2auxOffset),
                      ((LongArray) fs).get(index)));
            });
            break;

          case Slot_DoubleRef:
            fsChange.arrayUpdates.forAllInts(index -> {
              chgLongAvs.add(new AddrPlusValue(
                      convertArrayIndexToAuxHeapAddr(bcsd, index, fs, fs2auxOffset),
                      CASImpl.double2long(((DoubleArray) fs).get(index))));
            });
            break;

          // heap stored arrays
          case Slot_Int:
            fsChange.arrayUpdates.forAllInts(index -> {
              chgMainAvs.add(new AddrPlusValue(convertArrayIndexToMainHeapAddr(index, fs, fs2addr),
                      ((IntegerArray) fs).get(index)));
            });
            break;

          case Slot_Float:
            fsChange.arrayUpdates.forAllInts(index -> {
              chgMainAvs.add(new AddrPlusValue(convertArrayIndexToMainHeapAddr(index, fs, fs2addr),
                      CASImpl.float2int(((FloatArray) fs).get(index))));
            });
            break;

          case Slot_StrRef:
            fsChange.arrayUpdates.forAllInts(index -> {
              int v = bcsd.nextStringHeapAddrAfterMark
                      + bcsd.stringHeap.addString(((StringArray) fs).get(index));
              chgMainAvs.add(
                      new AddrPlusValue(convertArrayIndexToMainHeapAddr(index, fs, fs2addr), v));
            });
            break;

          case Slot_HeapRef:
            fsChange.arrayUpdates.forAllInts(index -> {
              TOP tgtFs = (TOP) ((FSArray<?>) fs).get(index);
              chgMainAvs.add(new AddrPlusValue(convertArrayIndexToMainHeapAddr(index, fs, fs2addr),
                      fs2addr.get(tgtFs)));
            });
            break;

          default:
            Misc.internalError();
        } // end of switch
      } else { // end of if-array
        // 1 or more features modified
        if (fs instanceof UimaSerializable uimaSerializable) {
          uimaSerializable._save_to_cas_data();
        }
        BitSet fm = fsChange.featuresModified;
        int offset = fm.nextSetBit(0);
        while (offset >= 0) {
          int addr = csds.fs2addr.get(fs) + offset + 1; // skip over type code);
          int value = 0;

          FeatureImpl feat = type.getFeatureImpls()[offset];

          switch (feat.getSlotKind()) {
            case Slot_Boolean:
              value = fs._getBooleanValueNc(feat) ? 1 : 0;
              break;

            case Slot_Byte:
              value = fs._getByteValueNc(feat);
              break;
            case Slot_Short:
              value = fs._getShortValueNc(feat);
              break;
            case Slot_Int:
              value = fs._getIntValueNc(feat);
              break;
            case Slot_Float:
              value = CASImpl.float2int(fs._getFloatValueNc(feat));
              break;
            case Slot_LongRef: {
              value = bcsd.nextLongHeapAddrAfterMark
                      + bcsd.longHeap.addLong(fs._getLongValueNc(feat));
              break;
            }
            case Slot_DoubleRef: {
              value = bcsd.nextLongHeapAddrAfterMark
                      + bcsd.longHeap.addLong(CASImpl.double2long(fs._getDoubleValueNc(feat)));
              break;
            }
            case Slot_StrRef: {
              value = bcsd.nextStringHeapAddrAfterMark
                      + bcsd.stringHeap.addString(fs._getStringValueNc(feat));
              break;
            }
            case Slot_HeapRef:
              value = fs2addr.get(fs._getFeatureValueNc(feat));
              break;
            default:
              Misc.internalError();
          } // end of switch

          chgMainAvs.add(new AddrPlusValue(addr, value));

          offset = fm.nextSetBit(offset + 1);
        } // loop over changed feature offsets
      } // end of features-modified case
    } // end of for all fsChanges
  }