Initial opendaylight infrastructure commit!!
[controller.git] / third-party / net.sf.jung2 / src / main / java / edu / uci / ics / jung / algorithms / importance / Ranking.java
1 /*
2 * Copyright (c) 2003, the JUNG Project and the Regents of the University 
3 * of California
4 * All rights reserved.
5 *
6 * This software is open-source under the BSD license; see either
7 * "license.txt" or
8 * http://jung.sourceforge.net/license.txt for a description.
9 */
10 package edu.uci.ics.jung.algorithms.importance;
11
12
13 /**
14  * Abstract data container for ranking objects. Stores common data relevant to both node and edge rankings, namely,
15  * the original position of the instance in the list and the actual ranking score.
16  * @author Scott White
17  */
18 public class Ranking<V> implements Comparable {
19     /**
20      * The original (0-indexed) position of the instance being ranked
21      */
22     public int originalPos;
23     /**
24      * The actual rank score (normally between 0 and 1)
25      */
26     public double rankScore;
27     
28     /**
29      * what is being ranked
30      */
31     private V ranked;
32
33     /**
34      * Constructor which allows values to be set on construction
35      * @param originalPos The original (0-indexed) position of the instance being ranked
36      * @param rankScore The actual rank score (normally between 0 and 1)
37      */
38     public Ranking(int originalPos, double rankScore, V ranked) {
39         this.originalPos = originalPos;
40         this.rankScore = rankScore;
41         this.ranked = ranked;
42     }
43
44     /**
45      * Compares two ranking based on the rank score.
46      * @param o The other ranking
47      * @return -1 if the other ranking is higher, 0 if they are equal, and 1 if this ranking is higher
48      */
49     public int compareTo(Object o) {
50
51         Ranking otherRanking = (Ranking) o;
52         return Double.compare(otherRanking.rankScore,rankScore);
53     }
54
55     /**
56      * Returns the rank score as a string.
57      * @return the stringified rank score
58      */
59     @Override
60     public String toString() {
61         return String.valueOf(rankScore);
62     }
63
64         /**
65          * @return the ranked
66          */
67         public V getRanked() {
68                 return ranked;
69         }
70
71         /**
72          * @param ranked the ranked to set
73          */
74         public void setRanked(V ranked) {
75                 this.ranked = ranked;
76         }
77 }