/*
 *    AudioDBDocInfo.java
 *    Copyright (C) 2011 New Zealand Digital Library, http://www.nzdl.org
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package org.greenstone.gsdl3.util;

import java.util.Vector;
import java.lang.Comparable;

public class AudioDBDocInfo implements Comparable<AudioDBDocInfo>
{
    public String oid_;
    public Vector<Double> rankVector_;
    public Vector<Integer> offsetVector_;

    public AudioDBDocInfo(String doc_oid, double rank, int offset)
    {
	oid_ = doc_oid;
	
	rankVector_ = new Vector<Double>();
	rankVector_.add (rank);

	offsetVector_ = new Vector<Integer>();
	offsetVector_.add(offset);
    }


    public AudioDBDocInfo(String doc_oid, Vector<Double> rankVector, Vector<Integer> offsetVector)
    {
	oid_ = doc_oid;
	rankVector_ = rankVector;
	offsetVector_ = offsetVector;
    }

    public String getDocID()
    {
	return oid_;
    }

    public double getTopRank()
    {
	return rankVector_.get(0);
    }


    public String getOffsetList() 
    {
	StringBuffer all_offsets = new StringBuffer();
	boolean first = true;

	for (int i=0; i<offsetVector_.size(); i++) {
	    int offset = offsetVector_.get(i);
	    String offsetStr = Integer.toString(offset);

	    if (first) {
		first = false;
	    }
	    else {
		all_offsets.append(",");
	    }

	    all_offsets.append(offsetStr);
	}

	return all_offsets.toString();
    }

    public int compareTo(AudioDBDocInfo di)
    {
	// based on first entry in rank Vector

	// embodies a descending sort order
	double lrank = rankVector_.get(0);
	double rrank = di.rankVector_.get(0);

	if (lrank<rrank) {
	    return 1;
	}
	else if (lrank>rrank) {
	    return -1;
	}
	else {
	    return 0;
	}
    }
}
