All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openas2.lib.util.GeneralUtil Maven / Gradle / Ivy

Go to download

Open source implementation of the AS2 standard for signed encrypted and compressed document transfer

There is a newer version: 2.10.1
Show newest version
package org.openas2.lib.util;

import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class GeneralUtil {


    public static String[] convert(Enumeration en) {
        List list = Collections.list(en);        
        return convert(list);
    }

    static String[] convert(List list)
    {
        String[] values = new String[0];
        return list.toArray(values);
    }
    
    public static String[] convertKeys(Map map) {
        String[] keys = new String[0];
        return map.keySet().toArray(keys);
    }
    
    public static String convert(Map map, String valueDelimiter, String pairDelimiter) {
		StringBuffer strBuf = new StringBuffer();
		Iterator it = map.entrySet().iterator();
		Map.Entry entry;
		while (it.hasNext()) {
			entry = (Entry) it.next();
			strBuf.append(entry.getKey().toString()).append(valueDelimiter);
			strBuf.append(entry.getValue().toString());
			if (it.hasNext()) {
			    strBuf.append(pairDelimiter);
			}
		}
		return strBuf.toString();
	}

    public static Object getKey(Map map, Object value) {
        Iterator it = map.entrySet().iterator();
        Map.Entry entry;
        Object currentValue;
        while (it.hasNext()) {
            entry = (Entry) it.next();
            currentValue = entry.getValue();
            if (currentValue == null && value == null) {
                return entry.getKey();
            } else if (currentValue != null && currentValue.equals(value)) {
                return entry.getKey();
            }
        }
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy