View Javadoc
1   /*
2   * Copyright (c) 2003, The JUNG Authors 
3   *
4   * All rights reserved.
5   *
6   * This software is open-source under the BSD license; see either
7   * "license.txt" or
8   * https://github.com/jrtom/jung/blob/master/LICENSE 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  @SuppressWarnings("rawtypes")
19  public class Ranking<V> implements Comparable {
20      /**
21       * The original (0-indexed) position of the instance being ranked
22       */
23      public int originalPos;
24      /**
25       * The actual rank score (normally between 0 and 1)
26       */
27      public double rankScore;
28      
29      /**
30       * what is being ranked
31       */
32      private V ranked;
33  
34      /**
35       * Constructor which allows values to be set on construction
36       * @param originalPos The original (0-indexed) position of the instance being ranked
37       * @param rankScore The actual rank score (normally between 0 and 1)
38       * @param ranked the vertex being ranked
39       */
40      public Ranking(int originalPos, double rankScore, V ranked) {
41          this.originalPos = originalPos;
42          this.rankScore = rankScore;
43          this.ranked = ranked;
44      }
45  
46      /**
47       * Compares two ranking based on the rank score.
48       * @param other The other ranking
49       * @return -1 if the other ranking is higher, 0 if they are equal, and 1 if this ranking is higher
50       */
51      public int compareTo(Object other) {
52      	@SuppressWarnings("unchecked")
53  		Ranking<V> otherRanking = (Ranking<V>) other;
54          return Double.compare(otherRanking.rankScore,rankScore);
55      }
56  
57      /**
58       * Returns the rank score as a string.
59       * @return the stringified rank score
60       */
61      @Override
62      public String toString() {
63          return String.valueOf(rankScore);
64      }
65  
66  	/**
67  	 * @return the ranked element
68  	 */
69  	public V getRanked() {
70  		return ranked;
71  	}
72  
73  	/**
74  	 * @param ranked the ranked to set
75  	 */
76  	public void setRanked(V ranked) {
77  		this.ranked = ranked;
78  	}
79  }