| TYPE | KEY | HASH_LEVEL | VALUE_TYPE | VALUE_STRING | VALUE_TIMESTAMP | VALUE_INT | ... | ... |
| 'data' 'key' 'error' 'warning' |
%Hashtable's key% | %int% | 'string' 'integer' 'boolean' 'timestamp' |
List levels;
Vector errors = new Vector();
Vector warnings = new Vector();
Hash root = new Hash();
Hash branch = root;
levels[0] = root; // this hash added at the index 0
foreach row {
if row.TYPE is 'data' { // this row is a hash
if row.HASH_LEVEL > -1 {
branch = new Hash();
Hash parent = levels.getAt(row.HASH_LEVEL);
parent.put(row.KEY, branch);
levels[row.HASH_LEVEL+1] = branch;
}
foreach row.other.columns {
if row.other.column.value is not null {
if row.HASH_LEVEL == -1
root.put(LowerCase(row.other.column.name), row.other.column.value);
else
branch.put(LowerCase(row.other.column.name), row.other.column.value);
}
}
} else if row.TYPE is 'key' {
case row.VALUE_TYPE {
when 'string' : branch.put(row.KEY, row.VALUE_STRING); break;
when 'integer' : branch.put(row.KEY, row.VALUE_INT); break;
when 'boolean' : branch.put(row.KEY, row.VALUE_INT==0?false:true); break;
when 'timestamp': branch.put(row.KEY, row.VALUE_TIMESTAMP); break;
}
} else if row.TYPE is 'warning' {
warnings.add(row.VALUE_STRING);
} else if row.TYPE is 'error' {
errors.add(row.VALUE_STRING);
}
}
if warnings is not empty {
root.put('warnings', warnings);
}
if errors is not empty {
root.put('errors', errors);
}
TYPE KEY HASH_LEVEL VALUE_TYPE VALUE_STRING OBJECT CREATED_AT ----------------------------------------------------------------------------------------------- data NULL -1 NULL NULL node 2005-02-13 22:17:35.0 data groups 0 NULL NULL NULL NULL key ASSU NULL string NULL NULL key Aero/Astro NULL string NULL NULL key Alumni Association NULL string NULL NULL key Anthropology NULL string NULL NULL key Art NULL string NULL NULL key Asian Languages NULL string NULL NULLResulting hash
(Hash) <object> -> [node] <created_at> -> [2005-02-13 22:17:40.0] <groups> <Alumni Association> -> [] <ASSU> -> [] <Art> -> [] <Aero/Astro> -> [] <Asian Languages> -> [] <Anthropology> -> []