/// <summary> /// Initializes a new instance of the <see cref="Configuration"/> class. /// </summary> /// <param name="looseObjectsHolder">The holder of the loose objects of this configurations.</param> /// <param name="constructedObjects">The list of constructed configuration objects ordered in a way that we can construct them in this order.</param> public Configuration(LooseObjectHolder looseObjectsHolder, IReadOnlyList <ConstructedConfigurationObject> constructedObjects) { LooseObjectsHolder = looseObjectsHolder; ConstructedObjects = constructedObjects ?? throw new ArgumentNullException(nameof(constructedObjects)); ObjectMap = new ConfigurationObjectMap(LooseObjects.Cast <ConfigurationObject>().Concat(constructedObjects)); ConstructedObjectsSet = ConstructedObjects.ToReadOnlyHashSet(); // Make sure there are no duplicated if (ConstructedObjectsSet.Count != constructedObjects.Count) { throw new GeoGenException("Configuration contains equal constructed objects."); } }
/// <summary> /// Initializes a new instance of the <see cref="LooseObjectHolder"/> /// instance wrapping the actual loose objects and possible their layout. /// </summary> /// <param name="looseObjects">The actual loose configurations objects.</param> /// <param name="layout">The layout of these loose objects.</param> public LooseObjectHolder(IEnumerable <LooseConfigurationObject> looseObjects, LooseObjectLayout layout) { LooseObjects = looseObjects?.ToList() ?? throw new ArgumentNullException(nameof(looseObjects)); ObjectMap = new ConfigurationObjectMap(looseObjects); Layout = layout; // Make sure the objects match the layout if (!LooseObjects.Select(looseObject => looseObject.ObjectType).SequenceEqual(layout.ObjectTypes())) { throw new GeoGenException($"The loose objects don't match the specified layout {layout}."); } // Make sure they are distinct if (LooseObjects.AnyDuplicates()) { throw new GeoGenException("The loose objects are not distinct."); } }