PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/source/Info.ooc

http://github.com/eagle2com/boulvouzoun
Unknown | 68 lines | 42 code | 26 blank | 0 comment | 0 complexity | 5cf33602719d1a0641b9ff03707a2d17 MD5 | raw file
 1include stdint
 2
 3import structs/[LinkedList, ArrayList, List, HashMap]
 4import Relation
 5
 6ID: cover from Int {
 7    
 8    toString: func -> String { this as Int toString() }
 9    
10    getInfo: func -> Info { Info get(this) }
11    
12}
13
14Info: abstract class {
15    
16    
17	trust: Double = 0.0
18	relations: LinkedList<Relation>
19	humanNames: ArrayList<String>
20    
21	id: ID
22    
23	lastID: static ID = 1 // an ID of 0 is invalid
24    map := static HashMap<This> new()
25	
26	init: func {
27		relations = LinkedList<Relation> new()
28		humanNames = ArrayList<String> new()
29            
30		id = lastID
31        lastID += 1
32        
33        map put(id toString(), this)
34	}
35    
36    init: func ~humanName (humanName: String) {
37        init()
38        humanNames add(humanName)
39    }
40    
41    getRelations: func -> List<Relation> { relations }
42    
43    addRelation: func (r: Relation) {
44        relations add(r)
45    }
46	
47	rate: func(d: Double) {
48		trust += d
49	}
50    
51    getID: func -> ID { id }
52    
53    get: static func (id: ID) -> This { map get(id toString()) }
54    
55    toString: func -> String {
56        
57        if(!humanNames isEmpty()) {
58            return humanNames[0]
59        } else {
60            return "noname"
61        }
62        
63    }
64	
65}
66
67
68