{"action":"created","issue":{"url":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues/443","labels_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues/443/labels{/name}","comments_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues/443/comments","events_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues/443/events","html_url":"https://github.com/SpongePowered/SpongeAPI/pull/443","id":57125691,"number":443,"title":"Queryable Unified Inventory API","user":{"login":"Mumfrey","id":1147071,"avatar_url":"https://avatars.githubusercontent.com/u/1147071?v=3","gravatar_id":"","url":"https://api.github.com/users/Mumfrey","html_url":"https://github.com/Mumfrey","followers_url":"https://api.github.com/users/Mumfrey/followers","following_url":"https://api.github.com/users/Mumfrey/following{/other_user}","gists_url":"https://api.github.com/users/Mumfrey/gists{/gist_id}","starred_url":"https://api.github.com/users/Mumfrey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mumfrey/subscriptions","organizations_url":"https://api.github.com/users/Mumfrey/orgs","repos_url":"https://api.github.com/users/Mumfrey/repos","events_url":"https://api.github.com/users/Mumfrey/events{/privacy}","received_events_url":"https://api.github.com/users/Mumfrey/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/SpongePowered/SpongeAPI/labels/needs%20team%20review","name":"needs team review","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":28,"created_at":"2015-02-10T03:25:33Z","updated_at":"2015-02-12T23:22:28Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls/443","html_url":"https://github.com/SpongePowered/SpongeAPI/pull/443","diff_url":"https://github.com/SpongePowered/SpongeAPI/pull/443.diff","patch_url":"https://github.com/SpongePowered/SpongeAPI/pull/443.patch"},"body":"This pull request encapsulates a proposal for an Inventory API for Sponge. At the core it is based upon #242 by @gratimax but is revised and expanded to include the proposition outlined below. Please read all of this document before commenting on design specifics within this PR.\r\n\r\nThis is my first PR to the API side of things so be gentle.\r\n\r\nDesign Proposal for a Queryable Unified Inventory API\r\n----------------\r\n\r\nMany of the proposed systems for dealing with inventories in Sponge have been very close to the underlying Minecraft implementation of inventories, there are a number of drawbacks with this model:\r\n\r\n* Inventory topology is bifurcated into \"Inventories\", generally describing an actual container (the *Model*), and \"Containers\" which present a code-facing view of one or more \"Inventories\" (the *ViewModel*). Which has its own problems:\r\n * Generally the physical layout of the Inventory and the physical layout of the Container are not contractually linked in any meaningful way.\r\n * The terminology when referring to one or other of these constructs gets very wooly very quickly (especially with Containers that have a 1:1 mapping of \"slots\" to underlying Inventory position).\r\n \r\n The *View* in this instance (taking MVVM as our template) is a client-only user-facing object responsible for displaying the Container to the user.\r\n \r\n* Working with different types of inventory requires prior knowledge of the inventory's internal layout (interface is coupled invisibly to implementation) because there is no way to obtain *meta* information about a specific Inventory or Container. This means that:\r\n * consumers have to deal with the characteristics of specific inventories, and any code which wants to deal with different types of inventory must do so by handling each inventory type directly\r\n * This makes the API extremely brittle and not particularly extensible, since any types of inventory which are not *known about in advance* cannot be efficiently interacted with\r\n * Code which consumes the inventory API is *forced* to make assumptions which must then be forcibly invalidated (for example by throwing an exception) should the underlying behaviour of a particular inventory change. eg. the same brittleness applies to \"built in\" inventories as to mod-provided inventories over time and there is no way to deal gracefully with this.\r\n * In other words, assumptions *have* to be made, but there is no programmatic way for a consumer to *validate* those assumptions prior to operation\r\n* Because of the blurring of the distinction between Inventory and Container, functionality is cross-contaminated between the two concepts, and this lack of separation of concerns tends to (in turn) pollute any API which tries to faithfully replicate it.\r\n\r\n### Design Goals\r\n\r\nThe aim of this proposal is to address these shortcomings in the following ways:\r\n\r\n* Devise an API where *describing* an Inventory is a core aspect of interacting with an Inventory, essentially making Inventories *aspect-oriented*.\r\n* Provision for extensibility by allowing consumers to *query* an Inventory for the particular *aspect* they are interested in, and manipulate the inventory via the results of their queries.\r\n* Create a clear separation between Inventory and Container concepts but acknowledge their overlaps, by making Container essentially another aspect that an Inventory can have.\r\n\r\n### Starting Assumptions\r\n\r\nAs Morpheus famously said to Neo: *\"free your mind\"*.\r\n\r\nTo begin talking about a new structure for Inventory interaction, it's necessary to forget everything you currently understand about Inventories. Done that? Okay, let's start with the basic concepts.\r\n\r\n#### Common Inventory Operations\r\n\r\nIf we make **no other assumptions** about an inventory, we can essentially begin by declaring that, in many ways an Inventory exhibits the same behaviour as a `Queue` in that we can add items to the Inventory, consume items from the Inventory, and get the underlying capacity of the Inventory.\r\n\r\n```java\r\ninterface Inventory {\r\n\t/**\r\n\t * Get and remove the first available stack from this\r\n\t * Inventory\r\n\t */\r\n\tpublic abstract Optional<ItemStack> poll();\r\n\t\r\n\t/**\r\n\t * Get without removing the first available stack from this\r\n\t * Inventory\r\n\t */\r\n\tpublic abstract Optional<ItemStack> peek();\r\n\t\r\n\t/**\r\n\t * Try to put an ItemStack into this Inventory. Just like\r\n\t * Queue, this method returns true if the Inventory accepted\r\n\t * the stack and false if not, the size of the supplied\r\n\t * stack is reduced by the number of items successfully\r\n\t * consumed by the Inventory.\r\n\t */\r\n\tpublic abstract boolean offer(ItemStack stack);\r\n\t\r\n\t/**\r\n\t * The number of stacks in the Inventory\r\n\t */\r\n\tpublic abstract int size();\r\n\t\r\n\t/**\r\n\t * The maximum number of stacks the Inventory can hold\r\n\t */\r\n\tpublic abstract int capacity();\r\n}\r\n```\r\n\r\nNote that our base implementations of `poll` and `offer` don't provide any position information, this is because we are not making any other assumptions about the structure of the Inventory at this point. While this might seem like an odd baseline, it begins to make sense when we consider that with a query-based Inventory API, we will be returning inventories which fall into one of the following three categories:\r\n\r\n* **Empty Inventory** - to provide for a fluent interface we don't want to return null, the **Empty Inventory** will be our representation of an *empty result set*.\r\n* **Single-Stack Inventory** - an `Inventory` with a single stack is effectively a `Slot`. By keeping the `Inventory` interface simple enough that a `Slot` can reasonably extend it, we have simple unified way of a query returning anything from an entire Inventory, to a specific set of matching slots, to a single slot containing an Item we're looking for.\r\n* **Multi-Stack Inventory** - other inventories which can contain more than a single stack.\r\n\r\n#### Basis and Purpose of Queries\r\n\r\nBefore we look at how queries can work, let's first take a look at a simple use-case to understand the purpose of queries in the first place.\r\n\r\nThe `PlayerInventory` class actually encompasses several groups of inventory slots we may be interested in. These groups are internally (physically) separated into two arrays: the **Main Inventory** and the **Armour Inventory**. The **Main Inventory** comprises both the hotbar area (the 9 inventory slots always displayed on the screen) and the rest of the player's main inventory. Representing this as a basic Venn Diagram we see:\r\n\r\n![](http://eq2.co.uk/pr/inv/playerinv.png)\r\n\r\nWhen working directly with Minecraft, the two inner inventory arrays are available directly as public members of the `InventoryPlayer` class. However some additional functionality is available which supports both the *ViewModel*-esque contract required by Containers and also some additional convenience functions for working with only the hotbar slots. Some notable drawbacks with this mixing of concerns is that the following become apparent when working with the `PlayerInventory`:\r\n\r\n* Some methods treat the slots within the inventory as a contiguous set, and treat the **Armour Inventory** as indices beyond the **Main Inventory** indices whereas other code does not, this presents an inconsistent external interface.\r\n* Conversely, some methods only deal with the hotbar slots, and not the rest of the Inventory\r\n* No distinction is made between any positions in the inventory, thus external code has to \"know\" the meaning of slot indices within the Inventory in advance. *(A problem not confined to the `InventoryPlayer` class)*\r\n\r\nIt should be noted that this scenario is far from unique amongst inventories, and only gets worse when dealing with Containers. For example let's take a look at a container which you're likely to be very familiar with, `ContainerPlayer`:\r\n\r\n![](http://eq2.co.uk/pr/inv/playercontnr.png)\r\n\r\nThis container presents a View of 3 separate Inventories (essentially ViewModels) which in turn represent 4 distinct underlying arrays of slots (essentially the underlying Models).\r\n\r\nYou may find yourself asking *\"so what the hell does all this have to do with queries?\"* and that's a fair question. Ultimately we have 3 ways of dealing with this mess in order to improve it from the point of view of API consumers:\r\n\r\n1. Abstract the hell out of things. Provide \"sensible\" external interfaces and break everything down into small logical units which hide the underlying horribleness.\r\n * **Pros:**\r\n     * easy to work with from a consumer's point of view\r\n     * hides all the horrible internals\r\n * **Cons:**\r\n     * nasty to maintain (if anything in the implementation changes then the abstraction could get more and more complex)\r\n     * hard to extend (mod inventories and and kind of custom inventory are hard to work into this model because the abstractions themselves are \"hard coded\")\r\n     * makes simple operations more complex than they need to be (consumers need to explicitly dig through layers of abstraction to get to what they want)\r\n     * doesn't actually **add** any value, just hides all the nastiness\r\n2. Expose the underlying horribleness but provide a metadata system which assigns meaning to the exposed data structures, such as allowing a \"range\" of slots to be described.\r\n * **Pros:**\r\n     * doesn't add much overhead\r\n     * keeps people who are used to the old system happy\r\n     * provides added value in terms of some meta information about the meanings of slots\r\n * **Cons:**\r\n     * just as brittle as the underlying impementation\r\n     * doesn't provide any useful abstraction\r\n3. *(Using queries)* Make metadata an intrinsic part of the API and allow consumers to stipulate exactly what part of an inventory they *mean* by accessing inventory *via the metadata using queries*:\r\n * **Pros:**\r\n     * All the advantages of both option **1.** and **2.** (the underlying representations without metadata are *still accessible* via casting down - see implementation details below)\r\n     * Consumers only ask for what they need, they never need to care about what *type* of Inventory or Container they're dealing with, only the results of a query\r\n     * Intrinsically extensible - the nature of queries makes it easy for third-party extensibility without removing the ability to do simple `instanceof`-and-cast operations which would have been *required* before.\r\n * **Cons:**\r\n     * May be difficult for consumers to adjust to the new model (although the nature of the implementation means that stick-in-the-muds can still use the old model if they're foolhardy enough)\r\n     * Underlying implementation is more complex than other systems *(however it should be noted that all the complex logic will be handled in the initial implementation, and that ongoing __maintenance__ of the system will actually be __simpler__)*\r\n\r\nPresented with the options it's clear that option 3, using queries has merit.\r\n\r\n#### Goals for a Query-based implementation\r\n\r\nFundamental to the concept of querying Inventories is the basic premise that:\r\n\r\n* An **Inventory** is a **View** of **one or more \"sub inventories\"**\r\n* An **Inventory** and its **sub inventories** exist in a **parent-child** relationship\r\n* An **Inventory** is thus a **View of Views** with arbitrary depth\r\n\r\nIn the `InventoryPlayer` example above, the relationship of the Inventory to its notional sub-inventories is as follows:\r\n\r\n![](http://eq2.co.uk/pr/inv/invhierarchy.png)\r\n\r\nThe main idea of queries is that given an unknown `Inventory` instance, it should be possible to query for any sub-inventory or combination of matching sub-inventories, with the query returning either all sub-inventories which match the query, or an empty set if no sub-inventories matched the query.\r\n\r\nIt's useful to bear in mind that our above definition of `Inventory` essentially means that everything can be represented as an `Inventory` right down to `Slot` (defined as an `Inventory` with only a single position) and thus a more helpful representation when considering what can be returned by a query is the following:\r\n\r\n![](http://eq2.co.uk/pr/inv/invhierarchydeep.png)\r\n\r\nWe're now in a position to specify what a **query** should actually return:\r\n\r\n* A **Query** should return all **Sub Inventories** of the **Inventory** which match the supplied **criteria**\r\n* If a **sub inventory** is **included** in the results set, its **parent** will **not be**\r\n* A query will **never return a null** result, it will return an **Empty Inventory** object.\r\n* A query will **never return duplicate** entries\r\n\r\nWhich produces as a consequence some assumptions for `Inventory` itself:\r\n\r\n* The **result** of a query is always an `Inventory`\r\n* An `Inventory` is `Iterable<Inventory>` and the returned iterator traverses the child nodes of the Inventory's hierarchy\r\n* An `Inventory`'s leaf nodes should also be traversable via a method which returns an `Iterator`\r\n\r\nTo give some examples, based on the hierarchy above:\r\n\r\n* A query for an imaginary `Hotbar.class` should return the Hotbar inventory\r\n* A query for `ItemTypes.TNT` should return an Inventory with all of the slots containing TNT\r\n* A query for the imaginary `InventoryRow.class` should return each row in the Main Inventory and the Hotbar\r\n\r\nWhich produces the following assumptions:\r\n\r\n* When performing a query, if an `Inventory` matches the query directly, it should return itself\r\n* When performing a query, an `Inventory` should perform a depth-first search of its hierarchy. A matching child node will remove its parent from the results set if present.\r\n* If no children match the query, the query should return an `EmptyInventory`.\r\n* If all direct children match the query, the query should return the parent *(eg. if all InventoryRow children within an InventoryGrid match the query, then the InventoryGrid is returned)*\r\n\r\nWe now have enough information to begin formulating our query interface.\r\n\r\n### Inventory methods for query results\r\n\r\nSince the result of a Query will always be an `Inventory`, we add some decoration and methods to our `Inventory` interface. Firstly, we have the `Inventory` extend `Iterable<Inventory>` as planned. Next we add a method for iterating the leaf nodes of our `Inventory` and a convenience function for checking whether the `Inventory` has no slots:\r\n\r\n```java\r\ninterface Inventory extends Iterable<Inventory> {\r\n\t//\r\n\t// ... code code code (see above) ...\r\n\t//\r\n\r\n\t/**\r\n\t * Returns an iterable view of all slots, use type specifier to\r\n\t * allow easy pseudo-duck-typing\r\n\t */\r\n\tpublic abstract <T extends Inventory> Iterable<T> slots();\r\n\r\n\t/**\r\n\t * Returns true if this Inventory contains no children\r\n\t */\r\n\tpublic abstract boolean isEmpty();\r\n}\r\n```\r\n\r\nDepending on requirement, we **may** also wish to add some convenience methods to work with `Inventory`s which are result sets, for example\r\n\r\n```java\r\n\t/**\r\n\t * Return the first child inventory, effectively the same as\r\n\t * Inventory::iterator().next() but more convenient when we are\r\n\t * expecting a result set with only a single entry. Also use type\r\n\t * specifier to allow easy pseudo-duck-typing. If no children, then\r\n\t * returns this.\r\n\t */\r\n\tpublic abstract <T extends Inventory> T first();\r\n\r\n\t/**\r\n\t * Return the next sibling inventory, allows traversing the inventory\r\n\t * hierarchy without using an iterator. If no more children, returns\r\n\t * an EmptyInventory.\r\n\t */\r\n\tpublic abstract <T extends Inventory> T next();\r\n```\r\n\r\n\r\n### Inventory methods for executing queries\r\n\r\nIt is anticipated that the full scope and possibilities of queries will only become apparent in time, and also that the initial system should be sufficiently extensible to support quite a wide scope of potential queries. However the basic query types which should be in the initial release are:\r\n\r\n#### Query by type\r\n\r\n```java\r\npublic abstract <T extends Inventory> T query(Class<?>... types);\r\n```\r\n\r\nQuery for sub-inventories matching the specified interfaces/concrete classes (effictively an `instanceof` check). Multiple classes can be specified and logical `OR` will be applied.\r\n\r\n**Example 1:**\r\n```java\r\nInventory inv = ...; // An unknown inventory\r\nPlayerInventory pinv = inv.query(PlayerInventory.class).first();\r\n```\r\n\r\n**Example 2: Logical AND** _(querying the result of a query)_\r\n```java\r\nInventory inv = ...; // An unknown inventory\r\nHotBar hotbar = inv\r\n\t.query(InventoryRow.class)\r\n\t.query(HotBar.class).first();\r\n```\r\n\r\n#### Query by contents\r\n\r\n```java\r\npublic abstract <T extends Inventory> T query(ItemTypes... types);\r\n```\r\n\r\nQuery for slots containing `ItemStack`s with items of the specified type. A logical `OR` applied between query operands.\r\n\r\n**Example:**\r\n```java\r\nInventory inv = ...; // An unknown inventory\r\nInventory slotsWithTNT = inv.query(ItemTypes.TNT);\r\nif (!slotsWithTNT.isEmpty()) {\r\n    // found slots with TNT!\r\n}\r\n```\r\n\r\n#### Query by property\r\n\r\nAs well as defining a (possibly multi-dimensional) hierarchy of sub-inventories, it is anticipated that some sub-inventory types will tag their members with additional data which can be used to include them in queries. For example, let's assume that we have a `GridInventory` interface:\r\n\r\n```java\r\n/**\r\n * MetaInventory(?) stores arbitrary properties for child inventories\r\n */\r\ninterface MetaInventory extends Inventory {\r\n\t/**\r\n\t * Get a property defined in THIS inventory for the specified\r\n\t * (immediate) sub-inventory.\r\n\t */\r\n\tpublic abstract <T extends InventoryProperty> getProperty(Inventory child, Class<T> property);\r\n}\r\n\r\n/**\r\n * This type of inventory arranges its children in a grid.\r\n */\r\ninterface GridInventory extends MetaInventory {\r\n\t/**\r\n\t * Get the number of rows in the grid\r\n\t */\r\n\tpublic int getRows();\r\n\r\n\t/**\r\n\t * Get the number of columns in the grid\r\n\t */\r\n\tpublic int getColumns();\r\n\r\n\t/**\r\n\t * Get the X/Y position of the specified slot. The InventoryPos\r\n\t * class extends InventoryProperty and thus this method is just a\r\n\t * convenience method which effectively calls:\r\n\t * \r\n\t *    this.getProperty(slot, InventoryPos.class);\r\n\t */ \r\n\tpublic abstract InventoryPos getSlotPos(Inventory slot);\r\n}\r\n```\r\n\r\nAssuming that `InventoryPos` extends some ficticious base class `InventoryProperty`, we now have a mechanism for querying by any arbitrary properties we care to define:\r\n\r\n```java\r\npublic abstract <T extends Inventory> T query(InventoryProperty... props);\r\n```\r\n\r\nQuery for sub-inventories where the specified property is set and `.equals()` the supplied properties. Logical `OR` is applied between operands.\r\n\r\n**Example:**\r\n```java\r\nInventory inv = ...; // An unknown inventory\r\nInventory slots = inv.query(new InventoryPos(2, 2)).first();\r\n```\r\n\r\n#### Query by name\r\nSince in the real world, `Inventory` classes are always nameable, we can use a `String` overload to query by name:\r\n\r\n```java\r\npublic abstract <T extends Inventory> T query(String... names);\r\n```\r\n\r\n#### Query by arbitrary operands\r\n\r\nTo promote extensibilty, even where completely unknown Inventories are in play, we should also include a general query interface which will allow arbitrary queries to be executed:\r\n\r\n```java\r\npublic abstract <T extends Inventory> T query(Object... args);\r\n```\r\n\r\nQuery for sub-inventories using an arbitrary check defined by the inventory class in question.\r\n\r\n**Example:**\r\n```java\r\nInventory inv = ...; // An unknown inventory\r\nSomeObject someObject = ...; // Something\r\nInventory result = inv.query(someObject); // ???\r\n```\r\n\r\n### Multi-Dimensional Query Model\r\n\r\nSo far, for simplicity we have outlined a straightforward hierarchical model of the inventory. However it is not the intention that underlying implementations should adopt such a simple model. To facilitate querying by dimensions, we can represent underlying sub-inventories in as many different dimensions as we like, and allow queries to return corresponding views. For example we can expand our simple example above to allow the Inventory to be queried by column:\r\n\r\n![](http://eq2.co.uk/pr/inv/invhierarchymulti.png)\r\n\r\nIn this example the `InventoryGrid` contains both row and column sub-Inventories. This is by no means the limit of what can be represented by further dimensions. However note that one tree should always be considered the *master* view (a notional appellation), a traversal of which visits each leaf node in a deterministic order which is the iteration order as experienced by `slots()`.\r\n\r\nEssentially every Inventory should have a deterministic *spanning tree*, whose depth-first traversal will be the primary iteration order of the leaf nodes. This order is left to implementors to decide upon. Here is an example for the inventory structure shown above.\r\n\r\n**Example Spanning Tree for the Player Inventory**\r\n![](http://eq2.co.uk/pr/inv/invhierarchyspanning.png)\r\n\r\n**Example traversal of the Spanning Tree**\r\n![](http://eq2.co.uk/pr/inv/invhierarchytraverse.png)\r\n\r\n### Implications for Intended Usage\r\n\r\nSo far we have seen how queries can work in general, the main goals of incorporating queries into the API are to change the general way that consumers interact with Inventories. Without queries, a typical interaction with an Inventory might take place as follows:\r\n\r\n1. Consumer obtains an Inventory instance from an API object. The inventory is of a known type - eg. a `PlayerInventory` is obtained from a `Player` because it is advertised by the object.\r\n2. Knowing the type of inventory, the consumer performs some operations on the inventory: for example moving items from the main inventory to the hotbar, or consuming items from the inventory.\r\n\r\nNow if the same code wishes to interact with a different type of Inventory, the code has to be adapted or rewritten, even if the other inventory has substantially the same behaviour or characteristics.\r\n\r\nWith a query-based approach, the interaction takes place as follows:\r\n\r\n1. Consumer obtains an Inventory instance from an API object. The inventory is not a specialised type, the return type of the getter is simply `Inventory`.\r\n2. The consumer queries for the inventory characteristics it requires, for example it queries for all `InventoryRow`s\r\n3. The consumer interacts with the returned rows, or can simply skip processing if the query returns an empty set.\r\n\r\nIf the same code wishes to interact with a different type of Inventory, it can do so as long as the Inventory has `InventoryRow` children.\r\n\r\n> **SIDE NOTE**\r\n> Consider porting of old code. Old code may simply (as a stop-gap) wish to obtain the `PlayerInventory` and manipulate it directly, without any queries. With queries this is still supported as long as `PlayerInventory` is provided as an interface in the API. Consumers wishing to perform legacy interactions can either:\r\n> \r\n> 1. Query directly for the `InventoryPlayer` interface *(this works because of assumption 1 of queries - if an inventory matches a query it simply returns itself)*\r\n> 2. Use an `instanceof` check followed by a type cast\r\n>\r\n>This provides a convenient way for legacy code to be ported quickly to the new system, and transition to a full query-based implementation at the convenience of the plugin author.\r\n\r\nTaking the intended usage into account, we can deduce some additional characteristics our API should have:\r\n\r\n* Any API object which has an Inventory should simply return `Inventory`, with no requirement to return a particular subinterface\r\n\r\n* Consumers should *always* obtain `Inventory` subclasses by querying for them (either directly or via `instanceof` check)\r\n\r\n* Specific Inventory subinterfaces should still be provided within the API in order to satisfy queries, however they should not generally be returned and different implementations are therefore at liberty to select whichever interfaces they wish to implement - in other words there is no hard rule that says a `PlayerInventory` must have `InventoryRow`s as children for example, the query model means that this is purely optional and the only negative effect would be that consumers expecting such a structure would not be able to perform their operations.\r\n\r\n This works in both directions however, and while it is expected that all implementations will likely follow similar conventions (in order that queries can be relied upon across platforms), it's also possible that some implementations will be able to innovate, and extend their capabilities without in any way breaking backward compatibility.\r\n\r\n The implication of all this is that the shape and design of the underlying Inventories is thus free to follow a logical representation of the underlying game *without* at any point breaking backward compatibility.\r\n \r\n* This in turn leads us to the conclusion that the number of \"specific\" inventories should be kept to a minimum, and general-purpose Inventory interfaces should be used wherever possible. The general-purpose Inventory interfaces should essentially represent *characteristics* of inventories, with little regard for specific Inventory types.\r\n\r\n### Relationship with Containers\r\n\r\nIt should be clear by now that a query-based model also solves the Container problem. By acknowledging that the line between Inventory and Container can often be blurry, we can treat Containers as Inventories for the most part (since we have essentially turned Inventory into a ViewModel at this point anyway, and all a Container really is is a ViewModel) and simply have them exist as yet another type of SubInventory interface.\r\n\r\n## Features *not* included within this PR\r\n\r\nTaking a longer view, the following features are worthy of consideration\r\n\r\n* **Inventory Transactions** - basically SQL transactions but for Inventories allowing *commit* and *rollback* operations\r\n\r\n* **Aggregate Inventory Operations** - basically SQL join for queries, such that a logical union of inventories can be created and subsequently queried and operated upon as if it were a single inventory. *This isn't too hard to do I just don't have sufficient time to flesh it out*.\r\n\r\n* **Atomic Multi-Inventory Operations** - as a poor second choice to full-blown transactional behaviour, having atomic operations (get-stack-from-first-inventory, deposit-in-second) would still be useful.\r\n\r\n* **Cookies** - congratulations, if you read this far you get a cookie *(Not a real cookie, an imaginary one. What? You think I'm made of cookies or something?)*\r\n"},"comment":{"url":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues/comments/74175354","html_url":"https://github.com/SpongePowered/SpongeAPI/pull/443#issuecomment-74175354","issue_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues/443","id":74175354,"user":{"login":"Aaron1011","id":1408859,"avatar_url":"https://avatars.githubusercontent.com/u/1408859?v=3","gravatar_id":"","url":"https://api.github.com/users/Aaron1011","html_url":"https://github.com/Aaron1011","followers_url":"https://api.github.com/users/Aaron1011/followers","following_url":"https://api.github.com/users/Aaron1011/following{/other_user}","gists_url":"https://api.github.com/users/Aaron1011/gists{/gist_id}","starred_url":"https://api.github.com/users/Aaron1011/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aaron1011/subscriptions","organizations_url":"https://api.github.com/users/Aaron1011/orgs","repos_url":"https://api.github.com/users/Aaron1011/repos","events_url":"https://api.github.com/users/Aaron1011/events{/privacy}","received_events_url":"https://api.github.com/users/Aaron1011/received_events","type":"User","site_admin":false},"created_at":"2015-02-12T23:22:28Z","updated_at":"2015-02-12T23:22:28Z","body":"A few suggestions:\r\n\r\n* Clarify the behavior of `Inventory#getProperty` when multiple `InventoryProperty`s could be returned\r\n  * This could occur if two subtypes of, for example, `IntPropery`, are sent, and `getProperty(IntProperty.class)` is called\r\n* Allow multiple properties of the same class (or with a common ancestor) to be set. This is related to the above point\r\n* Allow querying an Inventory with a specific `InventoryPropery` *class*, as opposed to a particular instance."}}