package com.onaro.sanscreen.client.view.tabular.columns; import java.util.HashMap; import java.util.Map; /** * Default presenter implementation that simply returns the value passed to it. * * @param the type of the value to present, which matches the value returned */ public class DefaultColumnValuePresenter extends AbstractColumnValuePresenter { /** * Cache of DefaultColumnValuePresenter instances, one per presentation type */ private static final Map, DefaultColumnValuePresenter> INSTANCE_CACHE = new HashMap, DefaultColumnValuePresenter>(); /** * Factory method to retrieve DefaultColumnValuePresenter instances * @param the value type to present * @param presentationType the presentation value type * @return the presenter instance */ public static DefaultColumnValuePresenter of(Class presentationType) { if (presentationType == null) throw new IllegalArgumentException("presentationType"); //$NON-NLS-1$ @SuppressWarnings("unchecked") DefaultColumnValuePresenter instance = (DefaultColumnValuePresenter)INSTANCE_CACHE.get(presentationType); if (instance == null) { instance = new DefaultColumnValuePresenter(presentationType); INSTANCE_CACHE.put(presentationType, instance); } return instance; } /** * Factory method to retrieve DefaultColumnValuePresenter for unknown Object type * @return the presenter instance */ public static DefaultColumnValuePresenter ofObjectType() { @SuppressWarnings("unchecked") DefaultColumnValuePresenter instance = (DefaultColumnValuePresenter)INSTANCE_CACHE.get(Object.class); if (instance == null) { instance = new DefaultColumnValuePresenter(Object.class); INSTANCE_CACHE.put(Object.class, instance); } return instance; } // Private constructor private DefaultColumnValuePresenter(Class presentationType) { super(presentationType); } @Override public V getPresentation(V value, String identifier) { return value; } }