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
#[derive(Serialize,Deserialize)] | |
struct Posts { | |
children: Vec<Post> | |
} |
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
{ | |
"kind": "Listing", | |
"data": { | |
"children": [....] | |
} | |
} |
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
/** | |
* ArrayBinaryTree implements the BinaryTreeADT interface using an array | |
* | |
* @author Dr. Lewis | |
* @author Dr. Chase | |
* @version 1.0, 8/19/08 | |
*/ | |
package jss2; | |
import java.util.Iterator; | |
import jss2.exceptions.*; |
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
val wb = workbook { | |
sheet("new sheet") { | |
row(2) { | |
cell(1.1) | |
cell(date1) | |
cell(calendar1) | |
cell("a string") | |
cell(true) | |
cell(5) { | |
cellType = ERROR |
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
fun Sheet.merge(firstRow: Int, lastRow: Int,firstCol: Int, lastCol: Int) { | |
addMergedRegion(CellRangeAddress(firstRow, lastRow, firstCol, lastCol)) | |
} | |
sheet.merge( | |
1, //first row (0-based) | |
1, //last row (0-based) | |
1, //first column (0-based) | |
2 //last column (0-based) |
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
// Notice the parameter is now of type "Workbook.() -> Unit" rather than "(Workbook) -> Unit" | |
fun workbook(block: Workbook.() -> Unit): Workbook { | |
var wb = HSSFWorkbook() | |
block(wb) | |
return wb | |
} | |
fun tryItOut() { | |
// Since we defined the lambda as using a Receiver Type of "Workbook.()" we can now directly call the methods without referencing the paramter |
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
fun Sheet.row(rowNumber: Int? = null, block: Row.() -> Unit): Row { | |
return createRow(rowNumber ?: physicalNumberOfRows).apply(block) | |
} | |
fun Row.cell(value: Any? = null, column: Int? = null, block: Cell.() -> Unit = {}): Cell { | |
val cell = createCell(column ?: physicalNumberOfCells) | |
when (value) { | |
is Calendar -> cell.setCellValue(value) | |
is Date -> cell.setCellValue(value) | |
is Boolean -> cell.setCellValue(value) |
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
fun Workbook.sheet(name: String? = null, block: Sheet.() -> Unit = {}): Sheet { | |
return if (name != null) { | |
createSheet(name) | |
} else { | |
createSheet() | |
}.apply(block) | |
} |
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
// In Kotlin function definitions start with the keywork "fun" | |
// Additionally Kotlin lets you have "top level" functions that do not need to be inside a class | |
// "(Workbook) -> Unit" means "a function that takes a workbook and returns nothing (Unit) | |
fun workbook(block: (Workbook) -> Unit): Workbook { | |
var wb = HSSFWorkbook() | |
// Note that in Kotlin we can direcly call "block" rather than needing to call "accept" on it | |
block(wb) | |
return wb | |
} |
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
public void createWorkbook() { | |
Workbook wb = new HSSFWorkbook(); | |
Sheet sheet = wb.createSheet(); | |
Row row = sheet.createRow(0); | |
row.createCell(0); | |
} |
NewerOlder