[Biojava-l] Location interface

Matthew Pocock mrp@sanger.ac.uk
Mon, 30 Apr 2001 14:15:08 +0100


Hi.

Greg Cox, Thomas Down and I discussed the Location interface at the 
BioJava boot-camp. The tutorials also turned up a number of 
Location-realted bugglets. The upshot is that the code needs to be 
re-vamped. I have volunteered to do the work, and wherever possible you 
should be unaware of the changes. Here is a summery:

* CircularLocation becomes decorator around some underlying instance

* BetweenLocation added as a decorateor arround some underlying instance 
- used to represent the dreaded splice-site locations


Location interface gains:
   // returns a new instance of Location with the actual
   // data identical to loc, but with the same set of decorators
   Location newInstance(Location loc);

   // Is there an instance of this decorator class somewhere
   // in the decorator chain?
   boolean hasDecorator(Class decoratorClass);

Location interface depricates (and looses on 1.2) all binary operators
   Overlaps
   Union
   Intersection
   Equals
   Contains

LocationTools added with static methods for these.

The rational behind moving the binary operators is that Java has 
extremely poor support for double-binding, and the current code-base is 
ickey.

We realy want to attach operators to tuples, not classes. Imagine if we 
could define and use methods on tuples and let the method binding work 
out as for the single-binding (inheritance) case. The tuples could look 
like arrays with individualy typed indecies. If tuples can implement 
interfaces then one interface could be the 'operator overloadable' 
interface, at which point we get safe overloading of binary operators 
like + and -.

boolean ol = [locA, locB].overlaps();

abstract tuple Location, Locaion {
   abstract boolean overlaps();
   abstract boolean equals();

   ...
}

and provide implementations like this:

tuple RangeLocation, RangeLocation {
   boolean overlaps() {
     return !(this[0].getMin() > this[1].getMax() ||
              this[0].getMax() < this[1].getMin());
   }

   ...
}

tuple RangeLocation, PointLocation {
   boolean overlaps() {
     return this[0].getMin() >= this[1].getMin() &&
            this[0].getMax() <= this[1].getMin();
   }

   ...
}