/*
 *    WekaDBDocInfo.java -- currently clone of 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;

// ****
// If turns out to be the same as AudioDBDocInfo then turn into
// superclass

import java.util.Vector;
import java.lang.Comparable;

public class WekaDBDocInfo implements Comparable<WekaDBDocInfo>
{
    public String oid_;
    public Vector<Double> arousalVector_;
    public Vector<Double> valenceVector_;
    public Vector<Double> rankVector_;
    public Vector<Integer> offsetVector_;

    public WekaDBDocInfo(String doc_oid, double arousal, double valence, double rank, int offset)
    {
	oid_ = doc_oid;

	arousalVector_ = new Vector<Double>();
	arousalVector_.add (arousal);
	valenceVector_ = new Vector<Double>();
	valenceVector_.add (valence);

	rankVector_ = new Vector<Double>();
	rankVector_.add (rank);

	offsetVector_ = new Vector<Integer>();
	offsetVector_.add(offset);
    }


    public WekaDBDocInfo(String doc_oid, Vector<Double> arousalVector, Vector<Double> valenceVector,
			 Vector<Double> rankVector, Vector<Integer> offsetVector)
    {
	oid_ = doc_oid;

	arousalVector_ = arousalVector;
	valenceVector_ = valenceVector;
	
	rankVector_   = rankVector;
	offsetVector_ = offsetVector;
    }

    public String getDocID()
    {
	return oid_;
    }

    public double getTopArousal()
    {
	return arousalVector_.get(0);
    }

    public double getTopValence()
    {
	return valenceVector_.get(0);
    }

    public double getTopRank()
    {
	return rankVector_.get(0);
    }

    public void incTopRank(double inc_rank_val)
    {
	double top_rank = rankVector_.get(0);

	double new_top_rank = top_rank + inc_rank_val;
	rankVector_.set(0,new_top_rank);
    }


    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(WekaDBDocInfo 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;
	}
    }
}
