[Biojava-dev] Suggestions for the BioJava project
Michael Heuer
heuermh at acm.org
Tue Aug 16 15:01:19 EDT 2005
Hello Mark, Richard
This is very cool. I took a quick look and noticed a few consistency
problems and several different styles of javadoc comments, but nothing
major. I'll wait until development slows down a bit before submitting
any style-related patches.
Unfortunately it's a little bit late, now that you already have something
that works, but I committed a source code generation library and shell
interface to the biojava subversion repository, at
> http://www.derkholm.net/svn/repos/biojava-expr/trunk/codegen/
> http://www.derkholm.net/svn/repos/biojava-expr/trunk/codegen-shell/
to save myself a lot of typing, particularly in javadoc comments.
You do a little of this
$ java -jar codegen-shell.jar
% InterfaceDescription foo = new InterfaceDescription("Foo");
% foo.attribute(..., Cardinality.ZeroToOne);
% foo.associate(..., Cardinality.OneToMany);
% ClassDescription simpleFoo = new ClassDescription("SimpleFoo");
% simpleFoo.realizes(foo);
% generateSource(foo);
% generateSource(simpleFoo, Style.RichlyMutable);
and you get something like
(sorry if the formatting doesn't work out)
--- Foo.java
import java.util.Set;
import java.util.List;
import java.util.SortedSet;
/**
* foo
*
* @author codegen
* @version $Revision$ $Date$
*/
public interface Foo
{
/**
* Return the foo id for this foo.
* The foo id will not be null.
*
* @return the foo id for this foo
*/
Long getFooId();
/**
* Return the name for this foo.
* The name may be null.
*
* @return the name for this foo
*/
String getName();
/**
* Return an unmodifiable set of synonyms
* for this foo. The returned set may be
* empty but will not be null.
*
* @return an unmodifiable set of synonyms
* for this foo
*/
Set<String> getSynonyms();
/**
* Return an unmodifiable list of positions
* for this foo. The returned list will
* not be null and will contain at least one position.
*
* @return an unmodifiable list of positions
* for this foo
*/
List<Integer> getPositions();
/**
* Return the optional bar for this foo.
* The optional bar may be null.
*
* @return the optional bar for this foo
*/
Bar getOptionalBar();
/**
* Return the required bar for this foo.
* The required bar will not be null.
*
* @return the required bar for this foo
*/
Bar getRequiredBar();
/**
* Return an unmodifiable list of additional bars
* for this foo. The returned list may be
* empty but will not be null.
*
* @return an unmodifiable list of additional bars
* for this foo
*/
List<Bar> getAdditionalBars();
/**
* Return an unmodifiable sorted set of other bars
* for this foo. The returned sorted set will
* not be null and will contain at least one other bar.
*
* @return an unmodifiable sorted set of other bars
* for this foo
*/
SortedSet<Bar> getOtherBars();
}
--- SimpleFoo.java:
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.SortedSet;
import java.util.TreeSet;
/**
* simple foo.
*
* @author codegen
* @version $Revision$ $Date$
*/
public class SimpleFoo
implements Foo
{
/** The foo id for this simple foo. */
private Long fooId;
/** The name for this simple foo. */
private String name;
/** The set of synonyms for this simple foo. */
private final Set<String> synonyms;
/** The list of positions for this simple foo. */
private final List<Integer> positions;
/** The optional bar for this simple foo. */
private Bar optionalBar;
/** The required bar for this simple foo. */
private Bar requiredBar;
/** The list of additional bars for this simple foo. */
private final List<Bar> additionalBars;
/** The sorted set of other bars for this simple foo. */
private final SortedSet<Bar> otherBars;
/**
* Create a new simple foo from the specified required parameters.
*
* <p>The specified list of positions must contain at least one position.
* The positions in <code>positions</code> are copied defensively
* into this class.</p>
*
* <p>The specified sorted set of other bars must contain at least one other bar.
* The other bars in <code>otherBars</code> are copied defensively
* into this class.</p>
*
* @param fooId foo id for this simple foo, must not be null
* @param positions list of integers, must not be null and must
* contain at least one integer
* @param requiredBar required bar for this simple foo, must not be null
* @param otherBars sorted set of bars, must not be null and must
* contain at least one bar
*
* @throws IllegalArgumentException if <code>positions.size() < 1</code>
*
* @throws IllegalArgumentException if <code>otherBars.size() < 1</code>
*/
public SimpleFoo(
final Long fooId,
final List<Integer> positions,
final Bar requiredBar,
final SortedSet<Bar> otherBars)
{
if (fooId == null)
{
throw new IllegalArgumentException("fooId must not be null");
}
if (positions == null)
{
throw new IllegalArgumentException("positions must not be null");
}
if (positions.size() < 1)
{
throw new IllegalArgumentException("positions must contain at least one position");
}
if (requiredBar == null)
{
throw new IllegalArgumentException("requiredBar must not be null");
}
if (otherBars == null)
{
throw new IllegalArgumentException("otherBars must not be null");
}
if (otherBars.size() < 1)
{
throw new IllegalArgumentException("otherBars must contain at least one other bar");
}
setFooId(fooId);
setName(null);
this.synonyms = new HashSet<String>();
this.positions = new ArrayList<Integer>(positions));
setOptionalBar(null);
setRequiredBar(requiredBar);
this.additionalBars = new ArrayList<Bar>();
this.otherBars = new TreeSet<Bar>(otherBars);
}
/**
* Create a new simple foo from the specified parameters.
*
* <p>The synonyms in <code>synonyms</code> are copied defensively
* into this class.</p>
*
* <p>The specified list of positions must contain at least one position.
* The positions in <code>positions</code> are copied defensively
* into this class.</p>
*
* <p>The additional bars in <code>additionalBars</code> are copied defensively
* into this class.</p>
*
* <p>The specified sorted set of other bars must contain at least one other bar.
* The other bars in <code>otherBars</code> are copied defensively
* into this class.</p>
*
* @param fooId foo id for this simple foo, must not be null
* @param name name for this simple foo
* @param synonyms set of synonyms, must not be null
* @param positions list of integers, must not be null and must
* contain at least one integer
* @param optionalBar optional bar for this simple foo
* @param requiredBar required bar for this simple foo, must not be null
* @param additionalBars list of additional bars, must not be null
* @param otherBars sorted set of bars, must not be null and must
* contain at least one bar
*
* @throws IllegalArgumentException if <code>positions.size() < 1</code>
*
* @throws IllegalArgumentException if <code>otherBars.size() < 1</code>
*/
public SimpleFoo(
final Long fooId,
final String name,
final Set<String> synonyms,
final List<Integer> positions,
final Bar optionalBar,
final Bar requiredBar,
final List<Bar> additionalBars,
final SortedSet<Bar> otherBars)
{
if (fooId == null)
{
throw new IllegalArgumentException("fooId must not be null");
}
if (synonyms == null)
{
throw new IllegalArgumentException("synonyms must not be null");
}
if (positions == null)
{
throw new IllegalArgumentException("positions must not be null");
}
if (positions.size() < 1)
{
throw new IllegalArgumentException("positions must contain at least one position");
}
if (requiredBar == null)
{
throw new IllegalArgumentException("requiredBar must not be null");
}
if (additionalBars == null)
{
throw new IllegalArgumentException("additionalBars must not be null");
}
if (otherBars == null)
{
throw new IllegalArgumentException("otherBars must not be null");
}
if (otherBars.size() < 1)
{
throw new IllegalArgumentException("otherBars must contain at least one other bar");
}
setFooId(fooId);
setName(name);
this.synonyms = new HashSet<String>(synonyms);
this.positions = new ArrayList<Integer>(positions);
setOptionalBar(optionalBar);
setRequiredBar(requiredBar);
this.additionalBars = new ArrayList<Bar>(additionalBars);
this.otherBars = new TreeSet<Bar>(otherBars);
}
/**
* Return the foo id for this simple foo.
* The foo id will not be null.
*
* @return the foo id for this simple foo
*/
public final Long getFooId()
{
return fooId;
}
/**
* Set the foo id for this simple foo to <code>fooId</code>.
*
* @param fooId foo id for this simple foo, must not be null
*/
public final void setFooId(final Long fooId)
{
if (fooId == null)
{
throw new IllegalArgumentException("fooId must not be null");
}
this.fooId = fooId;
}
/**
* Return the name for this simple foo.
* The name may be null.
*
* @return the name for this simple foo
*/
public final String getName()
{
return name;
}
/**
* Set the name for this simple foo to <code>name</code>.
*
* @param name name for this simple foo
*/
public final void setName(final String name)
{
this.name = name;
}
/**
* Return an unmodifiable set of synonyms
* for this simple foo. The returned set may be
* empty but will not be null.
*
* @return an unmodifiable set of synonyms
* for this simple foo
*/
public final Set<String> getSynonyms()
{
return Collections.unmodifiableSet(synonyms);
}
/**
* Add the specified synonym to the set of
* synonyms for this simple foo. An exception
* may be thrown if the underlying set prevents
* <code>synonym</code> from being added.
*
* @param synonym synonym to add
*/
public final void addSynonym(final String synonym)
{
synonyms.add(synonym);
}
/**
* Add all of the synonyms in the specified collection of synonyms
* to the set of synonyms for this simple foo.
* An exception may be thrown if the underlying
* set prevents any of the synonyms in
* <code>synonyms</code> from being added.
*
* @param synonyms collection of synonyms to add
*/
public final void addAllSynonyms(final Collection<? extends String> synonyms)
{
this.synonyms.addAll(synonyms);
}
/**
* Remove the specified synonym from the set of
* synonyms for this simple foo. An exception
* may be thrown if the underlying set prevents
* <code>synonym</code> from being removed.
*
* @param synonym synonym to remove
*/
public final void removeSynonym(final String synonym)
{
synonyms.remove(synonym);
}
/**
* Remove all of the synonyms in the set of
* synonyms for this simple foo that are also contained in the
* specified collection of synonyms. An exception
* may be thrown if the underlying set prevents any
* of the synonyms in <code>synonyms</code> from being removed.
*
* @param synonyms collection of synonyms to remove
*/
public final void removeAllSynonyms(final Collection<? extends String> synonyms)
{
this.synonyms.removeAll(synonyms);
}
/**
* Retain only the synonyms in the set of
* synonyms for this simple foo that are contained in the specified
* collection of synonyms. An exception may be thrown
* if the underlying set prevents any of the synonyms
* not in <code>synonyms</code> from being removed.
*
* @param synonyms collection of synonyms to retain
*/
public final void retainAllSynonyms(final Collection<? extends String> synonyms)
{
this.synonyms.retainAll(synonyms);
}
/**
* Remove all of the synonyms in the set of
* synonyms for this simple foo. An exception may
* be thrown if the underlying set prevents any of the
* synonyms from being removed.
*/
public final void clearSynonyms()
{
synonyms.clear();
}
/**
* Return an unmodifiable list of positions
* for this simple foo. The returned list will
* not be null and will contain at least one position.
*
* @return an unmodifiable list of positions
* for this simple foo
*/
public final List<Integer> getPositions()
{
return Collections.unmodifiableList(positions);
}
/**
* Add the specified position to the list of
* positions for this simple foo. An exception
* may be thrown if the underlying list prevents
* <code>position</code> from being added.
*
* @param position position to add
*/
public final void addPosition(final Integer position)
{
positions.add(position);
}
/**
* Add all of the positions in the specified collection of positions
* to the list of positions for this simple foo.
* An exception may be thrown if the underlying
* list prevents any of the positions in
* <code>positions</code> from being added.
*
* @param positions collection of positions to add
*/
public final void addAllPositions(final Collection<? extends Integer> positions)
{
this.positions.addAll(positions);
}
/**
* Remove the specified position from the list of
* positions for this simple foo. An exception
* may be thrown if the underlying list prevents
* <code>position</code> from being removed.
*
* @param position position to remove
*/
public final void removePosition(final Integer position)
{
positions.remove(position);
}
/**
* Remove all of the positions in the list of
* positions for this simple foo that are also contained in the
* specified collection of positions. An exception
* may be thrown if the underlying list prevents any
* of the positions in <code>positions</code> from being removed.
*
* @param positions collection of positions to remove
*/
public final void removeAllPositions(final Collection<? extends Integer> positions)
{
this.positions.removeAll(positions);
}
/**
* Retain only the positions in the list of
* positions for this simple foo that are contained in the specified
* collection of positions. An exception may be thrown
* if the underlying list prevents any of the positions
* not in <code>positions</code> from being removed.
*
* @param positions collection of positions to retain
*/
public final void retainAllPositions(final Collection<? extends Integer> positions)
{
this.positions.retainAll(positions);
}
/**
* Remove all of the positions in the list of
* positions for this simple foo. An exception may
* be thrown if the underlying list prevents any of the
* positions from being removed.
*/
public final void clearPositions()
{
positions.clear();
}
/**
* Return the optional bar for this simple foo.
* The optional bar may be null.
*
* @return the optional bar for this simple foo
*/
public final Bar getOptionalBar()
{
return optionalBar;
}
/**
* Set the optional bar for this simple foo to <code>optionalBar</code>.
*
* @param optionalBar optional bar for this simple foo
*/
public final void setOptionalBar(final Bar optionalBar)
{
this.optionalBar = optionalBar;
}
/**
* Return the required bar for this simple foo.
* The required bar will not be null.
*
* @return the required bar for this simple foo
*/
public final Bar getRequiredBar()
{
return requiredBar;
}
/**
* Set the required bar for this simple foo to <code>requiredBar</code>.
*
* @param requiredBar required bar for this simple foo, must not be null
*/
public final void setRequiredBar(final Bar requiredBar)
{
if (requiredBar == null)
{
throw new IllegalArgumentException("requiredBar must not be null");
}
this.requiredBar = requiredBar;
}
/**
* Return an unmodifiable list of additional bars
* for this simple foo. The returned list may be
* empty but will not be null.
*
* @return an unmodifiable list of additional bars
* for this simple foo
*/
public final List<Bar> getAdditionalBars()
{
return Collections.unmodifiableList(additionalBars);
}
/**
* Add the specified additional bar to the list of
* additional bars for this simple foo. An exception
* may be thrown if the underlying list prevents
* <code>additionalBar</code> from being added.
*
* @param additionalBar additional bar to add
*/
public final void addAdditionalBar(final Bar additionalBar)
{
additionalBars.add(additionalBar);
}
/**
* Add all of the additional bars in the specified collection of additional bars
* to the list of additional bars for this simple foo.
* An exception may be thrown if the underlying
* list prevents any of the additional bars in
* <code>additionalBars</code> from being added.
*
* @param additionalBars collection of additional bars to add
*/
public final void addAllAdditionalBars(final Collection<? extends Bar> additionalBars)
{
this.additionalBars.addAll(additionalBars);
}
/**
* Remove the specified additional bar from the list of
* additional bars for this simple foo. An exception
* may be thrown if the underlying list prevents
* <code>additionalBar</code> from being removed.
*
* @param additionalBar additional bar to remove
*/
public final void removeAdditionalBar(final Bar additionalBar)
{
additionalBars.remove(additionalBar);
}
/**
* Remove all of the additional bars in the list of
* additional bars for this simple foo that are also contained in the
* specified collection of additional bars. An exception
* may be thrown if the underlying list prevents any
* of the additional bars in <code>additionalBars</code> from being removed.
*
* @param additionalBars collection of additional bars to remove
*/
public final void removeAllAdditionalBars(final Collection<? extends Bar> additionalBars)
{
this.additionalBars.removeAll(additionalBars);
}
/**
* Retain only the additional bars in the list of
* additional bars for this simple foo that are contained in the specified
* collection of additional bars. An exception may be thrown
* if the underlying list prevents any of the additional bars
* not in <code>additionalBars</code> from being removed.
*
* @param additionalBars collection of additional bars to retain
*/
public final void retainAllAdditionalBars(final Collection<? extends Bar> additionalBars)
{
this.additionalBars.retainAll(additionalBars);
}
/**
* Remove all of the additional bars in the list of
* additional bars for this simple foo. An exception may
* be thrown if the underlying list prevents any of the
* additional bars from being removed.
*/
public final void clearAdditionalBars()
{
additionalBars.clear();
}
/**
* Return an unmodifiable sorted set of other bars
* for this simple foo. The returned sorted set will
* not be null and will contain at least one other bar.
*
* @return an unmodifiable sorted set of other bars
* for this simple foo
*/
public final SortedSet<Bar> getOtherBars()
{
return Collections.unmodifiableSortedSet(otherBars);
}
/**
* Add the specified other bar to the sorted set of
* other bars for this simple foo. An exception
* may be thrown if the underlying sorted set prevents
* <code>otherBar</code> from being added.
*
* @param otherBar other bar to add
*/
public final void addOtherBar(final Bar otherBar)
{
otherBars.add(otherBar);
}
/**
* Add all of the other bars in the specified collection of other bars
* to the sorted set of other bars for this simple foo.
* An exception may be thrown if the underlying
* sorted set prevents any of the other bars in
* <code>otherBars</code> from being added.
*
* @param otherBars collection of other bars to add
*/
public final void addAllOtherBars(final Collection<? extends Bar> otherBars)
{
this.otherBars.addAll(otherBars);
}
/**
* Remove the specified other bar from the sorted set of
* other bars for this simple foo. An exception
* may be thrown if the underlying sorted set prevents
* <code>otherBar</code> from being removed.
*
* @param otherBar other bar to remove
*/
public final void removeOtherBar(final Bar otherBar)
{
otherBars.remove(otherBar);
}
/**
* Remove all of the other bars in the sorted set of
* other bars for this simple foo that are also contained in the
* specified collection of other bars. An exception
* may be thrown if the underlying sorted set prevents any
* of the other bars in <code>otherBars</code> from being removed.
*
* @param otherBars collection of other bars to remove
*/
public final void removeAllOtherBars(final Collection<? extends Bar> otherBars)
{
this.otherBars.removeAll(otherBars);
}
/**
* Retain only the other bars in the sorted set of
* other bars for this simple foo that are contained in the specified
* collection of other bars. An exception may be thrown
* if the underlying sorted set prevents any of the other bars
* not in <code>otherBars</code> from being removed.
*
* @param otherBars collection of other bars to retain
*/
public final void retainAllOtherBars(final Collection<? extends Bar> otherBars)
{
this.otherBars.retainAll(otherBars);
}
/**
* Remove all of the other bars in the sorted set of
* other bars for this simple foo. An exception may
* be thrown if the underlying sorted set prevents any of the
* other bars from being removed.
*/
public final void clearOtherBars()
{
otherBars.clear();
}
/** @see Object */
public final boolean equals(final Object o)
{
if (o == this)
{
return true;
}
if (!(o instanceof SimpleFoo))
{
return false;
}
SimpleFoo simpleFoo = (SimpleFoo) o;
return (true
&& (fooId.equals(simpleFoo.getFooId()))
&& ((name == null) ? (simpleFoo.getName() == null) : name.equals(simpleFoo.getName()))
&& (synonyms.equals(simpleFoo.getSynonyms()))
&& (positions.equals(simpleFoo.getPositions()))
&& ((optionalBar == null) ? (simpleFoo.getOptionalBar() == null) : optionalBar.equals(simpleFoo.getOptionalBar()))
&& (requiredBar.equals(simpleFoo.getRequiredBar()))
&& (additionalBars.equals(simpleFoo.getAdditionalBars()))
&& (otherBars.equals(simpleFoo.getOtherBars()))
);
}
/** @see Object */
public final int hashCode()
{
int result = 17;
result = 37 * result + ((fooId == null) ? 0 : fooId.hashCode());
result = 37 * result + ((name == null) ? 0 : name.hashCode());
result = 37 * result + synonyms.hashCode();
result = 37 * result + positions.hashCode();
result = 37 * result + ((optionalBar == null) ? 0 : optionalBar.hashCode());
result = 37 * result + ((requiredBar == null) ? 0 : requiredBar.hashCode());
result = 37 * result + additionalBars.hashCode();
result = 37 * result + otherBars.hashCode();
return result;
}
}
---
Whew, now that's a lot of typing saved.
michael
On Mon, 15 Aug 2005 mark.schreiber at novartis.com wrote:
> It's probably premature to announce this but Richard Holland and I have
> been working on a new object model that will pesist very easily to BioSQL.
> It extends the core interfaces and miraculously doesn't break anything so
> you can still use the core stuff or you can use the new models if you want
> to.
>
> For example we have the RichSequence interface which closely follows
> biosql but also extends Sequence, so anywhere you can use Sequence you can
> happily use a RichSequence (or just a plain old Sequence). The really cool
> stuff is the work Richard has done with Hibernate. The whole of BioSQL can
> now be happily transported back and forth to biojava via hibernate. It's
> amazingly painless and seems to avoid many of the problems of our old SQL
> system. The model is also decoupled from hibernate completely so you can
> use the objects for your normal biojava stuff without ever having a
> database for persistence.
>
> We also have a NCBITaxon class to handle all the issues Andreas brought
> up.
>
> The whole thing is available from CVS under the org.biojavax.bio package.
> We chose the name biojavax to be analogous to the relationship between
> java and javax. The javax packages are extensions to the core java. They
> improve it, they sometimes deprecate it, they use it, but they don't
> replace it. The same is true for biojavax. It is not a replacement. It is
> an extension that gives better functionality but still gets a lot of
> milage out of biojava. Importantly, they are not seperate packages. There
> is also a genetic algorithm framework under org.biojavax.ga but that's an
> entirely different story : )
>
> The biojavax packages should be considered highly unstable at the moment
> as we are still working out the kinks. More later.
>
> - Mark
>
> Mark Schreiber
> Principal Scientist (Bioinformatics)
>
> Novartis Institute for Tropical Diseases (NITD)
> 10 Biopolis Road
> #05-01 Chromos
> Singapore 138670
> www.nitd.novartis.com
>
> phone +65 6722 2973
> fax +65 6722 2910
>
>
>
>
>
> Len Trigg <len at reeltwo.com>
> Sent by: biojava-dev-bounces at portal.open-bio.org
> 08/15/2005 06:22 AM
>
>
> To: Andreas Dräger <andreas.draeger at clever-telefonieren.de>
> cc: biojava-dev at biojava.org, (bcc: Mark Schreiber/GP/Novartis)
> Subject: Re: [Biojava-dev] Suggestions for the BioJava project
>
>
>
> Andreas Dräger wrote:
> > I am and currently working with BioSQL and BioJava. Trying to insert
> > the NCBI taxon hierachy and also different kinds of biosequences into
> > the database I got to know that there are still some open problems in
> > BioJava. Since I wrote some classes anyway, I would like to contribute
> > them to the community.
>
> Good stuff. The work that I did with the TaxonSQL classes was based
> on the fairly simple requirements of the project I was working on,
> which is why you found the current implementation a bit limited. (I
> don't have projects involving BioJava at the moment, so haven't been
> doing much other than following the mailing list.)
>
>
> > I modified the functions to put and retrieve taxa into the database so
> > that they consider that the names Map could sometimes point to a Set of
> > names instead of normal name Strings.
> > In addition I considered the other information that can be inserted in
> > the database like genetic code and so on.
>
> Excellent improvements.
>
>
> > However, there are some methods in TaxonSQL.java that are defined to be
> > private. If they were protected, an extension of this class could call
> them.
> > But because they're private, I had to copy and paste them.
>
> That class isn't really designed for extension, since it's plugged
> directly into calls from BioSQLSequenceAnnotation and BioSQLSequenceDB
> (you presumably had to change these to point to your MySQLTaxon) and
> there's no need for multiple implementations. I'd say that your
> changes should instead be folded directly as improvements to TaxonSQL
> itself so that everyone gets the improvements out of the box.
>
>
> Cheers,
> Len.
>
> _______________________________________________
> biojava-dev mailing list
> biojava-dev at biojava.org
> http://biojava.org/mailman/listinfo/biojava-dev
>
>
>
>
> _______________________________________________
> biojava-dev mailing list
> biojava-dev at biojava.org
> http://biojava.org/mailman/listinfo/biojava-dev
>
More information about the biojava-dev
mailing list