better map2string and NullPointer fix

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3119 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
borg-0300 19 years ago
parent c48374d14a
commit a4f63d187d

@ -5,6 +5,10 @@
// Frankfurt, Germany, 2004 // Frankfurt, Germany, 2004
// last major change: 29.04.2004 // last major change: 29.04.2004
// //
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
//
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; either version 2 of the License, or
@ -177,22 +181,17 @@ public final class serverCodings {
} }
public static String map2string(Map m, String separator, boolean braces) { public static String map2string(Map m, String separator, boolean braces) {
StringBuffer buf = new StringBuffer(); final StringBuffer buf = new StringBuffer(512);
if (braces) buf.append("{"); if (braces) { buf.append("{"); }
Iterator i = m.entrySet().iterator(); final Iterator i = m.entrySet().iterator();
boolean hasNext = i.hasNext(); while (i.hasNext()) {
while (hasNext) { final Entry e = (Entry) (i.next());
Entry e = (Entry) (i.next()); buf.append(e.getKey()).append('=');
Object key = e.getKey(); if (e.getValue() != null) { buf.append(e.getValue()); }
Object value = e.getValue(); buf.append(separator);
buf.append(key.toString());
buf.append('=');
buf.append(value.toString());
hasNext = i.hasNext();
if (hasNext) buf.append(separator);
} }
if (braces) buf.append("}"); if (buf.length() > 1) { buf.setLength(buf.length() - 1); } // remove last separator
if (braces) { buf.append("}"); }
return buf.toString(); return buf.toString();
} }

Loading…
Cancel
Save