Cells/cells/server/src/net/okennedy/cells/state/Canvas.scala

27 lines
574 B
Scala

package net.okennedy.cells.state
import scala.collection.mutable
import net.okennedy.cells.Identifier
import net.okennedy.cells.serialized
class Canvas()
{
val tables = mutable.Map[Identifier, Table]()
def genSafeTableId(depth: Int = 0): Identifier =
{
val id = java.util.UUID.randomUUID()
if(tables contains id){
if(depth > 100) { throw new Exception("Too Many Tables!!!") }
return genSafeTableId(depth + 1)
}
return id
}
def addTable(): Unit =
{
val table = new Table(genSafeTableId())
tables.put(table.id, table)
}
}