/* $Id: TspGroupItem.java,v 1.3 2006/06/04 08:33:45 erk Exp $
 * -----------------------------------------------------------------------
 * 
 * TSP Library - core components for a generic Transport Sampling Protocol.
 * 
 * Copyright (c) 2002 Yves DUFRENNE, Stephane GALLES, Eric NOULARD and Robert PAGNOT 
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library 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
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 * -----------------------------------------------------------------------
 * 
 * Project    : TSP
 * SubProject : jTSP
 * Maintainer : tsp@astrium-space.com
 * Component  : Consumer
 * 
 * -----------------------------------------------------------------------
 * 
 * Purpose   : 
 * 
 * -----------------------------------------------------------------------
 */

package tsp.core.common;

import java.lang.Comparable;

import tsp.core.rpc.TSP_datatype_t;
import tsp.core.rpc.TSP_sample_symbol_info_t;


/**
 * The TSP group item.
 */
public class TspGroupItem implements Comparable {

    public TspGroupItem(int provider_global_index,
			int encoded_size,
			int group_rank) {
	this.provider_global_index = provider_global_index;
	this.encoded_size          = encoded_size;
	this.group_rank            = group_rank;
    }
    
    public TspGroupItem(TSP_sample_symbol_info_t s){
	this.provider_global_index = s.provider_global_index;
	this.group_rank            = s.provider_group_rank;
	this.type                  = s.type;
	this.nelem                 = s.nelem;
    }

    /*
     * This comparator induce a sort by
     * lowest group rank first
     */
    public int compareTo(Object o) {
    	return this.group_rank - ((TspGroupItem)o).group_rank;
	}
    
    /* Get the item encoded size for multi-type handling
     * 
     */
    public int getEncodedSize(){
    	return encoded_size;
    }
    
    /* Get the item type returned for multi-type handling
     * 
     */
    public int getReturnedType(){
    	return type;
    }
    
    /* Get the number of element og the item
     * 
     */
    public int getNbElem(){
    	return nelem;
    }
    

    /**
     * The provider global index.
     * (see TSP specs.).
     */
    public  int provider_global_index;
    /**
     * The size (in byte) to be read on the stream
     */
    public  int encoded_size;
    /**
     * The type to be read on the stream
     */
    private  int type;
    /**
     * The number of elements to be read on the stream
     */
    private  int nelem;
    /**
     * the rank in the group 
     */
    public  int group_rank;


}
