babase.ranker.ranking
Class Ranking

java.lang.Object
  extended by babase.ranker.ranking.Ranking

public class Ranking
extends java.lang.Object

A permutation of integers from 0 to n-1 that represents a linear ranking of n individuals. Each individual is identified by an integer from 0 to n-1.

Author:
junyang

Field Summary
protected  java.util.ArrayList<RankingChangedListener> _changedListeners
          A list of RankingChangedListeners that will be notified immediately after this Ranking object changes.
protected  int[] _ranks
          A permutation of integers from 0 to n-1 that represents a linear ranking of n individuals.
 
Constructor Summary
Ranking(int n)
          Construct an initial ranking of n individuals in their default order 0 to n-1.
Ranking(int[] ranks)
          Construct an initial ranking of n individuals in the order specified by ranks.
 
Method Summary
 void addChangedListener(RankingChangedListener listener)
           
 int[] get()
           
 int get(int i)
           
 void permute(int[] newRanks, java.lang.Object permuter)
          Permute the ranking.
 void removeChangedListener(RankingChangedListener listener)
           
 int size()
           
 void slide(int from, int to, java.lang.Object slider)
          Slide an individual to a new rank.
 void swap(int i, int j, java.lang.Object swapper)
          Swap the ranks of individuals currently ranked at i and j (both 0-based ranks).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_ranks

protected int[] _ranks
A permutation of integers from 0 to n-1 that represents a linear ranking of n individuals. Specifically, the individual identified by _ranks[i] is ranked at i.


_changedListeners

protected java.util.ArrayList<RankingChangedListener> _changedListeners
A list of RankingChangedListeners that will be notified immediately after this Ranking object changes.

Constructor Detail

Ranking

public Ranking(int n)
Construct an initial ranking of n individuals in their default order 0 to n-1.

Parameters:
n -

Ranking

public Ranking(int[] ranks)
Construct an initial ranking of n individuals in the order specified by ranks.

Parameters:
ranks - A permutation of integers from 0 to n-1 that represents a linear ranking of n individuals. Specifically, the individual identified by _ranks[i] is ranked at i.
Method Detail

addChangedListener

public void addChangedListener(RankingChangedListener listener)
Parameters:
listener - A RankingChangedListener object to be added. It will be notified immediately after each change to this Ranking.

removeChangedListener

public void removeChangedListener(RankingChangedListener listener)
Parameters:
listener - A RankingChangedListener object to be removed.

size

public int size()
Returns:
The number of individuals in the ranking.

get

public int get(int i)
Parameters:
i - A 0-based rank.
Returns:
The i-th ranked individual, identified by an integer between 0 and size()-1.

get

public int[] get()
Returns:
The entire ranking as an array of integers. The i-th array element is an an integer between 0 and size()-1 that identifies the i-th ranked individual.

swap

public void swap(int i,
                 int j,
                 java.lang.Object swapper)
Swap the ranks of individuals currently ranked at i and j (both 0-based ranks). This method generates a RankingChangeEvent.Swap event.

Parameters:
i -
j -
swapper - The object calling this method.

slide

public void slide(int from,
                  int to,
                  java.lang.Object slider)
Slide an individual to a new rank. The result of this operation is that this individual attains the new rank, while the individuals between the old and new ranks are shifted by one towards the old rank of the individual. This method generates a RankingChangeEvent.Slide event.

Parameters:
from - The current rank (0-based) of the individual.
to - The new rank (0-based) to slide to.
slider - The object calling this method.

permute

public void permute(int[] newRanks,
                    java.lang.Object permuter)
Permute the ranking. This method generates a RankingChangeEvent.Permute event.

Parameters:
newRanks - The new ranking, a permutation of integers between 0 and size()-1.
permuter - The object calling this method.