<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add(self, promise, bitoffset, *, _offsetideal=None):
 """Add a promise to the promise collection at an optional offset. Args: promise: A TDOPromise to add to this collection. bitoffset: An integer offset for this new promise in the collection. _offsetideal: An integer offset for this new promise in the collection if the associated primitive supports arbitrary TDO control. """

        #This Assumes that things are added in order.
        #Sorting or checking should likely be added.
        if _offsetideal is None:
            _offsetideal = bitoffset
        if isinstance(promise, TDOPromise):
            newpromise = promise.makesubatoffset(
                bitoffset, _offsetideal=_offsetideal)
            self._promises.append(newpromise)
        elif isinstance(promise, TDOPromiseCollection):
            for p in promise._promises:
                self.add(p, bitoffset, _offsetideal=_offsetideal)