Fix checkstyle warnings in netconf-cli
[controller.git] / third-party / net.sf.jung2 / src / main / java / edu / uci / ics / jung / algorithms / scoring / util / UniformDegreeWeight.java
1 /**
2  * Copyright (c) 2008, 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  * Created on Jul 14, 2008
10  * 
11  */
12 package edu.uci.ics.jung.algorithms.scoring.util;
13
14 import org.apache.commons.collections15.Transformer;
15
16 import edu.uci.ics.jung.graph.Hypergraph;
17 import edu.uci.ics.jung.graph.util.EdgeType;
18
19 /**
20  * An edge weight function that assigns weights as uniform
21  * transition probabilities.
22  * For undirected edges, returns 1/degree(v) (where 'v' is the
23  * vertex in the VEPair.
24  * For directed edges, returns 1/outdegree(source(e)) (where 'e'
25  * is the edge in the VEPair).
26  * Throws an <code>IllegalArgumentException</code> if the input 
27  * edge is neither EdgeType.UNDIRECTED nor EdgeType.DIRECTED.
28  *
29  */
30 public class UniformDegreeWeight<V, E> implements
31                 Transformer<VEPair<V, E>, Double> 
32 {
33     private Hypergraph<V, E> graph;
34     
35     /**
36      * Creates an instance for the specified graph.
37      */
38     public UniformDegreeWeight(Hypergraph<V, E> graph)
39     {
40         this.graph = graph;
41     }
42
43         /**
44          * @see org.apache.commons.collections15.Transformer#transform(java.lang.Object)
45          */
46         public Double transform(VEPair<V, E> ve_pair) 
47         {
48                 E e = ve_pair.getE();
49                 V v = ve_pair.getV();
50                 EdgeType edge_type = graph.getEdgeType(e);
51                 if (edge_type == EdgeType.UNDIRECTED)
52                         return 1.0 / graph.degree(v);
53                 if (edge_type == EdgeType.DIRECTED)
54                         return 1.0 / graph.outDegree(graph.getSource(e));
55                 throw new IllegalArgumentException("can't handle edge type: " + edge_type);
56         }
57
58 }