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

org.hibernate.tool.hbm2x.MetaAttributeHelper Maven / Gradle / Ivy

There is a newer version: 5.6.15.Final
Show newest version
package org.hibernate.tool.hbm2x;

import java.util.Collection;
import java.util.Iterator;

import org.apache.commons.collections4.MultiValuedMap;
import org.hibernate.cfg.reveng.utils.MetaAttributeHelper.SimpleMetaAttribute;
import org.hibernate.mapping.MetaAttribute;

/**
 * Helper for loading, merging  and accessing  tags.
 * 
 * @author max
 *
 * 
 */
public final class MetaAttributeHelper {
 
	private MetaAttributeHelper() {
		//noop
	}
	
	/**
	 * @param collection
	 * @param string
	 */
	public static String getMetaAsString(Collection meta, String seperator) {
		if(meta==null || meta.isEmpty() ) {
	        return "";
	    }
		StringBuffer buf = new StringBuffer();
		
			for (Iterator iter = meta.iterator(); iter.hasNext();) {				
				buf.append(iter.next() );
				if(iter.hasNext() ) buf.append(seperator);
			}
		return buf.toString();
	}

	public static String getMetaAsString(MetaAttribute meta, String seperator) {
		if(meta==null) {
			return null;
		} 
		else {
			return getMetaAsString(meta.getValues(),seperator);
		}
	}

	static	boolean getMetaAsBool(Collection c, boolean defaultValue) {
			if(c==null || c.isEmpty() ) {
				return defaultValue;
			} 
			else {
				return Boolean.valueOf(c.iterator().next().toString() ).booleanValue();
			}
		}

	public static String getMetaAsString(org.hibernate.mapping.MetaAttribute c) {		
		return c==null?"":getMetaAsString(c.getValues() );
	}
	
	static String getMetaAsString(Collection c) {
		return getMetaAsString(c, "");
	}

    public static void copyMultiMap(
    		MultiValuedMap destination, 
    		MultiValuedMap specific) {
        for (Iterator keyIterator = specific.keySet().iterator(); keyIterator.hasNext(); ) {
            String key = keyIterator.next();
            Collection c = specific.get(key);
            for (Iterator valueIterator = c.iterator(); valueIterator.hasNext();) { 
                destination.put(key, valueIterator.next() );
            }
        }
    }
    
	public static boolean getMetaAsBool(org.hibernate.mapping.MetaAttribute metaAttribute, boolean defaultValue) {
		return getMetaAsBool(metaAttribute==null?null:metaAttribute.getValues(), defaultValue);
	}

	

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy