Add tags

Add tags to the following comment
 scala-library.jarとscala-swing.jarについて調べてみました。Java側のリフレクションを使って調べているので,ソースコード上の値とはずれがあります。

total:  3173
scala.swing.Key:        206
scala.collection.jcl.Buffer$Projection: 166
scala.collection.jcl.ArrayList: 158
scala.collection.jcl.LinkedList:        158
scala.collection.jcl.Buffer$$anon$2:    155
scala.collection.jcl.SortedMap$$anon$1: 153
scala.collection.jcl.TreeMap:   153
scala.collection.jcl.SortedMap$$anon$2: 151
scala.collection.jcl.Buffer$Range:      150
scala.collection.jcl.TreeSet:   146
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import scala.collection.jcl.Conversions
import java.io.File
import java.util.Collections
import java.util.jar.{JarEntry,JarFile}

object MethodCount {
    def getClassInformations(l:List[String]):List[Pair[String,Int]] = {
        def getInfo(n:String):Pair[String,Int] =
            try { (n, Class.forName(n).getDeclaredMethods.size) } catch { case _ => (n, -1) }
        def isClass(n:String):Boolean = n.endsWith(".class") && !n.matches("\\$\\$anonfun\\$")
        def getClassName(n:String):String = n.substring(0, n.length - 6).replace('/', '.')
        def getJarEntries(f:File):List[JarEntry] =
            Conversions.convertList(Collections.list((new JarFile(f)).entries)).toList
        def getFiles(l:List[String]):List[File] =
            l.map(new File(System.getProperty("scala.home"), _)).filter(_.exists)
        getFiles(l).map(getJarEntries).flatten(identity(_)).map(_.getName).filter(isClass).map(getClassName).map(getInfo)
    }
    def main(args:Array[String]):Unit = {
        val l:List[Pair[String,Int]] = getClassInformations(List("lib/scala-library.jar", "lib/scala-swing.jar"))
        Console.printf("total:\t%d\n", l.size)
        l.sort(_._2 > _._2).take(10).foreach((i) => Console.printf("%s:\t%d\n", i._1, i._2))
    }
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...