| Line | Hits | Source |
|---|---|---|
| 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 | import edu.uci.ics.jung.graph.Vertex; | |
| 13 | import edu.uci.ics.jung.utils.MutableDouble; | |
| 14 | import edu.uci.ics.jung.utils.UserData; | |
| 15 | ||
| 16 | import java.util.Set; | |
| 17 | import java.util.Iterator; | |
| 18 | ||
| 19 | /** | |
| 20 | * This class provides basic infrastructure for relative authority algorithms that compute the importance of nodes | |
| 21 | * relative to one or more root nodes. The services provided are: | |
| 22 | * <ul> | |
| 23 | * <li>The set of root nodes (priors) is stored and maintained</li> | |
| 24 | * <li>Getters and setters for the prior rank score are provided</li> | |
| 25 | * </ul> | |
| 26 | * | |
| 27 | * @author Scott White | |
| 28 | */ | |
| 29 | 8 | public abstract class RelativeAuthorityRanker extends AbstractRanker { |
| 30 | private Set mPriors; | |
| 31 | /** | |
| 32 | * The default key used for the user datum key corresponding to prior rank scores. | |
| 33 | */ | |
| 34 | public static final String PRIOR_KEY = "jung.algorithms.importance.RelativeAuthorityRanker.PriorRankScore"; | |
| 35 | ||
| 36 | /** | |
| 37 | * Cleans up all of the prior rank scores on finalize. | |
| 38 | */ | |
| 39 | protected void finalizeIterations() { | |
| 40 | 8 | super.finalizeIterations(); |
| 41 | 8 | for (Iterator vIt = getVertices().iterator();vIt.hasNext();) { |
| 42 | 37 | Vertex currentVertex = (Vertex) vIt.next(); |
| 43 | 37 | currentVertex.removeUserDatum(PRIOR_KEY); |
| 44 | } | |
| 45 | ||
| 46 | 8 | } |
| 47 | ||
| 48 | /** | |
| 49 | * Returns the user datum key for the prior rank score. | |
| 50 | * @return the user datum key for the prior rank score | |
| 51 | */ | |
| 52 | protected String getPriorRankScoreKey() { | |
| 53 | 0 | return PRIOR_KEY; |
| 54 | } | |
| 55 | ||
| 56 | /** | |
| 57 | * Retrieves the value of the prior rank score. | |
| 58 | * @param v the root node (prior) | |
| 59 | * @return the prior rank score | |
| 60 | */ | |
| 61 | protected double getPriorRankScore(Vertex v) { | |
| 62 | 2588 | return ((MutableDouble) v.getUserDatum(PRIOR_KEY)).doubleValue(); |
| 63 | ||
| 64 | } | |
| 65 | ||
| 66 | /** | |
| 67 | * Allows the user to specify a value to set for the prior rank score | |
| 68 | * @param v the root node (prior) | |
| 69 | * @param value the score to set to | |
| 70 | */ | |
| 71 | public void setPriorRankScore(Vertex v, double value) { | |
| 72 | 46 | MutableDouble doubleVal = (MutableDouble) v.getUserDatum(PRIOR_KEY); |
| 73 | 46 | if (doubleVal == null) { |
| 74 | 30 | doubleVal = new MutableDouble(value); |
| 75 | } else { | |
| 76 | 16 | doubleVal.setDoubleValue(value); |
| 77 | } | |
| 78 | 46 | v.setUserDatum(PRIOR_KEY,doubleVal,UserData.SHARED); |
| 79 | 46 | } |
| 80 | ||
| 81 | /** | |
| 82 | * Retrieves the set of priors. | |
| 83 | * @return the set of root nodes (priors) | |
| 84 | */ | |
| 85 | 19 | protected Set getPriors() { return mPriors; } |
| 86 | ||
| 87 | /** | |
| 88 | * Specifies which vertices are root nodes (priors). | |
| 89 | * @param priors the root nodes | |
| 90 | */ | |
| 91 | 6 | protected void setPriors(Set priors) { mPriors = priors; } |
| 92 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |