/source/Info.ooc

http://github.com/eagle2com/boulvouzoun · Unknown · 68 lines · 42 code · 26 blank · 0 comment · 0 complexity · 5cf33602719d1a0641b9ff03707a2d17 MD5 · raw file

  1. include stdint
  2. import structs/[LinkedList, ArrayList, List, HashMap]
  3. import Relation
  4. ID: cover from Int {
  5. toString: func -> String { this as Int toString() }
  6. getInfo: func -> Info { Info get(this) }
  7. }
  8. Info: abstract class {
  9. trust: Double = 0.0
  10. relations: LinkedList<Relation>
  11. humanNames: ArrayList<String>
  12. id: ID
  13. lastID: static ID = 1 // an ID of 0 is invalid
  14. map := static HashMap<This> new()
  15. init: func {
  16. relations = LinkedList<Relation> new()
  17. humanNames = ArrayList<String> new()
  18. id = lastID
  19. lastID += 1
  20. map put(id toString(), this)
  21. }
  22. init: func ~humanName (humanName: String) {
  23. init()
  24. humanNames add(humanName)
  25. }
  26. getRelations: func -> List<Relation> { relations }
  27. addRelation: func (r: Relation) {
  28. relations add(r)
  29. }
  30. rate: func(d: Double) {
  31. trust += d
  32. }
  33. getID: func -> ID { id }
  34. get: static func (id: ID) -> This { map get(id toString()) }
  35. toString: func -> String {
  36. if(!humanNames isEmpty()) {
  37. return humanNames[0]
  38. } else {
  39. return "noname"
  40. }
  41. }
  42. }