package org.xgbi.vaadin.container;

import static com.google.common.base.Preconditions.checkNotNull;

import com.vaadin.data.Container;
import com.vaadin.data.Item;

/**
 * Simple static methods to do less check and get work quickly when working on
 * {@link Container}.
 * 
 * <p>
 * This is not a Preconditions class like {@link ContainersPreconditions}.
 * </p>
 * 
 * @author Vincent Demeester
 * 
 */
public class Containers {

	private Containers() {
	}

	/**
	 * Check if the container reference passed as argument has the propertyId.
	 * 
	 * @param container
	 *            a container reference
	 * @param propertyId
	 *            an object reference representing the propertyId
	 * @return true if the container has the propertyId, false otherwise.
	 */
	public static boolean containsPropertyId(Container container,
			Object propertyId) {
		checkNotNull(container);
		checkNotNull(container.getContainerPropertyIds());
		return container.getContainerPropertyIds().contains(propertyId);
	}
	
	/**
	 * Check if the item reference passed as argument has the propertyId.
	 * 
	 * @param item
	 *            an item reference
	 * @param propertyId
	 *            an object reference representing the propertyId
	 * @return true if the item has the propertyId, false otherwise.
	 */
	public static boolean containsPropertyId(Item item,
			Object propertyId) {
		checkNotNull(item);
		checkNotNull(item.getItemPropertyIds());
		return item.getItemPropertyIds().contains(propertyId);
	}
}

@@ -93,16 +93,97 @@
 NotNull;
+%0Aimport static org.xgbi.vaadin.container.ContainersPreconditions.checkPropertyId;
 %0A%0Aimport
@@ -238,16 +238,49 @@
 ta.Item;
+%0Aimport com.vaadin.data.Property;
 %0A%0A/**%0A *
@@ -860,32 +860,170 @@
 alse otherwise.%0A
+%09 * %0A%09 * @throws NullPointerException%0A%09 *             if the container is null, the propertyIds of the container is%0A%09 *             null.%0A
 %09 */%0A%09public sta
@@ -1248,17 +1248,16 @@
 Id);%0A%09%7D%0A
-%09
 %0A%09/**%0A%09 
@@ -1530,16 +1530,154 @@
 erwise.%0A
+%09 * %0A%09 * @throws NullPointerException%0A%09 *             if the container is null, the propertyIds of the container is%0A%09 *             null.%0A
 %09 */%0A%09pu
@@ -1725,20 +1725,17 @@
 em item,
-%0A%09%09%09
+ 
 Object p
@@ -1871,11 +1871,1718 @@
 yId);%0A%09%7D
+%0A%0A%09/**%0A%09 * Check if the property has a value.%0A%09 * %0A%09 * @param property%0A%09 *            the property reference%0A%09 * @return true if it has a value, false otherwise.%0A%09 * %0A%09 * @throws NullPointerException%0A%09 *             if the property is null.%0A%09 */%0A%09public static boolean propertyHasValue(Property property) %7B%0A%09%09checkNotNull(property);%0A%09%09return property.getValue() != null;%0A%09%7D%0A%0A%09/**%0A%09 * Return the value of the property identified by the container, itemId and%0A%09 * propertyId.%0A%09 * %0A%09 * @param container%0A%09 *            the container reference%0A%09 * @param itemId%0A%09 *            the itemId reference%0A%09 * @param propertyId%0A%09 *            the propertyId reference%0A%09 * @return the value if it exists, null otherwise.%0A%09 * %0A%09 * @throws NullPointerException%0A%09 *             if the container, itemId or propertyId are null.%0A%09 */%0A%09public static Object getValueOfProperty(Container container, Object itemId,%0A%09%09%09Object propertyId) %7B%0A%09%09checkPropertyId(container, propertyId);%0A%09%09if (container.containsId(itemId)) %7B%0A%09%09%09Item item = container.getItem(itemId);%0A%09%09%09return getValueOfProperty(item, propertyId);%0A%09%09%7D%0A%09%09return null;%0A%09%7D%0A%0A%09/**%0A%09 * Return the value of the property identified by the item and propertyId.%0A%09 * %0A%09 * @param item%0A%09 *            the item reference%0A%09 * @param propertyId%0A%09 *            the propertyId reference%0A%09 * @return the value if it exists, null otherwise.%0A%09 * %0A%09 * @throws NullPointerException%0A%09 *             if the item or propertyId are null.%0A%09 */%0A%09public static Object getValueOfProperty(Item item, Object propertyId) %7B%0A%09%09checkPropertyId(item, propertyId);%0A%09%09Property property = item.getItemProperty(propertyId);%0A%09%09if (propertyHasValue(property)) %7B%0A%09%09%09return property.getValue();%0A%09%09%7D%0A%09%09return null;%0A%09%7D
 %0A%7D%0A

Add few methods