Thread: [mud4j-commit] SF.net SVN: mud4j: [56] trunk/mud4j-core/src/java/net/sf/mud4j/world/item/ Container
Status: Pre-Alpha
Brought to you by:
mpurland
From: <mpu...@us...> - 2006-12-24 18:36:08
|
Revision: 56 http://mud4j.svn.sourceforge.net/mud4j/?rev=56&view=rev Author: mpurland Date: 2006-12-24 10:36:06 -0800 (Sun, 24 Dec 2006) Log Message: ----------- Add container item type. Added Paths: ----------- trunk/mud4j-core/src/java/net/sf/mud4j/world/item/ContainerItemType.java Added: trunk/mud4j-core/src/java/net/sf/mud4j/world/item/ContainerItemType.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/world/item/ContainerItemType.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/world/item/ContainerItemType.java 2006-12-24 18:36:06 UTC (rev 56) @@ -0,0 +1,99 @@ +/** + * Copyright 2006 Matthew Purland (m.p...@gm...) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sf.mud4j.world.item; + +import java.util.ArrayList; +import java.util.List; + +/** + * Container item type for managing a collection of items within + * it. + * + * @author Matthew Purland + */ +public class ContainerItemType extends AbstractItemType { + + // Capacity for the item container + private int initialCapacity; + private List<Item> itemList; + + /** + * Create an container item type with an initial capacity. + * + * @param initialCapacity Initial capacity of the item list. + */ + public ContainerItemType(int initialCapacity) { + this.initialCapacity = initialCapacity; + itemList = new ArrayList<Item>(initialCapacity); + } + + /** + * Add an item to the container. + * + * @param item Item to add to the container. + */ + public void addItem(Item item) { + itemList.add(item); + } + + /** + * Remove an item from the container. + * + * @param item Item to remove from the container. + */ + public void removeItem(Item item) { + itemList.remove(item); + } + + private int getInitialCapacity() { + return initialCapacity; + } + + private int getSize() { + return itemList.size(); + } + + /** + * {@inheritDoc} + */ + @Override + public int compareTo(Object o) { + if (o instanceof ContainerItemType) { + ContainerItemType itemType = (ContainerItemType) o; + + // First compare by initial capacity + if (getInitialCapacity() > itemType.getInitialCapacity()) { + return 1; + } + else if (getInitialCapacity() < itemType.getInitialCapacity()) { + return -1; + } + // If they are of equal initial capacity, then compare by + // their current sizes + else { + if (getSize() > itemType.getSize()) { + return 1; + } + else if (getSize() < itemType.getSize()) { + return -1; + } + } + } + + return 0; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpu...@us...> - 2006-12-30 04:56:51
|
Revision: 77 http://mud4j.svn.sourceforge.net/mud4j/?rev=77&view=rev Author: mpurland Date: 2006-12-29 20:56:49 -0800 (Fri, 29 Dec 2006) Log Message: ----------- Update javadoc comments. Modified Paths: -------------- trunk/mud4j-core/src/java/net/sf/mud4j/world/item/ContainerItemType.java Modified: trunk/mud4j-core/src/java/net/sf/mud4j/world/item/ContainerItemType.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/world/item/ContainerItemType.java 2006-12-30 04:55:10 UTC (rev 76) +++ trunk/mud4j-core/src/java/net/sf/mud4j/world/item/ContainerItemType.java 2006-12-30 04:56:49 UTC (rev 77) @@ -19,8 +19,7 @@ import java.util.List; /** - * Container item type for managing a collection of items within - * it. + * Item type for providing behavior to a container item to contain other items. * * @author Matthew Purland */ @@ -62,6 +61,11 @@ return initialCapacity; } + /** + * Get total size of the container. + * + * @return Return size of the container. + */ private int getSize() { return itemList.size(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |