Created
July 7, 2011 18:50
-
-
Save razie/1070245 to your computer and use it in GitHub Desktop.
AttrAccess#1
This file contains hidden or 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
/** 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