/// <summary> /// Changes the maximum storage capacity. /// </summary> /// <param name="newCapacity">The new capacity</param> /// <returns>The amount of overflow if the current value needs to be adjusted.</returns> public Oxygen ChangeMaxStorage(Oxygen newCapacity) { if (currentValue <= newCapacity) { capacity = newCapacity; return(new Oxygen()); } var overflow = currentValue - newCapacity; currentValue = newCapacity; return(overflow); }
public void Store(Oxygen oxygen) { oxygen = oxygenBaseStorage.Store(oxygen); using (var storages = oxygenStorages.GetEnumerator()) { while (oxygen > Oxygen.Zero && storages.MoveNext()) { Debug.Assert(storages.Current != null, "storages.Current != null"); oxygen = storages.Current.Store(oxygen); } } }
public bool TryConsume(Oxygen oxygen) { if (oxygen > OxygenAvailable) { return(false); } oxygen = oxygenBaseStorage.Consume(oxygen); foreach (var storage in oxygenStorages) { oxygen = storage.Consume(oxygen); } return(true); }
public Oxygen Store(Oxygen value) { if (value < new Oxygen()) { return(-Consume(-value)); } if (currentValue + value > capacity) { value -= capacity - currentValue; currentValue = capacity; return(value); } currentValue += value; return(new Oxygen()); }
public Oxygen Consume(Oxygen value) { if (value < new Oxygen()) { return(-Store(-value)); } if (currentValue - value < new Oxygen()) { value -= currentValue; currentValue = new Oxygen(); return(value); } currentValue -= value; return(new Oxygen()); }
public OxygenStorage(Oxygen capacity) { this.capacity = capacity; }
public static Oxygen Max(Oxygen a, Oxygen b) => a > b ? a : b;
public static Oxygen Min(Oxygen a, Oxygen b) => a < b ? a : b;