private DataTypeComponent replaceComponents(LinkedList<DataTypeComponentDB> origComponents,
			DataType resolvedDataType, int newOffset, int length, String name, String comment)
			throws IOException, IllegalArgumentException {

		boolean clearOnly = false;
		if (resolvedDataType == DataType.DEFAULT) {
			clearOnly = true;
			length = 0; // nothing gets consumed
		}

		DataTypeComponentDB origFirstDtc = origComponents.getFirst();
		DataTypeComponentDB origLastDtc = origComponents.getLast();
		int origFirstOrdinal = origFirstDtc.getOrdinal();
		int origLastOrdinal = origLastDtc.getOrdinal();
		int minReplacedOffset = origFirstDtc.getOffset();
		int maxReplacedOffset = origLastDtc.getEndOffset();

		// Perform origComponents checks
		if (newOffset < minReplacedOffset || newOffset > maxReplacedOffset) {
			throw new AssertException("newOffset not contained within origComponents");
		}
		if (origComponents.size() > 1) {
			int checkOrdinal = origFirstOrdinal;
			for (DataTypeComponentDB origDtc : origComponents) {
				if (origDtc.isUndefined()) {
					throw new AssertException(
						"undefined component within multi-component sequence");
				}
				if (origDtc.getOrdinal() != checkOrdinal++) {
					throw new AssertException("non-sequential components specified");
				}
			}
		}

		int leadingUnusedBytes = newOffset - minReplacedOffset;
		int newOrdinal = origFirstOrdinal;
		if (!isPackingEnabled()) {
			newOrdinal += leadingUnusedBytes; // leading unused bytes will become undefined components
		}

		// compute space freed by component removal
		int origLength = 0;
		if (origLastDtc.getLength() != 0) {
			origLength = maxReplacedOffset - minReplacedOffset + 1;
		}

		if (!clearOnly && !isPackingEnabled()) {
			int bytesNeeded = length - origLength + leadingUnusedBytes;
			checkUndefinedSpaceAvailabilityAfter(origLastOrdinal, bytesNeeded, resolvedDataType,
				newOffset);
		}

		// determine defined component list insertion point, remove old components
		// and insert new component in list
		int index;
		if (isPackingEnabled()) {
			index = newOrdinal;
		}
		else {
			index = Collections.binarySearch(components, Integer.valueOf(origFirstOrdinal),
				OrdinalComparator.INSTANCE);
		}
		if (index < 0) {
			index = -index - 1; // undefined component replacement
		}
		else {
			for (DataTypeComponentDB origDtc : origComponents) {
				DataTypeComponentDB dtc = doDelete(index);
				if (dtc != origDtc) {
					throw new AssertException("component replacement mismatch");
				}
			}
		}

		DataTypeComponentDB newDtc = null;
		if (!clearOnly) {
			// insert new component
			DBRecord rec = componentAdapter.createRecord(dataMgr.getResolvedID(resolvedDataType),
				key, length, newOrdinal, newOffset, name, comment);
			resolvedDataType.addParent(this);
			newDtc = new DataTypeComponentDB(dataMgr, componentAdapter, this, rec);
			components.add(index, newDtc);
		}

		// adjust ordinals of trailing components - defer if packing is enabled
		if (!isPackingEnabled()) {
			int deltaOrdinal = -origComponents.size() + origLength - length;
			shiftOffsets(index + 1, deltaOrdinal, 0);
		}
		return newDtc;
	}
Replace the specified components with a new component containing the specified data type.
If {@link DataType#DEFAULT} is specified as the resolvedDataType only a clear operation
is performed.

@param origComponents the original sequence of data type components in this structure to be
replaced.  These components must be adjacent components in sequential order. If an
non-packed undefined component is specified no other component may be included.
@param resolvedDataType the data type of the new component
@param newOffset offset of replacement component which must fall within origComponents
bounds
@param length the length of the new component
@param name the field name of the new component
@param comment the comment for the new component
@return the new component or null if only a clear operation was performed.
@throws IOException if database IO error occurs
@throws IllegalArgumentException if unable to identify/make sufficient space
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/StructureDB.java