Changeset 7415 for lang/scala
- Timestamp:
- 03/03/08 21:40:54 (9 months ago)
- Location:
- lang/scala/sandbox/src/jp/ryugate
- Files:
-
- 5 modified
-
apache/POI.scala (modified) (6 diffs)
-
apache/POISpecification.scala (modified) (2 diffs)
-
net/Http.scala (modified) (4 diffs)
-
text/RegexpSpecification.scala (modified) (1 diff)
-
video/Timecode.scala (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/scala/sandbox/src/jp/ryugate/apache/POI.scala
r6890 r7415 18 18 = n.foldLeft(List[T]()){(acc, i) => f(i) :: acc}.reverse 19 19 20 private def eachWithIndex[T ](lst:List[T], f2:(T,int) => Unit)20 private def eachWithIndex[T,V](lst:List[T], f2:(T,int) => V) 21 21 = lst.zipWithIndex.foreach{case (row,idx) => f2(row,idx)} 22 22 … … 36 36 } 37 37 38 def withSheet (index:int )(f:Sheet => Unit):Unit= f(sheet(index))39 def withSheet (name:String)(f:Sheet => Unit):Unit= f(sheet(name))38 def withSheet[V](index:int )(f:Sheet => V) = f(sheet(index)) 39 def withSheet[V](name:String)(f:Sheet => V) = f(sheet(name)) 40 40 41 41 def sheets(idxs:int* ) = makeSomeList(sheet, idxs:_*) 42 42 def sheets(range:Range) = makeSomeList(sheet, range:_*) 43 43 44 def eachSheets (idxs:int* )(f:Sheet => Unit):Unit= sheets(idxs:_* ).foreach{f(_)}45 def eachSheets (range:Range)(f:Sheet => Unit):Unit= sheets(range:_*).foreach{f(_)}44 def eachSheets[V](idxs:int* )(f:Sheet => V) = sheets(idxs:_* ).foreach{f(_)} 45 def eachSheets[V](range:Range)(f:Sheet => V) = sheets(range:_*).foreach{f(_)} 46 46 47 def eachSheetsWithIndex (idxs:int* )(f:(Sheet,int) => Unit) = eachWithIndex(sheets(idxs:_*), f)48 def eachSheetsWithIndex (range:Range)(f:(Sheet,int) => Unit) = eachWithIndex(sheets(range:_*), f)47 def eachSheetsWithIndex[V](idxs:int* )(f:(Sheet,int) => V) = eachWithIndex(sheets(idxs:_*), f) 48 def eachSheetsWithIndex[V](range:Range)(f:(Sheet,int) => V) = eachWithIndex(sheets(range:_*), f) 49 49 50 def each (f:Sheet => Unit):Unit= eachSheets(1 to hssf_book.getNumberOfSheets)(f)50 def each[V](f:Sheet => V) = eachSheets(1 to hssf_book.getNumberOfSheets)(f) 51 51 52 52 //-------------------------------------------- … … 65 65 def cell(ri:int,ci:int) = row(ri).apply(ci) 66 66 67 def withRow (ri:int)(f:Row => Unit):Unit= f(row(ri))68 def withCol (ci:int)(f:Col => Unit):Unit= f(col(ci))67 def withRow[V](ri:int)(f:Row => V) = f(row(ri)) 68 def withCol[V](ci:int)(f:Col => V) = f(col(ci)) 69 69 70 70 def rows(rowIdxs:int*) = makeSomeList(row, rowIdxs:_*) … … 73 73 def cols(range:Range ) = makeSomeList(col, range:_*) 74 74 75 def eachRows (rowIdxs:int*)(f:Row => Unit) = rows(rowIdxs:_*).foreach{f(_)}76 def eachCols (colIdxs:int*)(f:Col => Unit) = cols(colIdxs:_*).foreach{f(_)}77 def eachRows (range:Range )(f:Row => Unit) = rows(range ).foreach{f(_)}78 def eachCols (range:Range )(f:Col => Unit) = cols(range ).foreach{f(_)}75 def eachRows[V](rowIdxs:int*)(f:Row => V) = rows(rowIdxs:_*).foreach{f(_)} 76 def eachCols[V](colIdxs:int*)(f:Col => V) = cols(colIdxs:_*).foreach{f(_)} 77 def eachRows[V](range:Range )(f:Row => V) = rows(range ).foreach{f(_)} 78 def eachCols[V](range:Range )(f:Col => V) = cols(range ).foreach{f(_)} 79 79 80 def eachRowsWithIndex (idxs:int* )(f:(Row,int) => Unit) = eachWithIndex(rows(idxs:_*), f)81 def eachColsWithIndex (idxs:int* )(f:(Col,int) => Unit) = eachWithIndex(cols(idxs:_*), f)82 def eachRowsWithIndex (range:Range)(f:(Row,int) => Unit) = eachWithIndex(rows(range:_*), f)83 def eachColsWithIndex (range:Range)(f:(Col,int) => Unit) = eachWithIndex(cols(range:_*), f)80 def eachRowsWithIndex[V](idxs:int* )(f:(Row,int) => V) = eachWithIndex(rows(idxs:_*), f) 81 def eachColsWithIndex[V](idxs:int* )(f:(Col,int) => V) = eachWithIndex(cols(idxs:_*), f) 82 def eachRowsWithIndex[V](range:Range)(f:(Row,int) => V) = eachWithIndex(rows(range:_*), f) 83 def eachColsWithIndex[V](range:Range)(f:(Col,int) => V) = eachWithIndex(cols(range:_*), f) 84 84 85 def each (f:Row => Unit):Unit= eachRows(0 to getLastRowNum)(f)85 def each[V](f:Row => V) = eachRows(0 to getLastRowNum)(f) 86 86 87 87 //-------------------------------------------- … … 115 115 def cells(range:Range) = makeSomeList(apply, range:_*) 116 116 117 def eachCells (idxs:int* )(f:Cell => Unit) = cells(idxs:_* ).foreach{f(_)}118 def eachCells (range:Range)(f:Cell => Unit) = cells(range:_*).foreach{f(_)}117 def eachCells[V](idxs:int* )(f:Cell => V) = cells(idxs:_* ).foreach{f(_)} 118 def eachCells[V](range:Range)(f:Cell => V) = cells(range:_*).foreach{f(_)} 119 119 120 def eachCellsWithIndex (idxs:int* )(f:(Cell,int) => Unit) = eachWithIndex(cells(idxs:_*), f)121 def eachCellsWithIndex (range:Range)(f:(Cell,int) => Unit) = eachWithIndex(cells(range:_*), f)120 def eachCellsWithIndex[V](idxs:int* )(f:(Cell,int) => V) = eachWithIndex(cells(idxs:_*), f) 121 def eachCellsWithIndex[V](range:Range)(f:(Cell,int) => V) = eachWithIndex(cells(range:_*), f) 122 122 123 def each (f:Cell => Unit):Unit= eachCells(0 to hssf_row.getLastCellNum)(f)123 def each[V](f:Cell => V) = eachCells(0 to hssf_row.getLastCellNum)(f) 124 124 125 125 //-------------------------------------------- … … 151 151 def cells(range:Range) = makeSomeList(apply, range:_*) 152 152 153 def eachCells (idxs:int* )(f:Cell => Unit) = cells(idxs:_* ).foreach{f(_)}154 def eachCells (range:Range)(f:Cell => Unit) = cells(range:_*).foreach{f(_)}153 def eachCells[V](idxs:int* )(f:Cell => V) = cells(idxs:_* ).foreach{f(_)} 154 def eachCells[V](range:Range)(f:Cell => V) = cells(range:_*).foreach{f(_)} 155 155 156 def eachCellsWithIndex (idxs:int* )(f:(Cell,int) => Unit) = eachWithIndex(cells(idxs:_*), f)157 def eachCellsWithIndex (range:Range)(f:(Cell,int) => Unit) = eachWithIndex(cells(range:_*), f)156 def eachCellsWithIndex[V](idxs:int* )(f:(Cell,int) => V) = eachWithIndex(cells(idxs:_*), f) 157 def eachCellsWithIndex[V](range:Range)(f:(Cell,int) => V) = eachWithIndex(cells(range:_*), f) 158 158 159 def each (f:Cell => Unit):Unit= eachCells(0 to sheet.getLastRowNum)(f)159 def each[V](f:Cell => V) = eachCells(0 to sheet.getLastRowNum)(f) 160 160 } 161 161 -
lang/scala/sandbox/src/jp/ryugate/apache/POISpecification.scala
r6890 r7415 3 3 import org.specs._ 4 4 import org.specs.matcher._ 5 import org.specs.matcher.AnyMatchers6 import org.specs.matcher.PatternMatchers.CaseMatcher7 5 8 6 object POISpecification extends Specification { … … 12 10 13 11 "POI module" should { 14 val book = new Book("test .xls")12 val book = new Book("testdata/test.xls") 15 13 val sheet1 = book.sheet(1) 16 14 -
lang/scala/sandbox/src/jp/ryugate/net/Http.scala
r6269 r7415 1 // if (_proxy != null) { 2 // val proxy_addr = new InetSocketAddress(PROXY_HOST, PROXY_PORT) 3 // val proxy = new Proxy(Proxy.Type.HTTP, proxy_addr) 4 // } 5 1 6 package jp.ryugate.net 2 7 … … 10 15 def get(resource:String):String = { 11 16 val url = new URL("http://" + host + resource) 17 val br = new BufferedReader(new InputStreamReader(getInputStream(url))) 18 try { 19 readContents("", (br.readLine _)) 20 } finally { 21 br.close 22 } 23 } 24 25 def getInputStream(url: URL) = { 12 26 val con = url.openConnection.asInstanceOf[HttpURLConnection] 13 27 if (_read_timeout > 0) con.setReadTimeout(_read_timeout) 14 28 con.setRequestMethod("GET") 15 val br = new BufferedReader(new InputStreamReader(con.getInputStream)) 16 readContents("", (br.readLine _)) 29 con.getInputStream 17 30 } 18 31 19 def readContents(acc:String, reader:()=>String):String = reader() match {32 def readContents(acc:String, reader:()=>String):String = reader() match { 20 33 case null => acc 21 34 case s => readContents(acc + s, reader) … … 23 36 24 37 def read_timeout:int = _read_timeout 25 def read_timeout_=(timeout:int) { _read_timeout = timeout} 38 def read_timeout_=(timeout:int) { _read_timeout = timeout } 39 40 // def proxy_host:String = _proxy_host 41 // def proxy_host_=(proxy_host:String) { _proxy_host = proxy_host } 26 42 } 27 43 … … 30 46 f(http) 31 47 } 48 49 // def get(url:String) 32 50 } 33 51 -
lang/scala/sandbox/src/jp/ryugate/text/RegexpSpecification.scala
r6122 r7415 63 63 } 64 64 65 "=~" in { 66 ("piyohoge" =~ "hoge") must beTrue 65 // "=~" in { 66 // ("piyohoge" =~ "hoge") must beTrue 67 // } 68 69 "with Pattern match" in { 70 var ans = "" 71 72 val lst = List("hoge", "piyo", "foo", "hogepiyo") 73 lst.foreach {item => 74 item match { 75 case s if s =~ "h..e" => ans += s 76 case s if s =~ "p[iy]+o" => ans += s 77 case _ => null 78 } 79 } 80 ans must be_==("hogepiyohogepiyo") 67 81 } 82 68 83 } 69 84 } -
lang/scala/sandbox/src/jp/ryugate/video/Timecode.scala
r6119 r7415 3 3 import jp.ryugate.text.Format 4 4 5 object Timecode { 6 class TimecodeFactory(rate:Any) { 7 def make(hh:int, mm:int, ss:int, ff:int) = rate match { 8 case "ntsc" => 9 val minutes = hh * 60 + mm 10 new Timecode(17982 * (minutes/10) + 1798 * (minutes%10) + ss * 30 + ff) 11 case r:Int => 12 val mrate = r * 60 13 val hrate = mrate * 60 14 new Timecode(hh * hrate + mm * mrate + ss * r + ff) 15 } 5 class Timecode(val frames:Int, val rate:Any) { 6 def this(hh:Int, mm:Int, ss:Int, ff:Int, rate:Any) = this( rate match { 7 case "ntsc" => 8 val minutes = hh * 60 + mm 9 17982 * (minutes/10) + 1798 * (minutes%10) + ss * 30 + ff 10 case r:Int => 11 val mrate = r * 60 12 val hrate = mrate * 60 13 hh * hrate + mm * mrate + ss * r + ff 14 }, rate) 15 16 def changeRate(r:Any) = new Timecode(frames, r) 17 18 override def toString = rate match { 19 case "ntsc" => 20 val hh = frames / 17982 / 6 21 val mm = frames / 17982 % 6 * 10 + (frames % 17982 - 2) / 1798 22 val ss = ((frames % 17982 - 2) % 1798 + 2) / 30 23 val ff = ((frames % 17982 - 2) % 1798 + 2) % 30 24 sprIntf("%02d:%02d:%02d;%02d", hh,mm,ss,ff) 25 case r:Int => 26 val m = r * 60 27 val h = m * 60 28 val hh = frames / h 29 val mm = (frames % h) / m 30 val ss = ((frames % h) % m) / r 31 val ff = ((frames % h) % m) % r 32 sprIntf("%02d:%02d:%02d:%02d", hh,mm,ss,ff) 16 33 } 17 34 18 class Timecode(frames:int) { 19 class Tcode(hh:int, mm:int, ss:int, ff:int) { 20 def hour = hh 21 def minutes = mm 22 def second = ss 23 def frame = ff 24 25 override def toString() = Format.sprintf("%02d:%02d:%02d.%02d", hh,mm,ss,ff) 26 } 35 def +(add:Int) = new Timecode(frames + add, rate) 36 def -(sub:Int) = new Timecode(frames - sub, rate) 27 37 28 def ntsc = 29 new Tcode(frames / 17982 / 6, 30 frames / 17982 % 6 * 10 + (frames % 17982 - 2) / 1798, 31 ((frames % 17982 - 2) % 1798 + 2) / 30, 32 ((frames % 17982 - 2) % 1798 + 2) % 30 33 ) 38 private def sprIntf(fmt:String, args:Any*) = String.format(fmt, args.map(e => e.asInstanceOf[AnyRef]).toArray) 39 } 34 40 35 def tc:Tcode = tc(30) 36 def tc(rate:int):Tcode = { 37 val m = rate * 60 38 val h = m * 60 39 new Tcode(frames / h, 40 (frames % h) / m, 41 ((frames % h) % m) / rate, 42 ((frames % h) % m) % rate 43 ) 44 } 45 } 41 object TimecodeTest extends Application { 42 println("DROP") 43 val t1 = new Timecode(0,0,59,27,"ntsc") 44 (1 to 5).foreach {i => println(t1 + i) } 45 46 println("NONDROP") 47 val t2 = t1.changeRate(30) 48 (1 to 5).foreach {i => println(t2 + i) } 49 50 println("DROP 10min") 51 val t4 = new Timecode(0,9,59,27, "ntsc") 52 (1 to 5).foreach {i => println(t4 + i) } 53 54 println("NONDROP 10min") 55 val t3 = new Timecode(0,9,59,27, 30) 56 (1 to 5).foreach {i => println(t3 + i) } 46 57 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)