Skip to content

Commit

Permalink
[core] Update limit of row columns from 26 to 52
Browse files Browse the repository at this point in the history
  • Loading branch information
cchantep committed Dec 11, 2013
1 parent 7aed12d commit d6e4d9a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
4 changes: 3 additions & 1 deletion faq.md
Expand Up @@ -44,4 +44,6 @@ val handler = handleQuery { e: QueryExecution =>

## What's the maximum number of column for a row?

Implementations of [Row](http://cchantep.github.io/acolyte/apidocs/acolyte/Row.html) and [RowList](http://cchantep.github.io/acolyte/apidocs/acolyte/RowList.html) are provided up to 26 columns.
Implementations of [Row](http://cchantep.github.io/acolyte/apidocs/acolyte/Row.html) and [RowList](http://cchantep.github.io/acolyte/apidocs/acolyte/RowList.html) are provided up to 52 columns.

As Scala tuples are limited to 22, syntax `rowList :+ tuple` is not available above this limit.
70 changes: 35 additions & 35 deletions project/Core.scala
Expand Up @@ -24,7 +24,7 @@ trait Core {
// Source generator
private def generateRowClasses(basedir: File, managedSources: File): Seq[File] = {
val rowTmpl = basedir / "src" / "main" / "templates" / "Row.tmpl"
val letter = 'A' to 'Z'
val letter = ('A' to 'Z').map(_.toString) ++: ('A' to 'Z').map(l "A" + l)
val lim = letter.size

val rows: Seq[java.io.File] = for (n 2 to lim) yield {
Expand Down Expand Up @@ -56,15 +56,15 @@ trait Core {
IO.foreachLine(r) { l
w.append(l.replaceAll("#N#", n.toString).
replaceAll("#CP#", cp.mkString(",")).
replace("#PS#", ps.mkString("\r\n ")).
replace("#AS#", as.mkString("\r\n ")).
replace("#PS#", ps.mkString("\n ")).
replace("#AS#", as.mkString("\n ")).
replace("#IP#", ip.mkString(", ")).
replace("#RP#", rp.mkString("\r\n ")).
replace("#RP#", rp.mkString("\n ")).
replace("#NA#", na.mkString(", ")).
replace("#SP#", sp.mkString("\r\n\r\n ")).
replace("#HC#", hc.mkString(".\r\n ")).
replace("#EQ#", eq.mkString(".\r\n "))).
append("\r\n")
replace("#SP#", sp.mkString("\n\n ")).
replace("#HC#", hc.mkString(".\n ")).
replace("#EQ#", eq.mkString(".\n "))).
append("\n")

}
}
Expand Down Expand Up @@ -104,14 +104,14 @@ public final class Rows {""")
p.mkString(", "), n, gd, a.mkString(", ")))
}

w.append("\r\n}")
w.append("\n}")

f
}
}

val listTmpl = basedir / "src" / "main" / "templates" / "RowList.tmpl"
val rowLists: Seq[java.io.File] = for (n <- 2 to lim) yield {
val rowLists: Seq[java.io.File] = for (n 2 to lim) yield {
val f = managedSources / "acolyte" / "RowList%d.java".format(n)
val cp = for (i 0 until n) yield letter(i)
val cs = for (i 0 until n) yield {
Expand All @@ -127,28 +127,28 @@ public final class Rows {""")
colClasses.add(c%d);""".format(i, i, i)
}
val ca = for (i 0 until n) yield "c%d".format(i)
val ap = cp map { l "final %s %s".format(l, l.toLower) }
val ap = cp map { l "final %s %s".format(l, l.toLowerCase) }
val ps = for (i 0 until n) yield {
"""/**
* Class of column #%d
*/
private final Class<%s> c%d;""".format(i, letter(i), i)
}

IO.writer[java.io.File](f, "", IO.defaultCharset, false) { w =>
IO.writer[java.io.File](f, "", IO.defaultCharset, false) { w
// Generate by substitution on each line of template
IO.reader[Unit](listTmpl) { r
IO.foreachLine(r) { l
IO.foreachLine(r) { l
w.append(l.replaceAll("#N#", n.toString).
replaceAll("#CP#", cp.mkString(",")).
replaceAll("#CS#", cs.mkString(", ")).
replaceAll("#AP#", ap.mkString(", ")).
replaceAll("#AV#", cp.map(_.toLower).mkString(", ")).
replaceAll("#PS#", ps.mkString("\r\n\r\n ")).
replaceAll("#IC#", ic.mkString("\r\n\r\n ")).
replaceAll("#AC#", ac.mkString("\r\n\r\n ")).
replaceAll("#AV#", cp.map(_.toLowerCase).mkString(", ")).
replaceAll("#PS#", ps.mkString("\n\n ")).
replaceAll("#IC#", ic.mkString("\n\n ")).
replaceAll("#AC#", ac.mkString("\n\n ")).
replaceAll("#CA#", ca.mkString(", "))).
append("\r\n")
append("\n")
}
}

Expand All @@ -160,22 +160,22 @@ public final class Rows {""")
val rlf: java.io.File = {
val f = managedSources / "acolyte" / "RowLists.java"

IO.writer[java.io.File](f, "", IO.defaultCharset, false) { w =>
val funcs = (1 to lim).foldLeft(Nil:List[String]) { (l, n) =>
val g = for (i <- 0 until n) yield letter(i)
val ps = for (i <- 0 until n) yield {
"final Class<%s> c%d".format(letter(i), i)
}
val cs = for (i <- 0 until n) yield {
"final RowList.Column<%s> c%d".format(letter(i), i)
}
val as = for (i <- 0 until n) yield "c%d".format(i)
val ls = for (i <- 0 until n) yield {
"withLabel(%d, c%d.name)".format(i+1, i)
}
val gp = g.mkString(",")

l :+ """
IO.writer[java.io.File](f, "", IO.defaultCharset, false) { w
val funcs = (1 to lim).foldLeft(Nil: List[String]) { (l, n)
val g = for (i 0 until n) yield letter(i)
val ps = for (i 0 until n) yield {
"final Class<%s> c%d".format(letter(i), i)
}
val cs = for (i 0 until n) yield {
"final RowList.Column<%s> c%d".format(letter(i), i)
}
val as = for (i 0 until n) yield "c%d".format(i)
val ls = for (i 0 until n) yield {
"withLabel(%d, c%d.name)".format(i + 1, i)
}
val gp = g.mkString(",")

l :+ """
/**
* Returns list of row with %d column(s).
*/
Expand All @@ -189,7 +189,7 @@ public final class Rows {""")

IO.reader[java.io.File](facTmpl) { r
IO.foreachLine(r) { l
w.append(l.replace("#F#", funcs.mkString("\r\n"))).append("\r\n")
w.append(l.replace("#F#", funcs.mkString("\n"))).append("\n")
}
f
}
Expand Down

0 comments on commit d6e4d9a

Please sign in to comment.