001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022package org.biojava.bio.program.indexdb;
023
024import org.biojava.utils.io.RAF;
025
026/**
027 * <code>Record</code> represents a record within an indexed flat file
028 * databank as defined by the OBDA standard.
029 *
030 * @author Matthew Pocock
031 * @author Keith James
032 */
033public interface Record {
034
035    /**
036     * <code>getID</code> returns the primary identifier of the
037     * record.
038     *
039     * @return a <code>String</code> ID.
040     */
041    public String getID();
042
043    /**
044     * <code>getFile</code> returns the random access file in which
045     * the record belongs.
046     *
047     * @return a <code>RAF</code>.
048     */
049    public RAF getFile();
050
051    /**
052     * <code>getOffset</code> returns the byte offset in the file at
053     * which the record begins.
054     *
055     * @return a <code>long</code> offset.
056     */
057    public long getOffset();
058
059    /**
060     * <code>getLength</code> returns the length of the record in
061     * bytes.
062     *
063     * @return an <code>int</code>.
064     */
065    public int getLength();
066  
067    /**
068     * <code>Impl</code> is the default implementation of Record.
069     *
070     * @author Matthew Pocock
071     */
072    public static class Impl
073        implements Record {
074        private final String id;
075        private final RAF file;
076        private final long offset;
077        private final int length;
078    
079        /**
080         * Creates a new <code>Impl</code> record.
081         *
082         * @param id a <code>String</code> primary ID.
083         * @param file a <code>RAF</code> file.
084         * @param offset a <code>long</code> byte offset.
085         * @param length an <code>int</code> byte record length.
086         */
087        public Impl(String id, RAF file, long offset, int length) {
088            if (id == null) {
089                throw new NullPointerException("Can't have null ID");
090            }
091            this.id = id;
092            this.file = file;
093            this.offset = offset;
094            this.length = length;
095        }
096
097        public String  getID()     { return id; }
098        public RAF     getFile()   { return file; }
099        public long    getOffset() { return offset; }
100        public int     getLength() { return length; }
101    }
102}