2.17.2: 2011-06-17

net.sf.basedb.core
Class BioMaterialList

java.lang.Object
  extended by net.sf.basedb.core.BasicItem<D>
      extended by net.sf.basedb.core.OwnedItem<D>
          extended by net.sf.basedb.core.SharedItem<D>
              extended by net.sf.basedb.core.CommonItem<BioMaterialListData>
                  extended by net.sf.basedb.core.BioMaterialList
All Implemented Interfaces:
AccessControlled, Identifiable, Nameable, Ownable, Removable, Shareable

public class BioMaterialList
extends CommonItem<BioMaterialListData>

This class represents a list of biomaterials.

Version:
2.10
Author:
Nicklas
Last modified
$Date: 2009-06-25 15:11:37 +0200 (Thu, 25 Jun 2009) $

Field Summary
static int MAX_EXTERNAL_ID_LENGTH
          The maximum length of the external id variable that can be stored in the database.
static Item TYPE
          The type of item represented by this class.
 
Fields inherited from interface net.sf.basedb.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
 
Constructor Summary
BioMaterialList(BioMaterialListData listData)
           
 
Method Summary
 boolean add(BioMaterial bioMaterial)
          Add a biomaterial to this list.
 int add(Iterator<? extends BioMaterial> it)
          Add multiple biomaterials to this list in one go.
 int addAll(BioMaterialList list)
          Add all items from another biomaterial list to this list.
 int addIfPresentIn(int minCount, int maxCount, Collection<BioMaterialList> lists)
          Add items that are present in the specified number of lists to this list.
 int addIntersection(Collection<BioMaterialList> lists)
          Add items that are present in ALL OF the given lists to this list.
private  int addMembers(Set<BioMaterialData> items)
          Add members to this list.
 int addUnion(Collection<BioMaterialList> lists)
          Add items that are present in at least ONE OF the given lists to this list.
private  void checkMemberType(Collection<BioMaterialList> lists)
          Checks that the lists have the same member type as this list.
private  void checkMemberType(Item otherType)
          Checks if the other type is the same type as the member type of this list.
private static Set<BioMaterialData> count(Collection<BioMaterialList> lists, int minCount, int maxCount)
          Count the number of times each item is present in the given lists and return those items that are found in >=minCount and <=maxCount lists.
 ItemQuery<? extends BioMaterial> getAllBioMaterials()
          Get a query that returns all biomaterials that can possibly be members of this list.
static BioMaterialList getById(DbControl dc, int id)
          Get a BioMaterialList item when you know the id.
 String getExternalId()
          Get the external id for this list.
 ItemQuery<? extends BioMaterial> getMemberBioMaterials()
          Get a query that returns all biomaterials that are members of this list.
 Item getMemberType()
          Get the item type of members on this list.
static BioMaterialList getNew(DbControl dc, Item memberType)
          Create a new BioMaterialList item.
static ItemQuery<BioMaterialList> getQuery()
          Get a query that returns biomaterial lists.
 int getSize()
          Get the number of members in this list.
 Item getType()
          Get the type of item represented by the object.
private static Set<BioMaterialData> intersection(Collection<BioMaterialList> lists)
          Create a set with the intersection of the items in the given lists.
 void remove(BioMaterial bioMaterial)
          Remove a biomaterial from the list.
 int removeAll(BioMaterialList list)
          Remove all items from this list that are present in the other list.
 int removeIfPresentIn(int minCount, int maxCount, Collection<BioMaterialList> lists)
          Remove items that are present in the specified number of lists from this list.
 int removeIntersection(Collection<BioMaterialList> lists)
          Remove items that are present in ALL OF the given lists from this list.
private  int removeMembers(Set<BioMaterialData> items)
          Remove members from this list
 int removeUnion(Collection<BioMaterialList> lists)
          Remove items that are present in at least ONE OF the given lists from this list.
 int retainAll(BioMaterialList list)
          Remove all items from this list that are NOT present in the other list.
 int retainIfPresentIn(int minCount, int maxCount, Collection<BioMaterialList> lists)
          Retain items that are present in the specified number of lists in this list.
 int retainIntersection(Collection<BioMaterialList> lists)
          Retain items that are present in ALL OF the given lists in this list.
private  int retainMembers(Set<BioMaterialData> items)
          Keep only specified members in this list
 int retainUnion(Collection<BioMaterialList> lists)
          Retain items that are present in at least ONE OF the given lists in this list.
 void setExternalId(String externalId)
          Set the external id for this list.
private  void setMemberType(Item memberType)
           
private static Set<BioMaterialData> union(Collection<BioMaterialList> lists)
          Create a set with the union of the items in the given lists.
 
Methods inherited from class net.sf.basedb.core.CommonItem
getDescription, getName, isRemoved, setDescription, setName, setRemoved, toTransferable
 
Methods inherited from class net.sf.basedb.core.SharedItem
getItemKey, getProjectKey, initPermissions, isShared, onBeforeCommit, setItemKey, setProjectKey, toTransferable
 
Methods inherited from class net.sf.basedb.core.OwnedItem
getOwner, isOwner, setOwner, takeOwnership, toTransferable
 
Methods inherited from class net.sf.basedb.core.BasicItem
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, onRollback, setDbControl, setProjectDefaults, toString, toTransferable, validate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.basedb.core.Identifiable
getId, getVersion
 
Methods inherited from interface net.sf.basedb.core.AccessControlled
checkPermission, getPermissions, hasPermission
 
Methods inherited from interface net.sf.basedb.core.Ownable
getOwner, isOwner, setOwner, takeOwnership
 

Field Detail

TYPE

public static final Item TYPE
The type of item represented by this class.

See Also:
Item.BIOMATERIALLIST, getType()

MAX_EXTERNAL_ID_LENGTH

public static final int MAX_EXTERNAL_ID_LENGTH
The maximum length of the external id variable that can be stored in the database. Check the length against this value before calling the setExternalId(String) method to avoid exceptions.

See Also:
Constant Field Values
Constructor Detail

BioMaterialList

BioMaterialList(BioMaterialListData listData)
Method Detail

getNew

public static BioMaterialList getNew(DbControl dc,
                                     Item memberType)
                              throws BaseException
Create a new BioMaterialList item.

Parameters:
dc - The DbControl which will be used for permission checking and database access
memberType - The item type of members in this list
Returns:
The new BioMaterialList item
Throws:
BaseException - If there is an error

getById

public static BioMaterialList getById(DbControl dc,
                                      int id)
                               throws ItemNotFoundException,
                                      PermissionDeniedException,
                                      BaseException
Get a BioMaterialList item when you know the id.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
id - The id of the item to load
Returns:
The BioMaterialList item
Throws:
ItemNotFoundException - If an item with the specified id is not found
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the item
BaseException - If there is another error

getQuery

public static ItemQuery<BioMaterialList> getQuery()
Get a query that returns biomaterial lists.

Returns:
An ItemQuery object

intersection

private static Set<BioMaterialData> intersection(Collection<BioMaterialList> lists)
Create a set with the intersection of the items in the given lists.

Returns:
A set with items. The set is always a new set, modifications to it will not affect anything else

union

private static Set<BioMaterialData> union(Collection<BioMaterialList> lists)
Create a set with the union of the items in the given lists.

Returns:
A set with items. The set is always a new set, modifications to it will not affect anything else

count

private static Set<BioMaterialData> count(Collection<BioMaterialList> lists,
                                          int minCount,
                                          int maxCount)
Count the number of times each item is present in the given lists and return those items that are found in >=minCount and <=maxCount lists.

NOTE!

Parameters:
lists - The lists to look in
minCount - The minimum number of list an item is required to be present in
maxCount - The maximum number of lists an item is allowed to the present in
Returns:
A set with items. It is always a new set, modifications to it will not affect anything else

getType

public Item getType()
Description copied from interface: Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in the Item enumeration.

Returns:
A value indicating the type of item

getExternalId

public String getExternalId()
Get the external id for this list.

Returns:
A string with the external id of this item, or null

setExternalId

public void setExternalId(String externalId)
                   throws PermissionDeniedException,
                          InvalidDataException
Set the external id for this list. Null is allowed, but the value must not be longer than the value specified by the MAX_EXTERNAL_ID_LENGTH constant. The value doesn't have to be unique.

Parameters:
externalId - The new external id for this item
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the new value is longer than MAX_EXTERNAL_ID_LENGTH

getSize

public int getSize()
Get the number of members in this list.


getMemberType

public Item getMemberType()
Get the item type of members on this list.

Returns:
An Item object

setMemberType

private void setMemberType(Item memberType)

checkMemberType

private void checkMemberType(Item otherType)
Checks if the other type is the same type as the member type of this list.


checkMemberType

private void checkMemberType(Collection<BioMaterialList> lists)
Checks that the lists have the same member type as this list.


add

public boolean add(BioMaterial bioMaterial)
            throws PermissionDeniedException,
                   InvalidDataException
Add a biomaterial to this list.

Parameters:
bioMaterial - The biomaterial to add to the list
Returns:
TRUE if the biomaterial was added, FALSE if it already existed in this list
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the biomaterial is null or not of the correct member type

add

public int add(Iterator<? extends BioMaterial> it)
        throws PermissionDeniedException,
               InvalidDataException
Add multiple biomaterials to this list in one go.

Parameters:
it - An iterator that returns all biomaterials to be added, null items are ignored
Returns:
The numer of added biomaterials
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the iterator returns a biomaterial of a different type than getMemberType()

remove

public void remove(BioMaterial bioMaterial)
            throws PermissionDeniedException,
                   InvalidDataException
Remove a biomaterial from the list.

Parameters:
bioMaterial - The biomaterial to remove.
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the biomaterial is null

getMemberBioMaterials

public ItemQuery<? extends BioMaterial> getMemberBioMaterials()
                                                       throws BaseException
Get a query that returns all biomaterials that are members of this list.

Returns:
An ItemQuery object
Throws:
BaseException - If the query could not be created and configured.

getAllBioMaterials

public ItemQuery<? extends BioMaterial> getAllBioMaterials()
                                                    throws BaseException
Get a query that returns all biomaterials that can possibly be members of this list. NOTE! This is just a convenience function that calls BioSource.getQuery(), etc. depending on the member type of the list.

Returns:
An ItemQuery object
Throws:
BaseException - If the query could not be created and configured
See Also:
ListUtil.getQuery(Item)

addMembers

private int addMembers(Set<BioMaterialData> items)
Add members to this list.

Parameters:
items - The items to add
Returns:
The number of new items

removeMembers

private int removeMembers(Set<BioMaterialData> items)
Remove members from this list

Parameters:
items - The items to remove
Returns:
The number of removed items

retainMembers

private int retainMembers(Set<BioMaterialData> items)
Keep only specified members in this list

Parameters:
items - The items to keep
Returns:
The number of removed items

addAll

public int addAll(BioMaterialList list)
Add all items from another biomaterial list to this list. The new list is the union of the existing list and the added list. The other list must have the same member type as this list.

Parameters:
list - The list to add items from
Returns:
The number of items added (not including items that already was in this list)

addUnion

public int addUnion(Collection<BioMaterialList> lists)
Add items that are present in at least ONE OF the given lists to this list. Eg. the added items is the union from the given lists.

Parameters:
lists - The lists to add items from
Returns:
The number of items added (not including items that already was in this list)

addIfPresentIn

public int addIfPresentIn(int minCount,
                          int maxCount,
                          Collection<BioMaterialList> lists)
Add items that are present in the specified number of lists to this list.

Parameters:
lists - The lists to add items from
minCount - The minimum number of lists an item is required to be present in
maxCount - The maximum number of lists an item is allowed to be present in
Returns:
The number of items added (not including items that already was in this list)

addIntersection

public int addIntersection(Collection<BioMaterialList> lists)
Add items that are present in ALL OF the given lists to this list. Eg. the added items is the intersection from the given lists.

Parameters:
lists - The lists to add items from
Returns:
The number of items added (not including items that already was in this list)

removeAll

public int removeAll(BioMaterialList list)
Remove all items from this list that are present in the other list.

Parameters:
list - The list that contains the items to remove
Returns:
The number of items removed from this list

removeUnion

public int removeUnion(Collection<BioMaterialList> lists)
Remove items that are present in at least ONE OF the given lists from this list. Eg. the removed items is the union from the given lists.

Parameters:
lists - The lists that contains the items to remove
Returns:
The number of items removed from this list

removeIfPresentIn

public int removeIfPresentIn(int minCount,
                             int maxCount,
                             Collection<BioMaterialList> lists)
Remove items that are present in the specified number of lists from this list.

Parameters:
lists - The lists with the items
minCount - The minimum number of lists an item is required to be present in
maxCount - The maximum number of lists an item is allowed to be present in
Returns:
The number of items removed

removeIntersection

public int removeIntersection(Collection<BioMaterialList> lists)
Remove items that are present in ALL OF the given lists from this list. Eg. the removed items is the intersection from the given lists.

Parameters:
lists - The lists that contains the items to remove
Returns:
The number of items removed from this list

retainAll

public int retainAll(BioMaterialList list)
Remove all items from this list that are NOT present in the other list. The new list is the intersection of the existing list and the other list. NOTE! If the other list is null or empty, all items will be removed from this list.

Parameters:
list - The list that contains the items to be retained
Returns:
The number of items removed from this list

retainUnion

public int retainUnion(Collection<BioMaterialList> lists)
Retain items that are present in at least ONE OF the given lists in this list. Eg. items that are not found in any of the given lists are removed from this list.

Parameters:
lists - The lists that contains the items to retain
Returns:
The number of items removed from this list

retainIntersection

public int retainIntersection(Collection<BioMaterialList> lists)
Retain items that are present in ALL OF the given lists in this list. Eg. items that are not found in all lists of the given lists are removed from this list.

Parameters:
lists - The lists that contains the items to retain
Returns:
The number of items removed from this list

retainIfPresentIn

public int retainIfPresentIn(int minCount,
                             int maxCount,
                             Collection<BioMaterialList> lists)
Retain items that are present in the specified number of lists in this list.

Parameters:
lists - The lists with the items
minCount - The minimum number of lists an item is required to be present in
maxCount - The maximum number of lists an item is allowed to be present in
Returns:
The number of items removed

2.17.2: 2011-06-17