Skip to content

Instantly share code, notes, and snippets.

@dsp
Created January 28, 2010 01:05
Show Gist options
  • Save dsp/288330 to your computer and use it in GitHub Desktop.
Save dsp/288330 to your computer and use it in GitHub Desktop.
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