Skip to content

Commit

Permalink
Add class parameter to TabulaMapImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
julianmendez committed Nov 6, 2018
1 parent ed3df1e commit dcd846e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class SimpleFormatParser(input: Reader) extends Parser {

}

val result = new TableMapImpl()
val result = TableMapImpl()
mapOfTables.keySet.foreach(key => result.put(key, mapOfTables.get(key).get))
result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,19 @@ import scala.collection.mutable
/** This is the default implementation of a table map.
*
*/
class TableMapImpl extends TableMap {

private val _map = new mutable.TreeMap[String, Table]()

/** Constructs a new table map using another one.
*
* @param otherTableMap
* other table map
*/
def this(otherTableMap: TableMap) = {
this()
otherTableMap.getTableIds.foreach(tableId => put(tableId, otherTableMap.getTable(tableId).get))
}
class TableMapImpl(map: mutable.TreeMap[String, Table]) extends TableMap {

override def getTableIds: Seq[String] = {
val result = new mutable.ArrayBuffer[String]()
result ++= this._map.keySet
result ++= this.map.keySet
result
}

override def put(id: String, table: Table): Option[Table] = { this._map.put(id, table) }
override def put(id: String, table: Table): Option[Table] = { this.map.put(id, table) }

override def getTable(id: String): Option[Table] = { this._map.get(id) }
override def getTable(id: String): Option[Table] = { this.map.get(id) }

override def hashCode(): Int = { this._map.hashCode() }
override def hashCode(): Int = { this.map.hashCode() }

override def equals(obj: Any): Boolean = {
val result = obj match {
Expand Down Expand Up @@ -59,6 +47,18 @@ class TableMapImpl extends TableMap {

object TableMapImpl {

def apply(): TableMapImpl = new TableMapImpl
def apply(): TableMapImpl = new TableMapImpl(mutable.TreeMap[String, Table]())

/** Constructs a new table map using another one.
*
* @param otherTableMap
* other table map
*/
def apply(otherTableMap: TableMap): TableMapImpl = {
val map = mutable.TreeMap[String, Table]()
otherTableMap.getTableIds
.foreach(tableId => map.put(tableId, otherTableMap.getTable(tableId).get))
new TableMapImpl(map)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MainTest extends FunSuite {

// Make a copy of the tableMap
// val newTableMap: TableMapImpl = new TableMapImpl(oldTableMap)
val newTableMap: TableMapImpl = new TableMapImpl()
val newTableMap: TableMapImpl = TableMapImpl()
oldTableMap.getTableIds.foreach(tableId => newTableMap.put(tableId, oldTableMap.getTable(tableId).get))

assertContent(newTableMap, ExpectedOutputFileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class CalendarParser extends Parser {
+ " keywords (line " + lineCounter + ").")
}

val result: TableMapImpl = new TableMapImpl()
val result: TableMapImpl = TableMapImpl()
map.keySet.foreach(key => result.put(key, map.get(key).get))
result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class CsvParser extends Parser {
}
}

val result: TableMapImpl = new TableMapImpl()
val result: TableMapImpl = TableMapImpl()
result.put(DefaultTableName, currentTable)
result
}
Expand Down

0 comments on commit dcd846e

Please sign in to comment.