TheJach.com

Jach's personal blog

(Largely containing a mind-dump to myselves: past, present, and future)
Current favorite quote: "Supposedly smart people are weirdly ignorant of Bayes' Rule." William B Vogt, 2010

Why I Sometimes Really Dislike Java

I don't hate Java, but the formalities really annoy me sometimes. And I wrote this code, so I don't hate it at all. (Well, the XML design wasn't mine, and it will be refactored.) Anyway, this is why. Mainly just the first line.


Map<String, Map<String, Map<String, Map<String, String>>> > meta_data = new LinkedHashMap<String, Map<String, Map<String, Map<String, String>>> >();

while (rs.next()) {
int c = 1;
String type = rs.getString(c++);
String schemaName = rs.getString(c++);
String name = rs.getString(c++);
String col_name = rs.getString(c++);
c++;
int col_len = rs.getInt(c++);
boolean is_null = rs.getBoolean(c++);
String data_type = rs.getString(c++);

if (!meta_data.containsKey(schemaName)) {
Map<String, Map<String, Map<String, String>> > new_schema = new LinkedHashMap<String, Map<String, Map<String, String>> >();
meta_data.put(schemaName, new_schema);
}
if (!meta_data.get(schemaName).containsKey(type)) {
Map<String, Map<String, String> > new_type = new LinkedHashMap<String, Map<String, String>>();
meta_data.get(schemaName).put(type, new_type);
}
if (!meta_data.get(schemaName).get(type).containsKey(name)) {
Map<String, String> new_table = new LinkedHashMap<String, String>();
meta_data.get(schemaName).get(type).put(name, new_table);
}
if (!meta_data.get(schemaName).get(type).get(name).containsKey(col_name)) {
String null_str = (is_null) ? "NULL" : "NOT NULL";
String col_info = "(" + data_type + ", " + null_str + ")";
meta_data.get(schemaName).get(type).get(name).put(col_name, col_info);
}

}

// Now build the XML to be returned to the client.
result.append("<node label=\"Schemas\">\n"); // root node for our metadata

for (Map.Entry<String, Map<String, Map<String, Map<String, String>>> > schema : meta_data.entrySet()) {
result.append("<node label=\"" + schema.getKey() + "\">\n");
for (Map.Entry<String, Map<String, Map<String, String>>> type : schema.getValue().entrySet()) {
result.append(" <node label=\"" + type.getKey() + "s\">\n");
for (Map.Entry<String, Map<String, String>> table : type.getValue().entrySet()) {
String table_data = " <node label=\"" + table.getKey() + "\" sqlquery=\"SELECT ";
String column_data = "";
for (Map.Entry<String, String> column : table.getValue().entrySet()) {
column_data += " <node column=\"" + column.getKey() + "\" label=\"" + column.getKey()
+ " " + column.getValue() + "\" />\n";
table_data += """ + column.getKey() + "", ";
}
// chop off the last comma-space and finish the node
table_data = table_data.substring(0, table_data.lastIndexOf(", ")) + " FROM " + schema.getKey()
+ "." + table.getKey() + "\">\n";
result.append(table_data);
result.append(column_data);
result.append(" </node>\n"); // table
}
result.append(" </node>\n"); // type
}
result.append("</node>\n"); // schema
}

r


Dynamic Duck Typing ftw! I'd much rather type meta_data = {} Though the Java's not that hard to read, you just gotta look beyond the typing crap.


Posted on 2010-06-16 by Jach

Tags: java, programming

Permalink: https://www.thejach.com/view/id/105

Trackback URL: https://www.thejach.com/view/2010/6/why_i_sometimes_really_dislike_java

Back to the top

Back to the first comment

Comment using the form below

(Only if you want to be notified of further responses, never displayed.)

Your Comment:

LaTeX allowed in comments, use $$\$\$...\$\$$$ to wrap inline and $$[math]...[/math]$$ to wrap blocks.