Created
January 28, 2010 01:05
-
-
Save dsp/288330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.experimentalworks.scala | |
import edu.kit.ipd.sonar.server._ | |
import edu.kit.ipd.sonar.server.centralities.CentralityImpl | |
import edu.kit.ipd.sonar.server.centralities.Centrality | |
import scala.collection.JavaConversions._ | |
import scala.collection.mutable.Map | |
import java.util.{HashMap => JavaHashMap} | |
/** | |
* Indegree calculations done in Scala. | |
* | |
* @author David Soria Parra <david.parra@student.kit..edu> | |
*/ | |
class IndegreeCentrality extends CentralityImpl { | |
def getWeight(g : edu.kit.ipd.sonar.server.Graph) : JavaHashMap[Annotable, java.lang.Double]= { | |
if (g == null) | |
throw new IllegalArgumentException("Graph is null") | |
val res = new JavaHashMap[Annotable, java.lang.Double]() | |
g.getNodeList.values.foreach( | |
(n : Node) => res.put(n, g.getEdgeList().filter( | |
(e : Edge) => e.isIncomingEdge(n)).size)) | |
res | |
} | |
override def getType = Centrality.Type.NodeCentrality | |
override def getRequiredAPIVersion = 0 | |
override def getVersion = 1 | |
override def getName = "Indegree (Scala)" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment