class EntityUtil {

	public static <T extends Entity> T getClusterView(T entity, String clusterName) {
	    switch(entity.getEntityType()) {
	    case CLUSTER:
	        return entity;
	        
	    case FEED:
	        Feed feed = (Feed) entity.clone();
	        Cluster feedCluster = FeedHelper.getCluster(feed, clusterName);
	        Iterator<Cluster> itr = feed.getClusters().getClusters().iterator();
	        while(itr.hasNext()) {
	            Cluster cluster = itr.next();
	            //In addition to retaining the required clster, retain the sources clusters if this is the target cluster
	            //1. Retain cluster if cluster n
	            if(!(cluster.getName().equals(clusterName) || 
	                    (feedCluster.getType() == ClusterType.TARGET && cluster.getType() == ClusterType.SOURCE)))
	                itr.remove();
	        }
	        return (T) feed;            
	        
	    case PROCESS:
	        Process process = (Process) entity.clone();
	        Iterator<org.apache.ivory.entity.v0.process.Cluster> procItr = process.getClusters().getClusters().iterator();
	        while(procItr.hasNext()) {
	            org.apache.ivory.entity.v0.process.Cluster cluster = procItr.next();
	            if(!cluster.getName().equals(clusterName))
	                procItr.remove();
	        }
	        return (T) process;
	    }
	    throw new UnsupportedOperationException("Not supported for entity type " + entity.getEntityType());
	}

}