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

org.jvnet.hyperjaxb3.item.MixedItemUtils Maven / Gradle / Ivy

package org.jvnet.hyperjaxb3.item;

import java.util.List;

public class MixedItemUtils {

	public static > ItemType create(
			Class itemClass, T value) {
		try {
			final ItemType item = itemClass.newInstance();
			item.setItem(value);
			return item;
		} catch (InstantiationException ex) {
			throw new IllegalArgumentException("Error in default constructor.",
					ex);
		} catch (IllegalAccessException ex) {
			throw new IllegalArgumentException("Error in default constructor.",
					ex);
		}
	}

	public static > ItemType create(
			Class itemClass, String value) {
		try {
			final ItemType item = itemClass.newInstance();
			item.setText(value);
			return item;
		} catch (InstantiationException ex) {
			throw new IllegalArgumentException("Error in default constructor.",
					ex);
		} catch (IllegalAccessException ex) {
			throw new IllegalArgumentException("Error in default constructor.",
					ex);
		}
	}

	public static  boolean shouldBeWrapped(List core) {
		if (core == null || !(core instanceof MixedItemList)) {
			return true;
		} else {
			return false;
		}
	}

	public static > List wrap(
			List core, List items,
			Class itemClass) {
		if (core == null || !(core instanceof MixedItemList)) {
			final List newCore = new DefaultMixedItemList(
					items, itemClass);
			if (core != null) {
				newCore.addAll(core);
			}
			return newCore;
		} else {
			return core;
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy