Holger's Java API

## com.antelmann.cddb
Class SimpleCDCollection

    java.lang.Object
      com.antelmann.cddb.SimpleCDCollection

All Implemented Interfaces:
  CDCollection, Serializable, Iterable<CDID>

    public class SimpleCDCollection

extends Object
implements CDCollection, Serializable, Iterable<CDID>

Just a very simple reference implementation for a CDCollection based on a bunch of files stored in a directory.

The file storage concept is somewhat similar to the CDDB file storage concept, but without subdirectories for categories. Simply reserve a directory for a class instance, as all files in that directory are considered part of the CD collection.

Conventions for this class: an embedded CDSet export is stored in a file relative to the given base directory and it is named cd.set (see CDSET_LOCATION). All other files in that same directory are user property files named by the discID that is associated with the properties. Property files not associated with a CD in the set are ignored; the content of these property files is standard xmcd format.

This rather simple implementation is designed for smaller collections, everything is held in memory and made persistent on request. For larger, more sophisticated CDCollections supporting queries, consider a different implementation.

Author:
  Holger Antelmann
See Also:
  `CDSet`, Serialized Form

Field Summary
`String` `CDSET_LOCATION` the filename where the CDSet is stored relative to the base dir
`String` `COL_CATEGORY` the category used for creating records from collection entries

Constructor Summary
`SimpleCDCollection(File baseDirectory)` initializes the collection based on the content found in the given directory

Method Summary
`boolean` `addCD(CDID cd)` adds the given cd to the collection and returns true only if the CD was added
`boolean` `contains(CDID cd)` returns true only if the given cd is in this collection
`CDInfo` `getCDInfo(CDID cd)` returns a CDDBEntry object
`Properties` `getCDProperties(CDID cd)` returns all user-properties available for a specific CD (as far as applicable) or null if the CD is not in the collection.
`Set<CDID>` `getCDSet()` returns an unmodifiable view over the set of CDID instances in the collection
`Iterator<CDID>` `iterator()`
`boolean` `removeCD(CDID cd)` removes the given cd to the collection and returns true only if the CD was removed
`CDInfo[]` `searchContent(String pattern)` searches the entire xmcd format content for the exact given pattern.
`void` `setCDInfo(CDID cd, CDInfo info)` associates the given info with the given cd in this collection; if the given cd is not yet in the collection, it is added.
`void` `setCDInfo(CDID cd, String xmcdString)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### CDSET_LOCATION

    public final String CDSET_LOCATION

  the filename where the CDSet is stored relative to the base dir

  See Also:
    Constant Field Values

### COL_CATEGORY

    public final String COL_CATEGORY

  the category used for creating records from collection entries

  See Also:
    Constant Field Values

Constructor Detail

### SimpleCDCollection

    public SimpleCDCollection(File baseDirectory)
                       throws IOException

  initializes the collection based on the content found in the given directory

  Throws:
    `IOException`

Method Detail

### iterator

    public Iterator<CDID> iterator()

  Specified by:
    `iterator` in interface `Iterable<CDID>`

### contains

    public boolean contains(CDID cd)

  Description copied from interface: `CDCollection`
  returns true only if the given cd is in this collection

  Specified by:
    `contains` in interface `CDCollection`

### addCD

    public boolean addCD(CDID cd)

  Description copied from interface: `CDCollection`
  adds the given cd to the collection and returns true only if the CD was added

  Specified by:
    `addCD` in interface `CDCollection`

### removeCD

    public boolean removeCD(CDID cd)

  Description copied from interface: `CDCollection`
  removes the given cd to the collection and returns true only if the CD was removed

  Specified by:
    `removeCD` in interface `CDCollection`

### getCDInfo

    public CDInfo getCDInfo(CDID cd)

  returns a CDDBEntry object

  Specified by:
    `getCDInfo` in interface `CDCollection`
  See Also:
    `CDDBEntry`

### setCDInfo

    public void setCDInfo(CDID cd,
                          CDInfo info)

  Description copied from interface: `CDCollection`
  associates the given info with the given cd in this collection; if the given cd is not yet in the collection, it is added.

  Specified by:
    `setCDInfo` in interface `CDCollection`

### setCDInfo

    public void setCDInfo(CDID cd,
                          String xmcdString)

### getCDSet

    public Set<CDID> getCDSet()

  Description copied from interface: `CDCollection`
  returns an unmodifiable view over the set of CDID instances in the collection

  Specified by:
    `getCDSet` in interface `CDCollection`

### getCDProperties

    public Properties getCDProperties(CDID cd)

  Description copied from interface: `CDCollection`
  returns all user-properties available for a specific CD (as far as applicable) or null if the CD is not in the collection.

  (For instance, the properties could map keys like year.bought to the value 2002 or the alike.)

  Note: An implementing class should specify if the changes in the returned properties are reflected on the actual properties associated with the CD in the collection; otherwise you would assume being given a generated view of the properties that internally are maintained differently.

  Specified by:
    `getCDProperties` in interface `CDCollection`

### searchContent

    public CDInfo[] searchContent(String pattern)

  searches the entire xmcd format content for the exact given pattern. if no results are found, an empty array is returned.

  Returns:
    an array containing the qualifying CDDBEntry objects

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads