[Vala] Having a problem understanding Vala or Gee HashMap
- From: Jason Martin <agrellum gmail com>
- To: vala-list gnome org
- Subject: [Vala] Having a problem understanding Vala or Gee HashMap
- Date: Thu, 6 Aug 2015 04:52:54 -0400
I am porting some Java software to Vala but I cannot understand why the
following code will not work like I think it should.
Vala 0.26.2, libgee-0.8 on Xubuntu 15.04
Thanks in advance. I have used many variations and casts but I cannot get
@get or has_key for Gee.HashMap to work. (website samples work fine for me)
I placed notes in the comments.
public virtual RexxNode getnode (Rexx key) {
/* this.coll is part of a whole Rexx Object */
if (this.coll == null) {
lock (this.coll) {
if (this.coll == null) { // still virgin
this.coll = new HashMap<Rexx, RexxNode> (); // make a hashtable
/* IF I place a @set entry here for testing only */
/* var node = this coll get (key) below finds it */
}
}
}
/* But it ALWAYS RETURNS NULL - for any other entry */
var node = this coll get (key); // look it up
/* foreach works like it should */
foreach (var entry in coll.entries) {
if (key.OpEqS(null, entry.key)) {
stdout.printf ("we found the key - it's there\n");
/* BUT this also RETURNS has key FALSE */
stdout.printf("has key %s\n", this.coll.has_key(key).to_string ());
node = entry.value;
}
}
if (node != null) { // found
if (node.leaf != null) {
stdout.printf ("Only gets here if foreach is used\n");
;
}
} else {
node = new RexxNode (new Rexx.clone (this)); // make node
/* @set works fine unlike @get or has_key */
this coll set (key, node); // save
}
return node;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]