openrat-java-client

Unnamed repository; edit this file 'description' to name the repository.
git clone http://git.code.weiherhei.de/openrat-java-client.git
Log | Files | Refs

MapConverter.java (829B)


      1 package de.openrat.client.util;
      2 
      3 import java.util.ArrayList;
      4 import java.util.Iterator;
      5 import java.util.List;
      6 import java.util.Map;
      7 import java.util.Map.Entry;
      8 
      9 public class MapConverter
     10 {
     11 
     12 	private Map<String, String> map;
     13 
     14 	public MapConverter(Map<String, String> map)
     15 	{
     16 		super();
     17 		this.map = map;
     18 	}
     19 
     20 	public String convertMapToString(String keyValueSeparator, String entrySeparator, boolean withLast)
     21 	{
     22 
     23 		List<String> list = new ArrayList<String>();
     24 
     25 		for (Entry<String, String> entry : map.entrySet())
     26 		{
     27 			list.add(entry.getKey() + keyValueSeparator + entry.getValue());
     28 		}
     29 
     30 		StringBuffer out = new StringBuffer();
     31 		for (Iterator<String> i = list.iterator(); i.hasNext();)
     32 		{
     33 			out.append(i.next());
     34 			if (withLast || i.hasNext())
     35 			{
     36 				out.append(entrySeparator);
     37 			}
     38 		}
     39 		return out.toString();
     40 
     41 	}
     42 }