Skip to content

Instantly share code, notes, and snippets.

@razie
Created July 7, 2011 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save razie/1070245 to your computer and use it in GitHub Desktop.
Save razie/1070245 to your computer and use it in GitHub Desktop.
AttrAccess#1
/** simple Java access interface - needs sync-ing with some Java typical interfaces, probably Properties */
trait JavaAttrAccess {
/** set the value of the named attribute + the name can be of the form name:type */
def setValue(name: String, value: AnyRef, t: AttrType): Unit
def setValue(name: String, value: AnyRef): Unit
def getValue(name: String): AnyRef
def getType(name: String): AttrType
}
/** simple name-value pairs with optional type */
trait AttrAccess extends collection.mutable.Map[String, AnyRef] with JavaAttrAccess {
def types: Map[String, AttrType]
}
class AttrAccessImpl extends AttrAccess {
val types = new collection.mutable.HashMap[String, AttrType]()
def setValue(name: String, value: AnyRef, t: AttrType) {
this put (name, value)
types put (name, t)
}
def setValue(name: String, value: AnyRef) {
this put (name, value)
}
def getValue(name: String): AnyRef = this(name)
def getType(name: String): AttrType = types.getOrElse(name, AttrType.DEFAULT)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment